Skip to content

Instantly share code, notes, and snippets.

@1wheel
Forked from mbostock/.block
Last active Dec 30, 2015
Embed
What would you like to do?
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 960,
height = 400,
parameters = [0.4, 0.3, 0.2, 0.1];
var x = d3.scale.ordinal()
.domain(parameters)
.rangeRoundBands([0, width], .5);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
svg.append("rect")
.attr("width", x.rangeBand())
.attr("height", x.rangeBand())
.attr("x", x)
.attr("y", -x.rangeBand())
.transition().duration(3000)
.attrTween('y', function(d, i, a){
var interpolator = d3.interpolate(a, 400);
var halfWayDone = false;
return function(t){
if (t > .5 && !halfWayDone){
d3.select('body').append('div').text('halfway done at ' + t);
halfWayDone = true;
}
return interpolator(t);
}
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment