liveBook · Manning

Update selection

As explained in D3.js in Action, Third Edition

An update selection is the set of document elements that already correspond to data items and remain associated during a data join.

An update selection contains the document elements already present and still associated with data items after a D3 data join. These elements can retain their position and style or receive updated values. section 7.4.2

During a data update, D3 matches data to elements. A key function such as d => d.uid keeps continuing data attached to the same elements instead of matching by DOM order. section 7.4.2 section 7.5

Use the update selection alongside the other results of a join:

  • Enter selections create elements for newly added data. section 7.4.2
  • Update selections modify elements that remain associated with data. section 7.4.2
  • Exit selections remove elements whose data is no longer present. section 7.4.2
  • Pass separate enter, update, and exit functions to join() when each lifecycle needs different behavior. section 7.4.2 section 7.5

Filtering a cetacean scatterplot

Filtering the scatterplot by hemisphere leaves matching circles in the update selection. Their positions, sizes, or styles can change, while new species enter and removed species exit. A key function preserves each continuing circle's association with its species. section 7.4 section 7.4.2

Figure 7.19 The enter selection represents new elements that need to be created, while the update selection contains the elements that are already displayed on the screen and will remain on the screen. The exit selection is made for elements that need to be removed from the DOM.
figure

Compare the enter, update, and exit selections as the three outcomes of a data join. section 7.4.2

How D3.js in Action, Third Edition covers it

How deep it goes
Explains retained elements, key-based matching, and separate join() callbacks for controlling update behavior.
Examples
Demonstrates hemisphere-filtered cetacean circles entering, updating, and exiting a scatterplot.
What you can do after
Apply via D3's join() method to retain, modify, create, or remove visualization elements during data updates.
How it connects
Connects data joins to enter selections, exit selections, key functions, and the join() method.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of D3.js in Action, Third Edition. The section links point to the parts of the book it draws on.