How to say when the layout of the D3 force stopped

I use D3 force layout to organize the network, and everything works smoothly.

However, I want to add a button to my user interface so that the user can play / pause the layout process as desired: I would like to have a toggle button that reflects the current layout status: regardless of not (d3 will automatically stop calculating when the layout stabilizes). Is there a way to tell when the compositing calculations ended and started? I was expecting some kind of event to handle this, but could not find it.

+6
source share
2 answers

Use the end event registered on the wiki .

 d3.layout.force() .on('end', function() { console.log('ended!'); }); 

jsFiddle: http://jsfiddle.net/zschuessler/gRqv3/ | Browse the console to see listeners in action.

+9
source

There really is no such thing as a β€œstop" layout calculation. Even when it looks motionless, there may still be slight changes. What you can do is check the alpha value and interpret it as stopped if it falls below the threshold value. In this case, you can set it to a negative value that will explicitly close the layout. There is no special event for this, but you can check your condition in the tick event handler.

+1
source

Source: https://habr.com/ru/post/949550/


All Articles