小编JHo*_*mes的帖子

缩放D3力布局链接标记上的箭头

我在d3强制有向图中有以下代码,我试图根据值(1-3)改变链接及其相关箭头的大小.行程重量确实随着值而变化,但箭头不会保持在正确的位置.当笔划重量从1变为3时,它往往会从最后移回.有关如何在更改笔划值时保持箭头(标记)正确对齐的任何想法?非常感谢!

      var link = vis.selectAll("line.link")
      .data(json.links)
    .enter().append("svg:line")
      .attr("class", "link")
      .style("stroke-width", function(d) { return Math.sqrt(d.value); })
      .attr("x1", function(d) { return d.source.x; })
      .attr("y1", function(d) { return d.source.y; })
      .attr("x2", function(d) { return d.target.x; })
      .attr("y2", function(d) { return d.target.y; })
      .attr("marker-end", "url(#arrowGray)")
      .on("click", function(d) {
            link.style("stroke","#dddddd");
            node.style("stroke","#FFFFFF");
            d3.select(this).style("stroke","red");
            link.attr("marker-end", null);
            link.attr("marker-end", "url(#arrowGray)");
            d3.select(this).attr("marker-end", null);
            d3.select(this).attr("marker-end", "url(#arrowRed)");
            clickLink(d);
            });

    defs.append("svg:marker")
            .attr("id", "arrowGray")
            .attr("viewBox","0 0 10 10")
            .attr("refX","20")
            .attr("refY","5")
            .attr("markerUnits","strokeWidth")
            .attr("markerWidth","9")
            .attr("markerHeight","5")
            .attr("orient","auto")
            .append("svg:path")
            .attr("d","M 0 0 L 10 5 L 0 10 …
Run Code Online (Sandbox Code Playgroud)

javascript svg markers d3.js force-layout

10
推荐指数
1
解决办法
5419
查看次数

标签 统计

d3.js ×1

force-layout ×1

javascript ×1

markers ×1

svg ×1