5

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 reported here by another user:

https://github.com/samizdatco/arbor/issues/12

Would appreciate your help with a fix / workaround

Chris Beach
  • 4,302
  • 2
  • 31
  • 50
  • Since this I have moved to the d3.js library [link](http://mbostock.github.com/d3/), which is a superb alternative. – Chris Beach Feb 23 '12 at 12:46
  • The problem seems to appear in other cases too when having more nodes. For example I had around 30 nodes connected to a central node and that central node started to bounce around as well – user579674 Aug 10 '12 at 14:08

5 Answers5

2

Using the d3.js library instead of Arbor has solved my problem :-)

Chris Beach
  • 4,302
  • 2
  • 31
  • 50
  • can you redefine redraw? like you can with arbor? I need to be able to use DOM elements for my nodes, instead of rendered shapes. =\ – NullVoxPopuli Jul 04 '12 at 00:54
2

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.

Ankur
  • 21
  • 3
2

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' });
}
ActualAl
  • 1,192
  • 10
  • 13
  • How exactly do you count the nodes? I've been trying to count them but I can't figure how to do it outside of arbor.js file since it seems that I can't access the node array. – user579674 Aug 10 '12 at 14:06
1

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).

ethrbunny
  • 10,379
  • 9
  • 69
  • 131
0

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 })
        }
pradip_PRP
  • 102
  • 4