Skip to content

Instantly share code, notes, and snippets.

@EE2dev
Last active September 7, 2018 23:40
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 EE2dev/672546eca63299d0b40a76e29097887e to your computer and use it in GitHub Desktop.
Save EE2dev/672546eca63299d0b40a76e29097887e to your computer and use it in GitHub Desktop.
Arc Tween
license: gpl-3.0
<!DOCTYPE html>
<head>
<title>animated arc</title>
<meta charset="utf-8">
<script src="//d3js.org/d3.v4.min.js"></script>
</head>
<body>
<svg width="960" height="500"></svg>
<script>
var arc = d3.arc()
.startAngle(0)
.endAngle(Math.PI);
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height"),
g = svg.append("g").attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
var clippath = g.append("clipPath")
.attr('id', "clippy")
.append('rect')
.attr('width', 200)
.attr('height', 200);
var nrWaves = Array(10).fill({});
var foreground = g.append("g")
.attr('clip-path', "url(#clippy)")
.selectAll("path")
.data(nrWaves)
.enter()
.append("path")
.style("fill", "orange")
.attr("d", arc);
foreground.transition()
.duration(4000)
.ease(d3.easeLinear)
.delay((d,i) => i * 200)
.attrTween("d", arcTween())
.style("opacity", 0);
function arcTween() {
return function(d) {
var interpolate = d3.interpolate(0, 300);
return function(t) {
d.innerRadius = interpolate(t);
d.outerRadius = interpolate(t) + 3;
return arc(d);
};
};
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment