d3 / d3-transition

Animated transitions for D3 selections.
https://d3js.org/d3-transition
ISC License
224 stars 65 forks source link

Inspect transition state after start? And end? #25

Closed mbostock closed 8 years ago

mbostock commented 8 years ago

Related #24, when transitions start, currently the transitions are initialized in-place, so there’s no way to retrieve the set tween after the transition starts. There’s some risky code when retrieving tweens that checks tween.name against the request name—but it’d be possible for the tween initializer to return a named function, and then have return the initialized value! For example:

var t = d3.transition().tween("foo", function() {
  function foo() {}; // tween.name = "foo"
  foo.value = 42; // tween.value
  return foo;
});
console.log(t.tween("foo")); // function() { function foo() {}; foo.value = 42; return foo; }
setTimeout(function() { console.log(t.tween("foo")); }, 50); // 42

So, oops!

Moreover, after a transition ends (or is interrupted or cancelled), the transition state is deleted from the DOM. Maybe it’s fine to say that transitions are destructive and just fix the above bug to return null, but would it be useful to be able to inspect the transition state after the transition ends? In order to do that, the transition object itself would need to retain the schedule for each node, rather than only storing it in the DOM. Which it could probably do as transition._schedules, or something.

mbostock commented 8 years ago

Fixed. Transitions are destructive and state cannot be inspected after they end.