Skip to content

Instantly share code, notes, and snippets.

@1wheel
Forked from mbostock/.block
Last active December 30, 2015 08:09
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 1wheel/7800813 to your computer and use it in GitHub Desktop.
Save 1wheel/7800813 to your computer and use it in GitHub Desktop.
<!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