删除少数节点后D3 SVG转换问题 [英] D3 SVG transition issue after deleting few nodes
问题描述
我在
此方案出现问题(唯一不同的是我们将首先删除节点,然后点击重置
按钮):
- 运行jsfiddle。
- 右键单击
GW
节点,然后选择Stop
选项。 - 这将从屏幕上删除节点。
- 现在点击
重置
按钮 - 选择
ctee
节点,该节点连接到其他几个节点并拖动。 - 理想情况下,所有连接的节点都应遵循主节点拖动节点但它不起作用。连接的节点保持原始位置。
- 查看以下屏幕截图,连接到
ctee的节点
节点不与ctee
一起移动。
- 查看以下屏幕截图,连接到
当您删除节点时,您正在创建对链接的新引用
这与你的部队布局不同步:
links = links.filter ...
要解决此问题,您只需添加: force.links(links);
在更新强制布局参考之后的行。
更新小提琴: https://jsfiddle.net/r1tcj0mf/16/
I am facing a weird issue in this 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 :
- run the jsfiddle.
- click the
reset
button - select
ctee
node which is connected to a few other nodes and drag. - all the connected nodes should follow the main dragged node.
- check out the following screenshot, the connected nodes to the
ctee
node are also moving along withctee
.
This scenario is having a problem (only difference is we are going to delete a node first and then click reset
button) :
- run the jsfiddle.
- right click the
GW
node and select the optionStop
. - this will remove the node from the screen.
- now click the
reset
button - select
ctee
node which is connected to a few other nodes and drag. - Ideally, all the connected nodes should follow the main dragged node but it doesn't work. the connected nodes stay at their original position.
- check out the following screenshot, the connected nodes to the
ctee
node are not moving along withctee
.
- check out the following screenshot, the connected nodes to the
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.filter...
To fix this, you can simply add: force.links(links);
to the line after it to update the force layout's reference.
Updated fiddle: https://jsfiddle.net/r1tcj0mf/16/
这篇关于删除少数节点后D3 SVG转换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!