The force-oriented layout is separate from the actual rendering. Usually you have a tick handler that updates the attributes of your SVG elements for each tick of the layout algorithm (the nice thing about decoupling is to do this instead of <canvas> or something else).
To answer your question, you just need to call this handler directly to update the attributes of your SVG elements. For example, your code might look like this:
var node = β¦; // append circle elements var force = d3.layout.force() .nodes(β¦) .links(β¦) .on("tick", tick) .start(); function tick() { // Update positions of circle elements. node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }
Thus, you can simply call tick() at any point and update the position of the elements.
You may be tempted to call force.tick() , but this is intended to be used as a synchronous alternative to force.start() : you can call it again, and each call performs a step in the layout algorithm. However, there is an internal variable alpha , used to control the simulated annealing used internally, and after the layout has βcooledβ, this variable will be 0 and further calls to force.tick() will have no effect. (Admittedly, it would be nice if force.tick() always triggered a tick event regardless of cooling, but this is not the current behavior).
As you correctly noted in the comments, if you manually set dx and dy , you should also set d.px and d.py with the same values ββif you want the node to stay in a certain position.
Jason davies
source share