How to tell when a D3 force layout has stopped
d3.js, events, force-layout, javascript, layout
Solution
Use the `end` event documented on the wiki.
d3.layout.force()
.on('end', function() { console.log('ended!'); });
jsFiddle : http://jsfiddle.net/zschuessler/gRqv3/ | View console to see listeners in action.
Problem
I'm using D3's force layout to organize a network graph, and everything works smoothly. However, I want to add a button to my UI so that the user can play/pause the layout process at will: I'd like to have a toggle button that reflects the current state of the layout: whether it's computing or not (d3 automatically will stop computing when the layout has stabilized). Is there a way to tell when force layout computing has finished and started? I expected some kind of event to handle this, but couldn't find one.