0

我有一个带有力导向图的动态模拟。

我想实现所有新节点都以某种颜色显示,而现有节点具有所有相同的其他颜色(由 id 标识的节点)。

在每次迭代中(我想),我会将一个类应用于现有节点,并将新节点仅设置new-node为“输入”选择中的一个类:

  restart() {
    // Update and restart the simulation.        
    node = node.data(nodes);
    // Remove all old nodes
    node.exit().remove();
    // Apply class "existing-node" to all existing nodes
    node.attr("class","existing");
    // Apply to all new nodes (enter selection)
    node = node
           .enter()
           .append("circle")
           .attr("r", rad)
           .attr("class", "new-node")
4

0 回答 0