What you need to do is stop the force and apply the transformation of existing nodes to xy obtained from another layout. So your function will look like this:
force.stop(); d3.selectAll("g.nodes").transtion().duration(500) .attr("translate","transform("+newLayoutX+","+newLayoutY+")"
Then iterate over the array of nodes and set the values x
, y
, px
, py
to display the new x
and y
. This will allow your nodes to know the current x
and y
position for the force layout when force.start()
run force.start()
You can see the plotLayout()
function in this example:
https://gist.github.com/emeeks/4588962
However, this is independent of the second d3.layout. The problem you will encounter is that you need a hierarchical dataset for the tree layout, which requires you to convert the node and edge data into an array node.children, as expected in hierarchical layouts. The way I will do this is to duplicate the dataset and manually smooth it, but there may be a more elegant solution that I don't know about.
Elijah
source share