A few things, in the order I approached the problem. Here's the final fiddle if you want to follow along.
First, your update()
method does a lot more than just update the position of the nodes; it recalculates the whole tree. It's overkill for what you're trying to do, and while in the end it turned out to not be the source of the problem, I'd still recommend just using force.resume()
to get the timer ticking and the nodes moving again.
Second, you were on the right track with adding a forEach
statement to turn off the former fixed nodes. But forEach
works on arrays, and root
is an object. So either reuse the flatten
method (slow) or do as @Pablo suggested and use force.nodes() to get the nodes as an array (better).
Third, and this took a bit to figure out: Once you set a node to be "fixed", the force layout ignores any new d.x and d.y values, resetting them back to d.px and d.py (the previous values). (I assume this is so that if the node is dragged, it will automatically jump back to its fixed position). So to move it to be fixed where you want it to be, you have to set the "previous" values, not the new values. The only problem is that this causes an immediate jump in position, instead of a smooth movement. You might want to add in a transition for that one node (to make it look like it's being dragged to the centre) before calling force.resume()
.