d3 / d3-selection

Transform the DOM by selecting elements and joining to data.
https://d3js.org/d3-selection
ISC License
558 stars 292 forks source link

Simplify usage of selection.join with transitions #286

Closed curran closed 3 years ago

curran commented 3 years ago

Related to #257, an alternative to https://github.com/d3/d3-selection/pull/285, this change would allow .join to handle the case that transitions are returned by onenter and/or onupdate. It would support the same simplified usage documented in #257, but leave the behavior of .merge unchanged. Just putting this out there as an alternative to consider, as it targets the main pain point, rather than introducing new behavior in .merge to accomplish the same goal.

This works because of selection.selection.

curran commented 3 years ago

Remaining work:

curran commented 3 years ago

I just realized that if https://github.com/d3/d3-selection/pull/285 lands in addition to this, then we will not need the following:

if (update) update = update.selection();

This is because the updated .merge implementation from https://github.com/d3/d3-selection/pull/285 will do this internally.

mbostock commented 3 years ago

I just realized that if #285 lands in addition to this, then we will not need the following:

if (update) update = update.selection();

This is because the updated .merge implementation from #285 will do this internally.

No, you’ll still want it because otherwise selection.join could return a transition if there’s no enter selection:

  return enter && update ? enter.merge(update).order() : update;
curran commented 3 years ago

Added tests and docs. Ready for review. Thanks!

curran commented 3 years ago

Hooray! Thank you @mbostock 🙏