I can get around D3 arc endAngle, but not startAngle. What am I doing wrong?

I just play with this demo and recreate it myself: http://bl.ocks.org/mbostock/5100636

I can define a new endAngle and it will animate just fine, but now I'm trying to animate startAngle. I just can't get it to work.

function animateArc(newStart, newEnd) {

    myArc.transition().duration(750).call(arcTween, newStart, newEnd);

    function arcTween(transition, newStart, newEnd) {
        transition.attrTween("d", function(d) {
            var interpolateStart = d3.interpolate(d.startAngle, startAngle);
            var interpolateEnd = d3.interpolate(d.endAngle, endAngle);
            return function(t) {
                d.startAngle = interpolateStart(t);
                d.endAngle = interpolateEnd(t);
                return arc(d);
            };
        });
    }
}

I get no errors and endAngle is still animating, but the startAngle code I added is literally just ignored.

What is the correct way to tween startAngle?

+4
source share
1 answer

, . script 0 . , , .

var arc = d3.svg.arc()
        .innerRadius(90)
        .outerRadius(150);

var background = svg.append("path")
        .datum({
        endAngle: τ,
        startAngle: 0
    })

var foreground = svg.append("path")
        .datum({
        endAngle: .127 * τ,
        startAngle: -.127 * τ
    })

Et voila: http://jsfiddle.net/breizo/h74f180b/

+3

Source: https://habr.com/ru/post/1534495/