New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<d3-group auto-resize>
breaks when used with transitions
#1665
Comments
Maybe d3fc/packages/d3fc-chart/src/cartesian.js Lines 48 to 49 in b294f0a
const propagateTransition = maybeTransition => selection => {
let selection = selection;
if (isTransition(maybeTransition)) {
try {
selection = selection.transition(maybeTransition)
}
}
return selection
} There's probably a more functional way to write that... This seems like the least surprising way to handle this case. Maybe there's a way to capture the transition before it fires and use it as a template? |
Extends to other places where transition inheritance happens, like in d3fc/packages/d3fc-data-join/src/dataJoin.js Lines 46 to 53 in 344b468
|
Thanks for raising this - it is a big can of worms that very much relates to the complexities of the D3 transition lifecycle: https://github.com/d3/d3-transition#the-life-of-a-transition With d3fc, the various components (chart, series, ...) create new elements using data joins. The goal is to ensure that we propagate any transitions from the select used to render the components over to the elements it creates itself. This will need further investigation! |
Yes, I've been digging through the source (both Perhaps with some guidance I can hack on the library itself and write tests at some point. My current focus is getting my project to function correctly, at least from an outside user perspective, but I'd love to figure out how to contribute. |
Disclaimer: I've not invested too much time in understanding how transitions should work, I've just having a quick poke around the code. I think the "proper" fix would be to observe the lifecycle events of the transition and only propagate it if it is still active. The error we are seeing is ultimately caused because the transition has been removed from the root note once it has ended. This can happen here or here. In each code path I've followed, this removal is immediately preceded by firing the event If we're adding this functionality in then I think it should be encapsulated in one place if we can (like |
Thinking a bit more about this, there are 3 common things we do which would break transition propagation without intervention -
|
So after all that pontificating, I think we need a new utility component/helper that -
|
Hmm, so registering an event handler inside the outer Where would such a component live? It seems like |
Yea that's what I was thinking. Assuming there's no direct way of tracking the state of the transition (which I couldn't easily find).
Agreed. I'm keen it doesn't become a utils package but this problem is tightly coupled to DOM manipulation for which we almost always use |
When rendering a Cartesian chart with a transition,
resizing the window does not update the chart. Many
Uncaught Error: transition 1 not found
errors are logged to console.Seems related to d3/d3-transition#59, since
redraw
retains a reference to the selection originally used to render the chart.Attempting to redraw the chart without the transition once completed, e.g.
causes the axes to resize properly, but the body of the chart is still broken
Recreating all components inside the "end" listener does fix the chart, but seems inefficient (especially for complex charts)
Luckily, it seems sufficient to recreate only the component directly passed to the chart. I.e. if
area
is a multi-series, the series passed toarea.series()
do not need to be recreated. The problem is not unique to multi-series; ifarea
is a "regular" series, it needs to be recreated as well.This works, but seems very hacky. Then again, I'm very new to the
d3
ecosystem, and it seems like solutions like this aren't uncommon. If there's a blessed solution to this, it would be nice to add to the documentation.The text was updated successfully, but these errors were encountered: