将节点逐组添加到D3力导向图

时间:2013-01-12 16:59:50

标签: graph d3.js force-layout

我正在尝试实施类似于this的强制定向网络。但是,我的每个节点都分配了一个组值,例如

Node    Group
node1   1
node2   1
node3   2
node4   3
node5   3

我希望网络增长,即在一段时间(比如说2秒)之后,后续节点组会添加其链接。

这可以实现吗?

1 个答案:

答案 0 :(得分:1)

是。诀窍是封装在函数中绘制图形的部分。在适当的时间间隔之后将特定组添加到graph数据结构并调用该函数。代码看起来大致如此。

function update(graph) {
    var link = svg.selectAll("line.link")
         .data(graph.links)
         .enter().append("line");

    var node = svg.selectAll("circle.node")
         .data(graph.nodes)
         .enter().append("circle")
         .call(force.drag);

    node.append("title")
         .text(function(d) { return d.name; });

    force.start();
}

你应该能够基本上重复使用其他所有内容。

相关问题