Skip to content

Instantly share code, notes, and snippets.

Last active February 9, 2016 01:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mbostock/3305854 to your computer and use it in GitHub Desktop.
Custom Tweens
license: gpl-3.0

Use transition.attrTween to customize interpolation during a transition. For example, the default transform interpolation from "rotate(0)" to "rotate(720)" has no effect because 0º and 720º are equivalent; by changing the interpolator to d3.interpolateString, you can animate the rotation.

    .attrTween("transform", function() {
      return d3.interpolateString("rotate(0)", "rotate(720)");
<!DOCTYPE html>
<meta charset="utf-8">
<script src="//"></script>
var width = 960,
height = 500;
var svg ="body").append("svg")
.attr("width", width)
.attr("height", height);
.attr("transform", "translate(" + (width / 2) + "," + (height / 2) + ")")
.attr("d", d3.svg.symbol().type("cross").size(10000))
function cycle() {
.attrTween("transform", function() { return d3.interpolateString("rotate(0)", "rotate(720)"); })
.each("end", cycle);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment