A function for triggering a callback at the end of D3.js transitions

If you’re using D3 for animations/transitions then you’ll find often yourself in need of a way to trigger events in sequence. Making it work with one transition is quite easy. Listening for the end of multiple transitions is also easy. But why bother writing the same function multiple times if you can simply use this snippet: