最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - d3 "end-of-ticking" event for force layout - Stack Overflow

programmeradmin1浏览0评论

I'm working with d3's force layout and trying to find a simple way to identify when the layout has reached a steady state (i.e. when the tick function has stopped manipulating the position of nodes).

My definition of force 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 begins...

function tick(e) {
...

I assumed that "e" would be key to catching the end-point of the simulation, but since I'm not explicitly passing e to the tick function on my force definition I'm not really sure what it represents or how I might be able to use it to identify the end of the simulation. Can anyone either shed light on the function of e (since I'm not explicitly passing it a value), or even suggest a better method to do something as simple as display an "alert(..)" message once the force layout simulation has ended?

Huge thanks in advance for any help at all!

I'm working with d3's force layout and trying to find a simple way to identify when the layout has reached a steady state (i.e. when the tick function has stopped manipulating the position of nodes).

My definition of force 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 begins...

function tick(e) {
...

I assumed that "e" would be key to catching the end-point of the simulation, but since I'm not explicitly passing e to the tick function on my force definition I'm not really sure what it represents or how I might be able to use it to identify the end of the simulation. Can anyone either shed light on the function of e (since I'm not explicitly passing it a value), or even suggest a better method to do something as simple as display an "alert(..)" message once the force layout simulation has ended?

Huge thanks in advance for any help at all!

Share Improve this question asked Jun 2, 2015 at 18:23 d3wannabed3wannabe 1,3172 gold badges23 silver badges40 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

You're almost right, just tick is the wrong event, you want end. So change your last line to

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

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

发布评论

评论列表(0)

  1. 暂无评论