Interrupting Chained Transitions
A grid of black squares pulses with random colors through chained transitions, each square cycling indefinitely until the “Stop The Music” button interrupts the sequence. Built with D3 v3 and SVG animation, the example shows how to prevent chained transitions from overriding a separate transition by checking `this.__transition__.count` before scheduling the next step. Clicking the button triggers a single non-chained transition that turns all squares dark gray, and the chain stops when the count exceeds one.
AI-generated descriptionThis example demonstrates how to interrupt chained transitions. Normally when a chained transition ends, it immediately schedules the next transition. However, blindly scheduling the next chained transition can prevent a different, non-chained transition from taking over — such as the “Stop The Music” button here.
To ensure that a chained transition does not interrupt a different transition, you can check the number of scheduled transitions on the current element: this.__transition__.count. Normally during a chained transition, only one transition will be scheduled; if two transitions are scheduled, then the chained transition should stop.
D3 uses this check internally to implement transition.remove.