-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
selection.merge(transition…)? #257
Comments
I like this line of thinking. Currently the de facto reference example does the following: svg.selectAll("text")
.data(randomLetters(), d => d)
.join(
enter => enter.append("text")
.attr("fill", "green")
.attr("x", (d, i) => i * 16)
.attr("y", -30)
.text(d => d)
.call(enter => enter.transition(t)
.attr("y", 0)),
update => update
.attr("fill", "black")
.attr("y", 0)
.call(update => update.transition(t)
.attr("x", (d, i) => i * 16)),
exit => exit
.attr("fill", "brown")
.call(exit => exit.transition(t)
.attr("y", 30)
.remove())
); I think it does not matter what is returned by svg.selectAll("text")
.data(randomLetters(), d => d)
.join(
enter => enter.append("text")
.attr("fill", "green")
.attr("x", (d, i) => i * 16)
.attr("y", -30)
.text(d => d)
.call(enter => enter.transition(t)
.attr("y", 0)),
update => update
.attr("fill", "black")
.attr("y", 0)
.call(update => update.transition(t)
.attr("x", (d, i) => i * 16)),
exit => exit
.attr("fill", "brown")
.transition(t)
.attr("y", 30)
.remove()
); If selection.merge(transition) did what you suggest here (use the underlying selection), then the example could be simplified to: svg.selectAll("text")
.data(randomLetters(), d => d)
.join(
enter => enter.append("text")
.attr("fill", "green")
.attr("x", (d, i) => i * 16)
.attr("y", -30)
.text(d => d)
.transition(t)
.attr("y", 0),
update => update
.attr("fill", "black")
.attr("y", 0)
.transition(t)
.attr("x", (d, i) => i * 16),
exit => exit
.attr("fill", "brown")
.transition(t)
.attr("y", 30)
.remove()
); This would be quite nice. |
Here's a starting point for a PR that adds this #285 |
Here's an alternative idea that enables the same simplification to usage of |
d3-selection@2 release notes mention:
However thanks to #248 selection.merge could call transition|selection.selection() before merging.
This would simplify a lot the examples in https://observablehq.com/@d3/selection-join.
Note that we can already do:
The text was updated successfully, but these errors were encountered: