问题描述
我正在尝试绘制vis.js网络图,并且可以加载和定位节点。然后,我希望禁用物理,以便用户可以移动节点。我试过这个但是没有用。
I am trying to draw a vis.js network diagram and have vis load and position the nodes. I then want the physics to be disabled so the nodes can be moved by the user. I have tried this but it is not working.
var options = {
nodes: {
borderWidth:4,
size:60,
color: {
border: '#222222',
background: 'grey'
},
font:{color:'black'}
},
edges: {
arrows: {
to: {enabled: false, scaleFactor:1},
middle: {enabled: false, scaleFactor:1},
from: {enabled: false, scaleFactor:1}
},
color: 'black'
},
{ physics: enabled: false; };
有没有人这样做过?如果是这样,你能提供一个例子或建议,以达到最佳方法。我还阅读了的解释,但我不太熟悉java,我可以' t计算出步骤。
Has anyone done this? if so can you provide an example or advice on best way to accomplish this. I have also read the explanation located here, but not being too familiar with java I can't figure the steps out.
谢谢
推荐答案
经过多次来自vis.js开发人员的工作和帮助是完成的代码,减去json数据和一些选项。诀窍是使用stabilizationIterationsDone
事件并禁用物理:
After some more work and help from the vis.js developer here is the completed code, minus the json data and some options. The trick is to use the "stabilizationIterationsDone"
event and disable physics:
// create a network
var container = document.getElementById('mynetwork');
var data = {
nodes: nodes,
edges: edges
};
var options = {
nodes: ...,
edges: ...,
physics: {
forceAtlas2Based: {
gravitationalConstant: -26,
centralGravity: 0.005,
springLength: 230,
springConstant: 0.18,
avoidOverlap: 1.5
},
maxVelocity: 146,
solver: 'forceAtlas2Based',
timestep: 0.35,
stabilization: {
enabled: true,
iterations: 1000,
updateInterval: 25
}
}
};
network = new vis.Network(container, data, options);
network.on("stabilizationIterationsDone", function () {
network.setOptions( { physics: false } );
});
这篇关于在节点加载后停止vis.js物理但允许可拖动节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!