简体   繁体   English

d3过渡后调用函数

[英]call function after d3 transition

Here is my codes: 这是我的代码:

var text = container.append('text');
text.text('text')
          .attr('transform',function(){
            return "translate(" + x1 + "," + y1 + ")"
          })
          .transition()
          .attr('transform',function(){
            return "translate(" + x2 + "," + y2 + ")";
          });
 addTextBackground(text);

Passing text to the function addTextBackground, I found the values in the transform attr were still x1, y1 rather than x2, y2. 将文本传递给函数addTextBackground,我发现transform attr中的值仍然是x1,y1而不是x2,y2。 Seems addTextBackground is called before the transition. 似乎在转换之前调用了addTextBackground。 How can I make it called after the transition? 如何在过渡后调用它?

Thanks 谢谢

I figured it out. 我想到了。 Using each('end',callback) like: 使用每个('结束',回调),如:

text.text('text')
          .attr('transform',function(){
            return "translate(" + x1 + "," + y1 + ")"
          })
          .transition()
          .attr('transform',function(){
            return "translate(" + x2 + "," + y2 + ")";
          })
          .each('end',function(){addTextBackground(d3.select(this))});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM