Skip to main content
100%

General Update Pattern, I

✓ Published0🌍 Public
AAjayyy
Last edited Apr 9, 2019
Created on Apr 9, 2019

This example visualizes the general update pattern in D3, where a data-join is followed by operations on the enter, update, and exit selections. The code uses d3.selectAll, data, enter, merge, and exit with a transition to handle changing arrays of alphabet letters. Entering letters appear in green, updating letters in black, and exiting letters are removed after a 750-millisecond transition that turns them red. The data comes from a shuffled alphabet array, updated every 1.5 seconds via d3.interval.

AI-generated description

Note: d3-selection 1.4 introduced selection.join which greatly simplifies the general update pattern! This series of examples is useful for understanding how joins work in D3, but I recommend you use selection.join in practice.

This example demonstrates D3’s general update pattern, where a data-join is followed by operations on the enter, update and exit selections. Entering elements are shown in green, while updating elements are shown in black. Exiting elements are removed immediately, so they're invisible.

This example does not use a key function for the data-join, so elements may change their associated letter. Entering elements are always added to the end: when the new data has more letters than the old data, new elements are entered to display the new letters. Likewise, exiting letters are always removed from the end when the new data has fewer letters than the old data.

Next: Key Functions

forked from <a href='http://bl.ocks.org/mbostock/'>mbostock</a>'s block: <a href='http://bl.ocks.org/mbostock/3808218'>General Update Pattern, I</a>

gpl-3.0 Licensed

Similar vizzes