如何防止SVG标记(箭头)继承路径的笔划宽度?

时间:2012-11-29 13:19:03

标签: svg d3.js

我有不同边缘厚度的箭头但是我希望箭头(svg标记)具有相同的大小,即根据路径的笔划宽度不调整大小。我该怎么办?

svg.append("svg:defs").selectAll("marker")
    .data(["suit", "licensing", "resolved"])
  .enter().append("svg:marker")
    .attr("id", String)
    .attr("viewBox", "0 -5 10 10")
    .attr("refX", 15)
    .attr("refY", -1.5)
    .attr("markerWidth", 6)
    .attr("markerHeight", 6)
    .attr("orient", "auto")
    .style("stroke-width", 1)
  .append("svg:path")
    .attr("d", "M0,-5L10,0L0,5");

var path = svg.append("svg:g").selectAll("path")
    .data(force.links())
  .enter().append("svg:path")
    .attr("class", function(d) { return "aglink " + "suit"; })
    .attr("marker-end", function(d) { return "url(#" + "suit" + ")"; })
    .style("stroke-width", function(d) { if (d.total != 0) { 

        var min = 2;
        var max = 16;
        var val = Math.round((max-min)*(d.count/d.total))+min;

        return val ;
        } });

1 个答案:

答案 0 :(得分:10)

http://www.w3.org/TR/SVG11/painting.html#MarkerUnitsAttribute

您似乎想要的是markerUnits="userSpaceOnUse"