D3 documentation says:
The enter selection merges into the update selection when you append or insert. This approach reduces code duplication between enter and update. Rather than applying operators to both the enter and update selection separately, you can now apply them to the update selection after entering the nodes. In the rare case that you want to run operators only on the updating nodes, you can run them on the update selection before entering new nodes.
I don't understand the meaning of the phrase merge into
in the first sentence. Can someone explain this bit? (Perhaps I'm missing a connection with some standard database terminology?)
This means that after you've applied an append
or insert
operation to the enter
selection, its elements will be part of the update
selection. That is, you increase the size of the update
selection. The purpose of this is, as the documentation says, to reduce code duplication. After appending a new element, various attributes have to set (e.g. size, color, position). The same attributes have to be set for elements that are updated in many cases and the same code can be used.
The database equivalent would be selecting rows from different tables (enter
and update
) and then applying some operation to the rows selected from enter
to add them to update
. This analogy doesn't work entirely, but it may help you understand what's going on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With