This is neat. I've been playing around with implementing this on a joined selection, and I find that I have to set the `_current` property using the .on('end') event,e.g.,
```
chartBody
.selectAll("text")
.data(data)
.join("text")
.transition(t)
.textTween(function (d) {
const i = d3.interpolateRound(this._current | 0, d);
return function (t) { return this._current = i(t); };
})
.on("end", function (d) {
d3.select(this).property("_current", d)
});
```
This works, but is there a more idiomatic approach?
That shouldn’t be necessary (as shown in the cell above). The idea is that _current represents the interpolated data for the currently-shown value. So, even if the transition is interrupted, the next transition will resume from the most recent interpolated value. If you need to reset the _current property at the end of the transition, that suggests that perhaps your interpolator isn’t returning interpolated data (and is instead returning a presentation value)? I’m happy to take a look if you link to a notebook.
Thanks - here is an example notebook: https://observablehq.com/@gallowayevan/d3-texttween-test
It occurs to me that maybe I need to separate out the enter and update in the .join, so that _current is initially set on enter and then only modified from the textTween function. (Example3 in the notebook.)