Created
December 26, 2014 05:07
-
-
Save miguelmota/1941ca3ed6a8dbf6dc83 to your computer and use it in GitHub Desktop.
D3.js arc transition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var width = 400, | |
height = 400, | |
endAngle = 2 * Math.PI, | |
colors = d3.scale.category20(); | |
var svg = d3.select("body").append("svg") | |
.attr("class", "pie") | |
.attr("height", height) | |
.attr("width", width); | |
function render(innerRadius) { | |
var data = [ | |
{startAngle: 0, endAngle: 0.1 * endAngle}, | |
{startAngle: 0.1 * endAngle, endAngle: 0.2 * endAngle}, | |
{startAngle: 0.2 * endAngle, endAngle: 0.4 * endAngle}, | |
{startAngle: 0.4 * endAngle, endAngle: 0.6 * endAngle}, | |
{startAngle: 0.6 * endAngle, endAngle: 0.7 * endAngle}, | |
{startAngle: 0.7 * endAngle, endAngle: 0.9 * endAngle}, | |
{startAngle: 0.9 * endAngle, endAngle: endAngle} | |
]; | |
var arc = d3.svg.arc().outerRadius(200).innerRadius(innerRadius); | |
svg.select("g").remove(); | |
svg.append("g") | |
.attr("transform", "translate(200,200)") | |
.selectAll("path.arc") | |
.data(data) | |
.enter() | |
.append("path") | |
.attr("class", "arc") | |
.attr("fill", function (d, i) { | |
return colors(i); | |
}) | |
.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)); | |
}; | |
}); | |
} | |
render(100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It doesn't work fine for me here, when i put the.
d3.interpolate(start, d);
But, i saw in others sites and found one way to do that:
Where currentArc is the old arc that i want substitute