SetInterval, d3 visualisations

320 views
Skip to first unread message

ice

unread,
Apr 13, 2014, 3:09:06 PM4/13/14
to d3...@googlegroups.com
Hi, 

I was wondering is there an alternative way to create visualisations, not using setInterval at all? I am asking this because I want to be able to pause and resume a visualisation and this won't be possible with setinterval function as the times are specified so it will mess up the timings/durations. I have tried setinterval and I can't seem to think how I can get pause and resume to work with it.  

Any suggestions/help in the right direction will be really appreciated! I am really stuck on this right now. 

Thank you!

ice

unread,
Apr 13, 2014, 4:49:18 PM4/13/14
to d3...@googlegroups.com
Or is there anyway to get pause and resume functions to work with setInterval? 

Thank you! 

Ian Johnson

unread,
Apr 13, 2014, 4:57:47 PM4/13/14
to d3...@googlegroups.com
you can use d3.timer and control it's pausing or resuming.

related questions:
examples:


--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Ian Johnson - 周彦

Ethan Jewett

unread,
Apr 13, 2014, 4:58:33 PM4/13/14
to d3...@googlegroups.com
What Ian said. If you really want to use setInterval, I believe the setInterval function returns and intervalID. You can pass this ID to the clearInterval function to stop the interval from running, and then create a new one when the user resumes.


--

ice

unread,
Apr 13, 2014, 8:58:34 PM4/13/14
to d3...@googlegroups.com
Thank you Ian and Ethan for your suggestions. :) I didn't think SetInterval would work because I thought it would clear the timer for the specified ID so when you resume the animations they will be in the wrong order or start again the transition which was incomplete when paused but I will try what you said Ethan. I will keep in mind about d3.timer for my next visualisation.

Thank you once again!

Ethan Jewett

unread,
Apr 14, 2014, 9:24:00 AM4/14/14
to d3...@googlegroups.com
I haven't used clearInterval with transitions, but I believe that once an interval has fired, any processing based on that firing will complete regardless of whether the interval is cleared. So I think transitions will complete, not pause. Not sure about what happens if you are using d3.timer.

Ian Johnson

unread,
Apr 14, 2014, 1:08:50 PM4/14/14
to d3...@googlegroups.com

d3.timer uses requestAninationFrame which is much more reliable than setTimeout.
if your calculations take longer than the timeout your visualization will start to lag and stutter and possibly not recover. using d3.timer or requestAnimationFrame will keep the browser at a usable FPS.
Also when you lose focus of your page setTimeout will keep running hogging the users resources unnecessarily.

just use d3.timer, its got a nicer interface and will work much better.

ice

unread,
Apr 15, 2014, 10:30:22 AM4/15/14
to d3...@googlegroups.com
Thank you Ethan and Ian for your replies. :D
I think I will go with d3.timer now, hopefully won't take too much time to change the implementation and get pause and resume to work. I didn't think setInterval was a good way for the visualisation when I initially started doing it but couldn't think of an alternative way as I am quite new to d3. 
Thanks once again for your suggestion! 

marc fawzi

unread,
Apr 15, 2014, 12:00:37 PM4/15/14
to d3...@googlegroups.com
fyi, if you need to control the maximum FPS while using rFA, there is a good way to do that

Chris Viau

unread,
Apr 28, 2014, 3:33:54 PM4/28/14
to d3...@googlegroups.com
Here is an example of pausing and resuming a transition: http://xaedes.de/dev/transitions/
ChrisV

Jonas Langvad

unread,
Apr 28, 2014, 5:22:55 PM4/28/14
to d3...@googlegroups.com
Very nice example! My social network conditioned self was looking for a "like" button :)

Marc Fawzi

unread,
Apr 28, 2014, 11:00:21 PM4/28/14
to d3...@googlegroups.com, d3...@googlegroups.com
Would be nice to turn this into .pause() and .resume() that can be called on selection and make a pull request

Sent from my iPhone
--
Reply all
Reply to author
Forward
0 new messages