d3 / d3-transition

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

issues when doing .transition(t) #129

Closed theiliad closed 3 years ago

theiliad commented 3 years ago

Hi I think there might be a bug in 3.0 when doing

const t = transition().duration(750);

selectAll("blah blah...")
   .transition(t)
   .attr('opacity', 1);

I keep seeing the error Error: transition 1 not found

I'm using a factory for transitions, and it's been working in previous versions, but updating to 3.0 keeps giving me this error

mbostock commented 3 years ago

Per the README, emphasis added:

If the name is a transition instance, the returned transition has the same id and name as the specified transition. If a transition with the same id already exists on a selected element, the existing transition is returned for that element. Otherwise, the timing of the returned transition is inherited from the existing transition of the same id on the nearest ancestor of each selected element. Thus, this method can be used to synchronize a transition across multiple selections, or to re-select a transition for specific elements and modify its configuration.

If you’re seeing this error, it’s either because (1) the transition has expired (not evident from your code snippet, but you didn’t share a complete working example so it’s impossible to say) or (2) the “blah blah” elements you are selecting are not descendant elements of the transition t.

mbostock commented 3 years ago

(This happens in 3.0 because of #59; in earlier versions, it would silently ignore the t argument when the transition was not found.)

theiliad commented 3 years ago

@mbostock I'm usually good w reading the d3 docs and figuring stuff out, however I still don't understand what could be happening.

Here's how I use transitions:

I've got a factory: https://github.com/carbon-design-system/carbon-charts/blob/8c27e54319d8aabcccdfcee211acc0c669572cef/packages/core/src/services/essentials/transitions.ts#L20-L39

And I use it like so: https://github.com/carbon-design-system/carbon-charts/blob/8c27e54319d8aabcccdfcee211acc0c669572cef/packages/core/src/components/axes/grid.ts#L100-L103

That's all working in 5.x, now trying to upgrade to 6.x or 7.x I keep seeing transition 1 not found

I might've misread your docs, but as a naive fix I tried adding an incrementing ID in my factory

image

and I still get the same error.

Could you pls clarify what needs to change?

theiliad commented 3 years ago

I still feel like I'm not understanding how transitions are supposed to be working

Is this better?

image

image

theiliad commented 3 years ago

bumping

theiliad commented 3 years ago

In case anyone else is having these kinds of issues. I ended up using .call() to handle my transitions

image

image