why doesn't attrTween pass old datum to function tween()?

427 views
Skip to first unread message

Peter Reinhardt

unread,
Jun 22, 2012, 9:14:53 PM6/22/12
to d3...@googlegroups.com
I'm working on an elliptical arc for a speedometer-type visualization. I see the example for tweening arcs at How-To: Update a Pie Chart (Part 2), but this._current doesn't seem a very satisfying solution.

From the documentation on the github wiki, tween functions get "passed the current datumd, the current index i and the current attribute value a, with the this context as the current DOM element."
function tween(d, i, a) {
  return d3.interpolate(a, String(value));
}
Why doesn't the tween function get the old datum as well? I'd rather not store an external cache of old datum values like this._current... any thoughts?

Thanks,
Peter

Mike Bostock

unread,
Jun 22, 2012, 9:21:21 PM6/22/12
to d3...@googlegroups.com
By the time you call selection.data, you've overwritten the old data
and thus it is not available when you create the transition later.

Also, this._current doesn't store the old data, but the current
interpolated value. (The interpolator returned by d3.interpolateObject
reuses the same object to reduce garbage collection, so the result of
`i(0)` is the same object later returned by `i(t)`.) If the transition
is interrupted, say by clicking twice quickly, a new transition
correctly resumes from the interrupted state.

Mike
Reply all
Reply to author
Forward
0 new messages