Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.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 /退出选择。代码中发生的情况是: 在初始化函数中为每个图表元素执行一次数据联接。该数据联接将每个节点标记为新节点并返回每个节点,然后缓存这些结果。 在更新函数中,每次都使用这些缓存的结果。_Javascript_Node.js_Reactjs_Typescript_D3.js - Fatal编程技术网

Javascript /退出选择。代码中发生的情况是: 在初始化函数中为每个图表元素执行一次数据联接。该数据联接将每个节点标记为新节点并返回每个节点,然后缓存这些结果。 在更新函数中,每次都使用这些缓存的结果。

Javascript /退出选择。代码中发生的情况是: 在初始化函数中为每个图表元素执行一次数据联接。该数据联接将每个节点标记为新节点并返回每个节点,然后缓存这些结果。 在更新函数中,每次都使用这些缓存的结果。,javascript,node.js,reactjs,typescript,d3.js,Javascript,Node.js,Reactjs,Typescript,D3.js,相反,每次图形更改时,在更新时执行数据联接,而不是在初始化时。节点元素的示例如下: private initializeGraph(): void { const mainGroup = select(this.svgElement.current) .append("g") .attr("id", "main"); // append nodes svg group this.

相反,每次图形更改时,在更新时执行数据联接,而不是在初始化时。节点元素的示例如下:

private initializeGraph(): void {
    const mainGroup = select(this.svgElement.current)
        .append("g")
        .attr("id", "main");

    // append nodes svg group
    this.nodeElements = mainGroup.append("g")
        .attr("id", "nodes")
}

private updateGraph(): void {
    // select nodes & edges
    const graphNodes = this.nodeElements
        .selectAll<SVGCircleElement, Node>(".directed-graph-node")
        .data<Node>(this.state.g.nodes, _ => _.id);

    // update nodes with their current position
    graphNodes.attr("cx", node => node.x)
        .attr("cy", node => node.y);

    // add newly added nodes if any
    graphNodes.enter()
        .append("circle")
        .attr("class", ".directed-graph-node")
        .attr("stroke", "steelblue")
        .attr("cx", node => node.x)
        .attr("cy", node => node.y)
        .attr("r", 2.5)
        .call(drag<SVGCircleElement, Node>());

    // remove nodes that don't exist anymore
    graphNodes.exit().remove();
}
private updateGraph(): void {
    const graphNodes = this.nodeElements
        .selectAll<SVGCircleElement, Node>(".directed-graph-node")
        // data() join()
        .data<Node>(this.state.g.nodes, _ => _.id)
        .join(
        enter => enter.append("circle")
            .attr("class", ".directed-graph-node")
            .attr("stroke", "steelblue")
            .attr("r", 2.5)
            .call(drag<SVGCircleElement, Node>()),
        update => update,
        exit => exit.remove();
        )
        // enter + update past this point
        .attr("cx", node => node.x) 
        .attr("cy", node => node.y)
}