d3.forceSimulation - continue from current node positions when data changes

I have a force directed chart with nodes grouped and then clustered by one of two selected fields in the data.

It works, with the simulation restarting from scratch each time the selected field is changed.

However, I’d like the nodes to continue moving from their current position rather than completely new coordinates generated for each cluster, so that the switch looks smooth and natural.

I’ve tried setting the x and y values to fixed values, just to see if it had any impact (and if did, then then look at how use the previous values instead), but it didn’t. So I’m not sure where to go next.

I think it works if you take nodes = pack().leaves() out of the chart cell, so that the x and y values of the nodes are not reset to the default phyllotaxis arrangement.

Thanks @Fil . I’ve tried moving it out but its still the performs in the same way.

It seemed to work for me, but the sudden change of radius and color makes it a bit difficult to follow.