d3 / d3-transition

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

How to use transition with timer? #65

Closed moroshko closed 7 years ago

moroshko commented 7 years ago

@mbostock It would be great to collect your thoughts on this one: http://stackoverflow.com/q/41800541/247243

The proposed solution feels somewhat hacky. I wonder if we can use d3.active() to solve this?

mbostock commented 7 years ago

It looks like you are starting a transition inside a timer callback, which means you are starting a new transition 60 times a second. Not sure what you are trying to accomplish.

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! 🤗

mbostock commented 7 years ago

Here’s a “fixed” version of your code:

https://bl.ocks.org/mbostock/a29e1eeb2bb15c97663dd336cd13f121

But, I still wouldn’t recommend this approach because you’re doing a lot of needless work on every tick of the timer. It’d be better to do that work only when the data changes (i.e., when the button is pressed).

Based solely on what you’ve shared, I’d do something like this, where you create a short-lived transition for each entering circle on click, and the transition cleans itself up when the circle is no longer needed:

https://bl.ocks.org/mbostock/ad550c9d6d156ac726b45f48fa6ff2c7

moroshko commented 7 years ago

Thanks Mike, this is much more helpful than the previous response 👍