Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript D3.js v5-从另一个节点阵列更新节点_Javascript_D3.js_D3 Force Directed - Fatal编程技术网

Javascript D3.js v5-从另一个节点阵列更新节点

Javascript D3.js v5-从另一个节点阵列更新节点,javascript,d3.js,d3-force-directed,Javascript,D3.js,D3 Force Directed,我得到的每个节点都是g html标记,其中包含另外两个标记: 文本标记-表示节点的名称 圆形标记-这是节点形状 当我在HTML中从一组节点切换到另一组节点时,我会看到来自旧节点集和新节点集的文本标记和圆圈标记 我尝试使用exit().remove()方法和merge()方法,但似乎没有任何东西可以解决我的问题 这里是我的更新函数的一部分,它与节点相关 var node = d3.select('.nodes') .selectAll('g.node'); //he

我得到的每个节点都是g html标记,其中包含另外两个标记:

文本标记-表示节点的名称

圆形标记-这是节点形状

当我在HTML中从一组节点切换到另一组节点时,我会看到来自旧节点集和新节点集的文本标记和圆圈标记

我尝试使用exit().remove()方法和merge()方法,但似乎没有任何东西可以解决我的问题

这里是我的更新函数的一部分,它与节点相关

    var node = d3.select('.nodes')
        .selectAll('g.node');
    //here is my selection between two array of nodes
    node = node.data(show_bad_connections ? bad_nodes : nodes)

    node.exit().remove();

    node_enter = node.enter().append("g")
        .attr("class", "node").merge(node);


    node_enter.append("text")
        .attr("class", "nodetext")
        .attr("x", "0em")
        .attr("y", 15)
        .text(function (d) { return d.name });

    node_enter.append("circle")
        .style("fill", function (d) {
            if (d.id == 0) { return "#0099ff" }
            if (d.CF.includes(0)) { return "#00cc00" }
            if (d.TSP > 0.5) { return "#ff9900" } else { return "#ff0000" }
        })
        .attr("r", r);

    node_enter.on("mouseover", function (d) {
        var g = d3.select(this); // The node
        // The class is used to remove the additional text later
        var info = g.append('text')
            .classed('info', true)
            .attr('dx', "0em")
            .attr('dy', -10)
            .text(function (d) {
                if (d.id == 0) { return "id=0" }
                else { return "id=" + d.id.toString() + ",TF=" + d.TF.toString() + ",AUA=" + d.AUA.toString() }
            })
            .style("font-size", "12px");

        d3.selectAll('line.link')
            .filter(function (l) {
                return (d.id != 0 && (d.id == l.source.id || d.id == l.target.id));
            })
            .style("opacity", 1)

    }).on("mouseout", function () {
        d3.selectAll('line.link').style("opacity", 0.1)
        // Remove the info text on mouse out.
        d3.select(this).select('text.info').remove();

    });
我希望得到只包含新节点的圆圈和文本的g html标记