0

This is not a new question and I have already referred to solutions stating that nodes must have their d.x d.y parameters set to suitable values before restarting the layout.

I have also created a simple block demonstrating this. However now that I have developed a more complex example here I am not satisfied with the result.

The reason being that as you click on the nodes, new nodes come into existence off screen and the force layout is erratic (not good), however once all the nodes appear at least once the nodes appear to behave as desired and appear close to the centre and hence produce minimal disturbance to the layout.

My feeling is that either this is the best I can expect from d3 or that there is some inconsistency in the data model model of my code.

The code itself is designed to display a smaller subset of a larger graph loaded from the JSON. It allows you to navigate a larger graph one subset at a time. The subsets being centred on the node that was clicked.

timebandit
  • 794
  • 2
  • 11
  • 26
  • What behaviour are you looking for? [This question](https://stackoverflow.com/questions/13463053/calm-down-initial-tick-of-a-force-layout) may help. – Lars Kotthoff Jun 30 '15 at 01:49
  • I want to eliminate the off screen entrances of new nodes so that they enter at the centre of the svg element, this would make the additions less likely to disturb greatly, the forced layout. If you're working in Cork right now you must be doing long hours :) – timebandit Jun 30 '15 at 01:53
  • Keep in mind that if you add several nodes, the repulsing forces will be extremely strong if they all start at the same position. You probably want to apply some jitter so that they start around the centre, but not all in the same place. And no, I'm in Canada ;) – Lars Kotthoff Jun 30 '15 at 02:19
  • Hmm yes good point. I could also add the nodes one at a time with a few milliseconds delay between them. – timebandit Jun 30 '15 at 02:22
  • Yes, that could work as well. – Lars Kotthoff Jun 30 '15 at 02:42
  • @LarsKotthoff Adding random noise to the initial positions solved my problem as well - thanks! I recommend to enter it as an answer to this question to make it easier to find for others having the same problem. – JSchirrmacher Jun 16 '16 at 12:03

0 Answers0