且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

D3.js强制布局:动态添加的节点不随图形的其余部分移动

更新时间:2023-08-30 21:26:16

您正在修改节点和链接的数据结构,而不是添加和删除节点,这会扰乱力布局。我特别讨论这些行。

You're modifying the data structures of the nodes and links beyond adding and deleting nodes, which messes up the force layout. I'm talking about these lines in particular.

function bigBang () {
    links = links.concat(linksList);
    nodes = nodes.concat(nodesList);
    buildMolecule();
  }

这个函数的前两行是我在说的。工作jsfiddle 这里

The first two lines in that function are what I'm talking about. Working jsfiddle here.