Problems with positioning nodes using d3.js force-layout. Nodes "re-enter" each data update, for example, internally

I asked this question a few days ago earlier, but I don’t think that anyone other than paxRoman really found out what I asked, since it was difficult to describe without an example.

However, we managed to figure out what might be my problem, and I was able to install the code on bl.ocks.org so you can see an example of what I mean!

Here is an example: http://bl.ocks.org/3020018

Each time the data is updated (in this example, just reading from the json file), all nodes are recreated and added back to the drawing.

What i want to do

I want the nodes to be updated without any changes.

If a new node exists in the new array, it should appear, like everything that is happening now, if something exists in the previous array, but not in the new one, it just has to disappear.

As you see in the example, this is not what is happening, and I could not understand why last week.

So my question is:

What am I actually doing wrong? Is this my lack of links? What is the problem? The two of us spent more than an hour looking at it yesterday and couldn't understand, I spent a good week on it now without much progress: /

My old question / post is still there , but it is poorly worded and I had no example to show.

Thanks for helping me :)

+4
source share
2 answers

So, I'm sure I have solved most of my problems!

It got to the point that I added / changed nodes when updating data. I completely forgot about x / y and similar attributes, since I did not set them myself, so I added "new" objects every time I updated the data, even if they were not really new.

With some jQuery magic using $.extend() , I kind of got it working, but it still moves / pulses slightly whenever I update the data.

I updated the gist to show the changes. http://bl.ocks.org/3020018

I would also like to remove this little ripple, so let me know if you have any ideas :)

+3
source

Have you tried setting the friction parameter (where do you have linkDistance and a set of charges)? Setting it to 0.9 will speed up the search for the final position, since I think that by default it is 1, if not set. Its just a case of adding

 .friction(0.9) // or any suitable value closer to 0 - have a play! 

Hope that helps

0
source

All Articles