Mike Bostock
unread,Oct 21, 2012, 11:51:08 AM10/21/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to d3...@googlegroups.com
There's no event at the end of a transition because elements can
transition with different delays and duration. If you want to call a
function when all your elements are done, you can use a reference
counting helper function, like this:
function endall(transition, callback) {
var n = 0;
transition
.each(function() { ++n; })
.each("end", function() { if (!--n) callback.apply(this, arguments); });
}
And then, rather than each("end", callback), say call(endall, callback):
d3.selectAll("g").transition().call(endall, function() {
console.log("all done"); });
Another approach, as Marc suggested, is to pick a single element as a
sentinel (e.g., i === 0 or i === n - 1). You could also do this by
listening to each("end") on a parent transition, say one created by
d3.transition followed by selectAll.
Mike