Skip to content

Instantly share code, notes, and snippets.

@mbostock
Created Mar 8, 2016
Embed
What would you like to do?
Chained Transitions II
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
<style>
circle {
fill: #000;
stroke: #000;
stroke-width: 1.5px;
}
</style>
<body>
<script src="//d3js.org/d3.v4.0.0-alpha.28.min.js"></script>
<script>
var margin = {top: 40, right: 40, bottom: 40, left: 40},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var y = d3.scalePoint()
.domain(d3.range(50))
.range([0, height]);
var z = d3.scaleLinear()
.domain([10, 0])
.range(["hsl(62,100%,90%)", "hsl(228,30%,20%)"])
.interpolate(d3.interpolateHcl);
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
svg.selectAll("circle")
.data(y.domain())
.enter().append("circle")
.attr("r", 25)
.attr("cx", 0)
.attr("cy", y)
.style("fill", function(d) { return z(Math.abs(d % 20 - 10)); })
.transition()
.duration(2500)
.delay(function(d) { return d * 40; })
.on("start", slide);
function slide() {
d3.active(this)
.attr("cx", width)
.transition()
.attr("cx", 0)
.transition()
.on("start", slide);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment