Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active August 27, 2019 09:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelmota/3faa2a2954f5249f61d9 to your computer and use it in GitHub Desktop.
Save miguelmota/3faa2a2954f5249f61d9 to your computer and use it in GitHub Desktop.
D3 callback when all transitions are done
function endAll(transition, callback) {
var n = 0
transition.each(() => ++n)
.each('end', () => (!--n && callback.apply(this, arguments)))
}
// Usage
// d3.selectAll('g').transition().call(endAll, allDone)
@phocks
Copy link

phocks commented Apr 23, 2019

Seems to be built in now, with Promises.

https://github.com/d3/d3-transition#transition_end

Looks like we can do something like this:

d3.selectAll("g")
  .transition("name")
  .duration(1000)
  .end()
  .then(() => {
    // do something
  });

@nrmtmt
Copy link

nrmtmt commented Aug 27, 2019

@phocks you literally saved my life

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment