简体   繁体   English

标记结束位置无法正常工作d3js

[英]Marker end position not working correctly d3js

I am trying to put marker at the end of arc. 我试图将标记放在弧线的末尾。 But it always placed at the start of the string. 但是它总是放在字符串的开头。

and is there any way tht we can make marker also animate along with the arc. 并且有什么方法可以使标记也随着弧线动画。

Fiddle for same 提琴一样

<svg version="1.1" viewBox="0 0 1000 1000">
<defs>
    <marker id="endtriangle"
  viewBox="0 0 10 10" refX="0" refY="5" 
  markerUnits="strokeWidth"
  markerWidth="4" markerHeight="3"
  orient="auto" overflow="visible">
    <path d="M 0 0 L 10 5 L 0 10 z" />
    </marker>

    <path d="M -2 5 L 8 0 L 8 10 z" />
    </marker>
</defs>

</svg>

var arc=d3.svg.arc()
    .innerRadius(140)
    .outerRadius(140)
    .startAngle(0)
    .endAngle(Math.PI*1.5);

d3.select("svg").append("path")
        .attr("d",arc)
        .attr("transform","translate(200,200)")
        .attr("stroke","black")
        .attr("marker-end","url(#endtriangle)")
        .attr("fill","none")
        .attr("stroke-width","10")
        .attr("id","dimen");

http://jsfiddle.net/LL8y9wg9/ http://jsfiddle.net/LL8y9wg9/

<svg version="1.1" viewBox="0 0 1000 1000">
  <defs>
   <marker id="endtriangle"
   viewBox="0 0 10 10" refX="7" refY="5" 
   markerUnits="strokeWidth"
   markerWidth="4" markerHeight="3"
   orient="auto" overflow="visible">

    <path d="M 10 0 L 5 10 L 0 0 z" />
   </marker>

 </defs>

</svg>


var svg = d3.select("svg");


    var data = [
        {startAngle: Math.PI*1.5, endAngle: 0}
    ];
    var arc = d3.svg.arc().outerRadius(140).innerRadius(140);
    svg.select("g").remove();
    svg.append("g")
        .attr("transform", "translate(200,200)")        
        .selectAll("path")
            .data(data)
        .enter()
            .append("path")
            .attr("stroke","black")
            .attr("marker-start","url(#endtriangle)")
            .attr("fill","none")
            .attr("stroke-width","10")
            .attr("id","dimen")
            .attr("class", "arc")
            .transition().duration(1000)
            .attrTween("d", function (d) { 
                var start = {startAngle: 0, endAngle: 0}; 
                var interpolate = d3.interpolate(start, d); 
                return function (t) {
                    return arc(interpolate(t));
                };
            });

Try this jsfiddle 试试这个jsfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM