d3 / d3-force

Force-directed graph layout using velocity Verlet integration.
https://d3js.org/d3-force
ISC License
1.82k stars 377 forks source link

All nodes starts to move when click and holding one node #209

Closed 87prashant closed 1 year ago

87prashant commented 2 years ago

I don't know if it is a bug or not. Here is what I meant:

https://user-images.githubusercontent.com/106697681/197469743-1843dc88-2d1c-4ed2-aee9-d25f11f0f10a.mp4

I believe we can fix the other node's position here:

Screenshot 2022-10-24 011541

But I am not getting why other nodes start to move when we click and hold any one node. How force changes between nodes in this case?

Could someone help me with this?

ooodummy commented 1 year ago

It's not a bug it is meant to jiggle.

mbostock commented 1 year ago

It’s this line here which reheats the simulation when you start dragging:

      if (!event.active) simulation.alphaTarget(0.3).restart();

You need to reheat the graph on interaction or else the nodes won’t respond to the node you move as expected. Of course you’re free to remove this line of code and try it another way.

87prashant commented 1 year ago

Thank you guys for helping!!