Skip to content

Instantly share code, notes, and snippets.

@mbostock
Last active February 9, 2016 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbostock/f8f88029f3a5fde00407 to your computer and use it in GitHub Desktop.
Save mbostock/f8f88029f3a5fde00407 to your computer and use it in GitHub Desktop.
Arc Corners II
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.paths--straight {
fill: none;
stroke: #777;
}
.paths--round {
fill: #ccc;
stroke: #000;
stroke-width: 1.5px;
stroke-linejoin: round;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
var data = [1, 1, 2, 3, 5, 8, 13, 21];
var width = 960,
height = 500,
outerRadius = height / 2 - 30,
cornerRadius = 20;
var pie = d3.layout.pie();
var arc = d3.svg.arc()
.outerRadius(outerRadius);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
var straightPath = svg.append("g")
.attr("class", "paths--straight")
.selectAll("path")
.data(data)
.enter().append("path");
var roundPath = svg.append("g")
.attr("class", "paths--round")
.selectAll("path")
.data(data)
.enter().append("path");
var ease = d3.ease("cubic-in-out"),
duration = 2500;
d3.timer(function(elapsed) {
var t = ease(1 - Math.abs((elapsed % duration) / duration - .5) * 2),
arcs = pie.padAngle(t * .1)(data);
arc.innerRadius(outerRadius / (3 - t));
straightPath.data(arcs).attr("d", arc.cornerRadius(0));
roundPath.data(arcs).attr("d", arc.cornerRadius(cornerRadius));
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment