When creating a trivial Arbor JS graph with a single node, the node jitters around all over the place and no further nodes can be added.
The problem is also rep开发者_运维技巧orted here by another user:
https://github.com/samizdatco/arbor/issues/12
Would appreciate your help with a fix / workaround
It's not really a fix but I count the number of nodes and if less than on I set the friction to 1.0
if (nodeCount == 1) {
//Stop single nodes bouncing all over the place
sys.parameters({ friction: '1.0' });
}
Using the d3.js library instead of Arbor has solved my problem :-)
We use a workaround solution for this. Its probably more of a hack than a complete solution, but it's easy to implement and works fine for most cases.
What we do is that we determine the number of particles in the system every time a particle is added or removed. If this count is equal to one, we add a new particle in the system, with its colour set to the canvas background colour. Since the node's colour is same as its background, it's not visible.
So at no point there is a single node in the graph. Whenever that happens due to an addition or deletion, we add this hidden balancing node. You may take a look at our website to see a live example for the above: http://www.graphthinker.com. As you add nodes, you may see that the graph continues to be responsive even when it has just a single (visible) node.
This hidden balancing node could be removed when there is no longer a need for it, say when another node gets added, or when the only visible node is removed.
Another option is to replace the physics.js
file with this one. It has several fixes to compensate for the issues around having a single node (including problems adding the second one).
try this
if (nodeCount == 1) {
sys.parameters({ repulsion: 10, gravity: false, dt: 0.035 })
}
else if (nodeCount > 1 && nodeCount < 30) {
sys.parameters({ repulsion: 1000, gravity: false, dt: 0.35 })
}
else {
sys.parameters({ friction: .1, stiffness: 0.1, repulsion: 1, gravity: false, dt: 0.035 })
}
精彩评论