I have a graph with about 600 nodes. After a while, d3.layout.force() converges. How can I display the (x,y) coordinates of the nodes such that I can store them as data and use them as a cached layout as described in this answer? The answer may be quite simple, as I'm a novice with javascript.
After the force layout converged, you can iterate over the list of nodes to get the current coordinates:
var force = d3.layout.force().nodes(nodes);
// after convergence
var positions = nodes.map(function(d) { return [d.x, d.y]; });
This assumes that your browser supports map, if not see here.
You can of course run this at every tick and save the result each time; this saves you figuring out when the layout has converged.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With