简体   繁体   English

D3中的中断出口过渡

[英]Interrupt exit transition in D3

I've got a D3 force layout network with labeled links like this one . 我有与像标记链接D3力布局网络这一块 I've extended it so the exiting link labels have a fadeout effect. 我已经对其进行了扩展,因此退出的链接标签具有淡入淡出的效果。 The exit code of the labels looks like this: 标签的退出代码如下所示:

$linkLabel.exit()
   .classed('fadeout', true)
   .transition()
   .delay(250)
   .remove();

Now it's possible for a label to re-enter the layout while still fading/exiting (eg when quick successive mouseover and mouseout events occur on the same node). 现在,标签仍可以在褪色/退出时重新输入布局(例如,当在同一节点上发生快速连续的mouseover和mouseout事件时)。 What happens is that the respective label is removed anyway because the event flow is like exit() -> transition() -> delay() -> enter() -> remove() . 发生的事情是无论如何都删除了相应的标签,因为事件流就像exit() -> transition() -> delay() -> enter() -> remove()

What I need to do is to interrupt the transition of labels that re-enter the layout so the remove() function isn't called for them. 我需要做的是中断重新进入布局的标签的过渡,以便不为它们调用remove()函数。 Do you know a way how to do this? 你知道怎么做吗?

By preparing the example I've actually found a possible solution. 通过准备示例,我实际上找到了可能的解决方案。 It works if I delete all currently fading/exiting labels before every update like this: 如果我在每次更新之前都删除所有当前正在褪色/退出的标签,则它会起作用:

 $svg.selectAll('.link-label.fadeout').remove();

See the modified fiddle (in the updateLinkLabels() function). 请参阅修改的小提琴 (在updateLinkLabels()函数中)。 Maybe you know a more elegant solution? 也许您知道一个更优雅的解决方案?

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

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