I am applying a transition to a group of nodes returned by selectAll()
. I thought the end event would fire after all transitions finished, but each("end",function)
gets called at the end of each transition.
So is there any way to set a callback that will be called after transitions on all selected node finishes ?
Should I use call
for this? but I don't see it used as end callback anywhere in documentation.
also I can run a counter inside each
callback. but is there any way to know how many nodes are still pending to finish transition ? or index of current node in group of selected nodes ?
I've two select() calls in chain like selectAll('.partition').selectAll('.subpartition')
so index argument passed to each callback will rotated n times.
I had the same issue
that the call back gets executed with each element
I have solved that using underscore once method
http://underscorejs.org/#once
As far as I know there is not a built in way to know when the last transition of a group has finished but there are ways around it. One way that I have used several times involves maintaining a count of transitions that have finished.
Here are the links to the relevant documentation:
Here's a clean way to accomplish what you want:
You can then easily call this function like so:
This will work even if the transition is empty.