-
-
Save GerHobbelt/2512177 to your computer and use it in GitHub Desktop.
Chained Transitions
This file contains 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
# Editor backup files | |
*.bak | |
*~ |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.9.1"></script> | |
<style type="text/css"> | |
circle { | |
fill: #ccc; | |
fill-opacity: .5; | |
stroke: #999; | |
} | |
</style> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
var w = 960, | |
h = 500, | |
y = d3.scale.ordinal().domain(d3.range(50)).rangePoints([20, h - 20]), | |
t0 = Date.now(), | |
d = y.domain(); | |
var svg = d3.select("body").append("svg:svg") | |
.attr("width", w) | |
.attr("height", h); | |
var circle = svg.selectAll("circle") | |
.data(d) | |
.enter().append("svg:circle") | |
.attr("r", 16) | |
.attr("cx", 20) | |
.attr("cy", y) | |
.each(slide(20, w - 20)); | |
var el_count = d3.max(d) - d3.min(d) + 1; | |
function slide(x0, x1, t) { | |
return function(d, i, j) { | |
t0 += 50; | |
t = t || t0; | |
t += 50 * el_count; | |
d3.select(this).transition() | |
.duration(t - Date.now()) | |
.attr("cx", x1) | |
.each("end", slide(x1, x0, t)); | |
}; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment