Force Transitions to End State and Trigger End Event
Eight circles transition horizontally across an SVG canvas, changing from black to olive at the start and to steelblue at the end. Clicking any circle forces its ongoing transition to jump to the final state and trigger the end event, turning it blue while also shrinking its radius. The code extends `d3.selection.prototype` with a custom `finish` method that invokes active transition timers, then uses `transition.attr` for positioning and `transition.on` for start/end events. Data is a simple array of eight numbers.
AI-generated descriptionPlaying around with transitions as a result of this question on Stack Overflow.
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.