Path Tween
This example shows a smooth animated transition between two SVG path shapes, alternating back and forth indefinitely. The code samples both the source and target paths uniformly using the SVG `getPointAtLength` method, then interpolates the corresponding points to create a piecewise linear curve during the transition. After each cycle, the path is restored to its original cubic Bézier form. The animation uses D3 v4’s `transition.attrTween` and `d3.easeLinear` easing, with a precision of 4 pixels for sampling.
AI-generated descriptionThis example demonstrates path interpolation using SVG's getPointAtLength feature. The source path and the target path are sampled uniformly using a configurable precision in pixels (here, 4px). During the transition, the path is replaced with a piecewise linear curve, or polyline, for easier interpolation. When the transition finishes, the path is restored to the original cubic Bézier. This technique is handy because it works for any path expressible with SVG's path data mini-language.
See also the circular shape tweening example.
forked from <a href='http://bl.ocks.org/mbostock/'>mbostock</a>'s block: <a href='http://bl.ocks.org/mbostock/3916621'>Path Tween</a>
forked from <a href='http://bl.ocks.org/anonymous/'>anonymous</a>'s block: <a href='http://bl.ocks.org/anonymous/d0f28de24658467d48053ef6e39e8413'>Path Tween</a>