Skip to main content
100%

Force Transitions to End State and Trigger End Event (v3)

✓ Published0🌍 Public
Aandrew-reid
Last edited Jul 4, 2018
Created on Jul 4, 2018

Eight circles transition horizontally across an SVG canvas, turning from black to olive on transition start and to steelblue on transition end. Clicking a circle forces its active transition to its final interpolated value and triggers the end event immediately, turning it blue while a secondary transition shrinks its radius. The example extends `d3.selection.prototype` with a custom `finish` method that inspects each transition’s internal timer state, manually invoking its callback with the remaining duration or infinity to flush the animation. It uses D3 v3’s `transition.attr`, `delay`, `duration`, and `each` event handlers on SVG circles.

AI-generated description

Based on a request to modify this block to work with d3v3. The original block is based on this Stack Overflow answer and is intended to create a method to flush transitions on a selection.

The bl.ock adds a method to d3.selection() that allows a user to force the transition to its end state:

  • values transitioned move to the final interpolated values, and
  • the transition end event triggers.

Circles start are drawn intially as black. On the beginning of the transition, after the delay (the transition is initalized prior to the delay start) the nodes turn green and begin to transition across the screen. When the transition ends, the nodes turn blue.

Clicking on the nodes forces the transition to its end point while triggering the end event (nodes turn blue). I've added a second transition on click to show those nodes that have been clicked, this transition reduces node radii.

Similar vizzes