Skip to main content
100%

Custom Tweens

✓ Published0🌍 Public
Mmbostock
Last edited Feb 9, 2016
Created on Aug 9, 2012

A single cross-shaped symbol, drawn with the SVG path API via `d3.svg.symbol`, rotates continuously in the center of the frame. The example demonstrates how a custom transition interpolator overrides default behavior: `transition.attrTween` combines `d3.interpolateString` to animate the transform attribute from "rotate(0)" to "rotate(720)", enabling a full double spin that the standard numeric interpolation would ignore. Each ten-second transition loops indefinitely through the `each` event, showcasing attribute tweening in a minimal SVG animation.

AI-generated description

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.

symbol.transition()
    .attrTween("transform", function() {
      return d3.interpolateString("rotate(0)", "rotate(720)");
    });
gpl-3.0 Licensed

Similar vizzes