New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
On end method of a group of concurrent transitions...is possible? #76
Comments
This is something I have to do sometimes too and I always end up doing something like this: const size = selection.size();
const done = 0;
const finalFunction = () => {
console.log('all done');
}
selection
.transition()
.delay(d => {
// return a delay that depends on d
})
.duration(d => {
// return a duration that depends on d
})
.on('end', d => {
// ...
done += 1;
if (done === size) {
finalFunction()
}
} but I too would like something cleaner. It would be nice to have something generic so that we can detect if a particular transition is the first or the last one like: const transition = selection.transition();
transition
.delay(d => {
// return a delay that depends on d
})
.duration(d => {
// return a duration that depends on d
})
.on('start', d => {
if (transition.isFirst) { // ... }
if (transition.isLast) { // ... }
})
.on('end', d => {
if (transition.isFirst) { // ... }
if (transition.isLast) { // ... }
}) so keeping that count on the transition object. .on('start', (d, i, event) => {
if (event.isFirst) { // ... }
if (event.isLast) { // ... }
}) This new
I'm not sure this would be good design, just throwing ideas here, but sure this is something I'd use. EDIT .duration(d => {
d.duration = 2 * d.value;
return d.duration;
})
.on('end', d => {
// use d.duration
delete d.duration;
}) |
On second thought, supposing to have the transition |
Here's a quite naïve example of what I mean: https://bl.ocks.org/mindrones/123832bbf5b08ce4b28dab66fae21a69 |
Now that await-async is a thing, I’ve been thinking that transitions could have some Promise-based APIs. One such idea that would address this issue is a transition.end method #77. |
Folding into #77. |
Hi, I would like to know if it's posible to somehow group certain concurrent transitions and execute a function when all of them are finished.
The thing is that I needed to do a transition to animate the modification of two attributes for the same d3 selection so I needed to use concurrent transitions the way that is here:
https://bl.ocks.org/mbostock/5348789
But now I need to execute a specific function after all transitions are finished. Anyone know a way to achieve this?
The text was updated successfully, but these errors were encountered: