D3 "end of ticking" for power arrangement

I am working with d3 force layout and am trying to find an easy way to detect when the layout has reached a steady state (i.e. when the tick function has stopped manipulating the position of the nodes).

My definition of strength looks like this ...

var force = d3.layout.force()
        .friction(frictionValue) 
        .theta(thetaValue)
        //.alpha(0.1) 
        .size([width, height])
        .gravity(gravityValue) 
        .charge(chargeValue) 
        .on("tick", tick); 

      

Then the tick function starts ...

function tick(e) {
...

      

I assumed "e" would be the key to trapping the endpoint of the simulation, but since I don't explicitly pass e to the tick function in defining my strength, I'm not entirely sure what it represents or how I might use it to determine the end of the simulation. Could anyone shed some light on the function e (since I am not explicitly passing its value), or even suggest a better way to do something as simple as displaying an "alert (..)" message after the simulation of the force layout is over?

Thank you so much for any help!

+3


source to share


1 answer


You are almost right, only the check mark is the wrong event, you want the end . So change your last line to

.on("end", function (){
    // some code
});

      



You can read about this in the Force Layout API documentation https://github.com/mbostock/d3/wiki/Force-Layout

+6


source







All Articles