Skip to content
Advertisement

d3 run animations inside function in order

I am trying to run animations in order. Here is an example.

JavaScript

So i want to create a function like this so i can run them in the order rect1(), rect2(), highlightRect() one after another (after each animation ends).

JavaScript

I have tried something like this but it gets messy when there are more animations.

JavaScript

Might be an ignorant question can this be done with promises?

Thanks

Advertisement

Answer

Promisifying these would actually be pretty easy:

First we’ll make the functions return the object we’re chaining on.

JavaScript

Then we can use a generic higher order function to promisify those for us.

JavaScript

Then chaining them is pretty easy:

JavaScript

Making a helper that takes an array of functions or something would be pretty easy here too.

Untested, but I think the general idea would work out.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement