Links overlapping with the image in directional force layout

后端 未结 2 504
栀梦
栀梦 2021-01-23 20:16

In my directional force layout codepen I am using icons rather than circles; currently, the links are overlapping with the image/icon. I want the links to end just before the im

2条回答
  •  别那么骄傲
    2021-01-23 20:53

    In the restart() function draw the links before the nodes and use an image that has no internal transparency.

    function restart() {
      link = link.data(links);
      link
        .enter()
        .append("path")
        .attr("class", "link")
        .attr("marker-end", "url(#arrow)");
      link.exit().remove();
      node = node.data(nodes);
      node
        .enter()
        .insert("g")
        .attr("class", "node")
        .call(force.drag);
      node
        .append("image")
        .attr("xlink:href", "https://github.com/favicon.ico")
        .attr("x", -8)
        .attr("y", -8)
        .attr("width", 16)
        .attr("height", 16);
      node
        .append("text")
        .attr("dx", 12)
        .attr("dy", ".35em")
        .text(function(d) {
          return d.id;
        });
      node.exit().remove();
    
      force.start();
    }
    

提交回复
热议问题