1
我正在使用vis.js库创建网络拓扑。之后,我创建一个使用网络:在vis js网络中设置默认比例
network = new vis.Network(container, data, options);
,其中容器上,我绘制canvas
。
数据:
{
nodes: Nodes,
edges: Edges
};
选项:
{
autoResize: true,
nodes: {
shape: 'image',
size: 25,
font: {
size: 16,
color: 'darkbrown'
},
borderWidth: 0,
shadow: true
},
edges: {
smooth: {
forceDirection: "none"
}
},
physics: {
forceAtlas2Based: {
springLength: 80,
springConstant: 0.27
},
minVelocity: 0.75,
solver: "forceAtlas2Based",
timestep: 0.34
},
layout: {
randomSeed: undefined
},
interaction: {
hover: true
}
}
它绘制的默认比例后(1)是非常大的相对于我的画布。我想调整规模。我试过这种方式:
network = new vis.Network(container, data, options); //network is drawn
var scaleOption = { scale : 0.5 }; -(1)
network.moveTo(scaleOption); -(2)
它不这样工作。但是,如果(1)和(2)在特定事件内发射说:
network.on("click",function(params) {
var scaleOption = { scale : 0.5 };
network.moveTo(scaleOption);
});
它的工作原理。我需要在开始时正确设置比例尺,即在绘制拓扑结构之后(发生任何此类事件之前)。 AfterDrawing
事件在拓扑绘制后不断触发,因此也失败。任何方式来解决这个问题?
network.once( 'startStabilizing',函数(){ VAR scaleOption = {规模:0.8}; network.moveTo(scaleOption); }); 这一个最适合我 –