d3 / d3-transition

Animated transitions for D3 selections.
https://d3js.org/d3-transition
ISC License
224 stars 64 forks source link

d3.active(...) returning null #69

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hi there,

I'm having an issue with d3.active(...). When I try to use it to grab a handle to a running transition, it returns null. The transition is definitely still running at the time I select it.

Seems like a bug, or maybe I misunderstood the documentation. Either way heres an example: https://jsfiddle.net/n92vxdn5/

mbostock commented 7 years ago

When you call selection.transition you are scheduling a transition. The transition doesn’t start until the next animation frame (tick). So, calling d3.active on an element for which you just scheduled a transition, even if that transition’s delay is zero, will return null (unless there was another transition running).

hanvyj commented 4 years ago

This caused me a lot of problems using d3 with useEffect in react. A chance set of props changing caused it to schedule two transitions at the same time.

Because they were both within the same tick, active returned null.