how to listen for the transition "end" event?

Showing 1-9 of 9 messages
how to listen for the transition "end" event? wimdows 8/4/11 3:49 AM
Hello there,

Both in the documentation and in this forum I have been reading the
advice to "listen for a transition end event".
Now, there are several occassions on which I would love to be doing
just that.

So I would love to see a simple working example of code that does
this.

More specifically, what I'm looking to learn of steal or whatever you
want to call it, is a way to change a year, then have something(s)
change color (or whatever), then up the year, change the colors, up
the year again, change the colors, etcetera.

Currently I use a JavaScript step function (thanks again for that,
Jason).
It works. But it is not very easy to co-ordinate between the
duration(s) of the D3 transitions and the timing parameters of the JS
function.

As Jason suggested in another thread, it would be much neater if one
could stick transitions back to back with event listeners. The
documentation also tells me I can do this, but not how to do it.

To get even more specific: I want to change the fill colors of the
countries on a map, year by year, based on the variables in my data
files.

In any case: thanks for listening so far!

Regards,

wim


Re: how to listen for the transition "end" event? Mike Bostock 8/4/11 10:10 AM
There are two examples I can think of off-hand that use the "end"
event to do staged transitions. The stack-to-group transition, and the
donut transition:

  http://mbostock.github.com/d3/ex/stack.html
  https://github.com/mbostock/d3/blob/master/examples/donut/donut.html

All you need is to say transition.each("end", callback):

  https://github.com/mbostock/d3/wiki/Transitions#each

Note that because each element may have a different delay and
duration, you receive an "end" event per element, rather than just one
for the entire selection.

Mike

Re: how to listen for the transition "end" event? wimdows 8/4/11 11:20 AM
So, just to make sure, if I have something like this:

function changeColors {
  //if some criterium is met stop repeating changeColors and do
something else
  //if not
    //advance year
    //change the colors
  .transition.each("end", changeColors);

that should do the trick?
Re: how to listen for the transition "end" event? Mike Bostock 8/4/11 12:24 PM
Well, d3.select(this).transition().each("end", changeColors). Here's
another example:

http://bl.ocks.org/1125997

Mike

Re: how to listen for the transition "end" event? wimdows 8/4/11 1:47 PM
Thanks, Mike. I´ll go and play around with it.
Cool animation, that! :)
Re: how to listen for the transition "end" event? Jon Frost 8/4/11 5:53 PM
Note how in this example that "some" of the links in the chain start to
disconnect over time and some mouse clicks - http://bl.ocks.org/1125997.

This happens in Chrome and Firefox, though more readily in Firefox I
think.  There are no mouse events specified in the user's script.

Re: how to listen for the transition "end" event? Sinan Aşçıoğlu 12/9/12 2:16 PM
Hey Mike,

I am having a similar issue: I would like to display a message like "Chart Ready!" and start another action after all the transitions end. Is there a way to listen/catch when all transitions ending, instead of catching each individual transitions?
Re: how to listen for the transition "end" event? sha...@gmail.com 2/15/13 1:52 PM
I'd also like to know if there's a way to listen for when all the transitions end. When adding delays, it's hard to use the each(end) thing cleanly.
Re: how to listen for the transition "end" event? Simon Russell 2/17/13 2:38 PM
There has been discussion of this at various times, it seems that it's not in there now either.  Mike's explanation is here:

And here's a more recent thread:

Counting seems like a reasonable approach; you could build a little thing to wrap it up nicely, if you're doing it in lots of places.


--
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/groups/opt_out.