d3 / d3-transition

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

How to fix replaying transitions when changing tabs? #64

Closed moroshko closed 7 years ago

moroshko commented 7 years ago

I'm implementing a chart that has a sliding x axis. Demo

The problem is, when I change to another tab, and then go back (say after 10 seconds), d3 seems to try to replay the missing transitions, which results in a very awkward behavior of the axis. See here.

@mbostock mentions that:

D3 4.0 fixes this problem by changing the definition of time. Transitions don’t typically need to be synchronized with absolute time; transitions are primarily perceptual aids for tracking objects across views. D3 4.0 therefore runs on perceived time, which only advances when the page is in the foreground. When a tab is backgrounded and returned to the foreground, it simply picks up as if nothing had happened.

Is this really fixed? Am I doing anything wrong?

mbostock commented 7 years ago

That looks like the expected behavior to me. The end event for the old transition doesn’t occur until the tab returns to the foreground, and the speed of the transition is different because your scale’s domain is based on real time (Date.now) rather than perceived time (d3.now).

And as I already mentioned in d3/d3-axis#23, you should probably be using d3.timer rather than transitions to implement a realtime axis.

Please use Stack Overflow tag d3.js to ask for help. Although I make an effort to assist everyone that asks, I am not always available to provide help promptly or directly. Stack Overflow provides a better collaborative forum for self-help: tens of thousands of D3-related questions have already been asked there, and some answered questions may be relevant to you.

When asking for help, please include a link to a live example that demonstrates the issue, preferably on bl.ocks.org. It is often impossible to debug from code snippets alone. Isolate the issue and reduce your code as much as possible before asking for help. The less code you post, the easier it is for someone to debug, and the more likely you are to get a helpful response.

If you have a question about D3’s behavior and want to discuss it with other users, also consider the d3-js Google Group or joining the d3-js Slack.

Thank you! 🤗