简体   繁体   English

删除少数节点后D3 SVG转换问题

[英]D3 SVG transition issue after deleting few nodes

I am facing a weird issue in this jsfiddle . 我在这个jsfiddle面临着一个奇怪的问题。 If I delete few existing nodes and add new nodes later, the transition of nodes doesn't stay the same. 如果我删除几个现有节点并稍后添加新节点,则节点的转换不会保持不变。

This scenario is working fine : 这种情况很好

  1. run the jsfiddle. 运行jsfiddle。
  2. click the reset button 单击reset按钮
  3. select ctee node which is connected to a few other nodes and drag. 选择连接到其他几个节点的ctee节点并拖动。
  4. all the connected nodes should follow the main dragged node. 所有连接的节点应遵循主拖动节点。
  5. check out the following screenshot, the connected nodes to the ctee node are also moving along with ctee . 看看下面的截图,连接到ctee节点的节点也随着ctee一起移动。

连接的节点随主节点移动

This scenario is having a problem (only difference is we are going to delete a node first and then click reset button) : 这种情况有问题 (唯一不同的是我们将首先删除节点,然后单击reset按钮):

  1. run the jsfiddle. 运行jsfiddle。
  2. right click the GW node and select the option Stop . 右键单击GW节点,然后选择Stop
  3. this will remove the node from the screen. 这将从屏幕上删除节点。
  4. now click the reset button 现在单击reset按钮
  5. select ctee node which is connected to a few other nodes and drag. 选择连接到其他几个节点的ctee节点并拖动。
  6. Ideally, all the connected nodes should follow the main dragged node but it doesn't work. 理想情况下,所有连接的节点应遵循主拖动节点,但不起作用。 the connected nodes stay at their original position. 连接的节点保持原始位置。
    1. check out the following screenshot, the connected nodes to the ctee node are not moving along with ctee . 查看以下屏幕截图, ctee节点的连接节点ctee一起移动。

拖动节点时连接的节点不移动

The issue looks like that when you delete a node, you're creating a new reference to links that is not in sync with your force layout: 问题看起来就像当您删除节点时,您正在创建对与您的强制布局不同步的links的新引用:

links = links.filter...

To fix this, you can simply add: force.links(links); 要解决这个问题,你可以简单地添加: force.links(links); to the line after it to update the force layout's reference. 到它之后的行更新力布局的参考。

Updated fiddle: https://jsfiddle.net/r1tcj0mf/16/ 更新小提琴: https//jsfiddle.net/r1tcj0mf/16/

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

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