Skip to main content
100%

Transition Values - Tween Function

✓ Published0🌍 Public
Aandrew-reid
Last edited Jul 15, 2017
Created on Jul 15, 2017

A circle moves diagonally across an SVG canvas while a text label continuously displays its current x-coordinate, updated during the transition. The example demonstrates a tween function applied to a dummy attribute, `attr.fill`, which is never actually changed. Instead, the tween callback reads the circle’s `cx` attribute at each tick and updates the text content accordingly. Using d3.v4, the code relies on `transition.attrTween` (via `.tween`) and `node.getAttribute` to access live interpolated values over a 5-second duration.

AI-generated description

This method of getting interpolated values during a transition uses a tween function which is normally used for a custom interpolation, but in this case is applied to a dummy attribute that we don't want to change. Instead, we just want to use the tween function to do something else, in this case get the cx value of the circle.

An alternative approach is to use a timer to constantly find the current attribute values during a transition, or alternatively, to conduct the transition itself.

Similar vizzes