Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Bowl of Fruit - General Update Pattern Special Cases

Public visualization

Viewing a saved revision (read-only)

4343e578e0c24eeb9447edc6cd9d4c4d

Bowl of Fruit - General Update Pattern Special Cases

3 stars221🌍 Public
CCurran Kelleher
Last edited Dec 28, 2019
Created on Sep 10, 2018

This example demonstrates the general update pattern in D3, handling special cases when a data array changes through add, remove, and mutation operations. A row of apples rendered as SVG circles is modified over time: one apple is eaten, another becomes a lemon, and a middle apple disappears. The code uses D3’s `selectAll` with data joins, `.enter()`, `.merge()`, and `.exit()` to manage entering, updating, and exiting elements. The `fruitBowl` function uses scaleOrdinal to map fruit types to colors and radii, with circles and text labels positioned by index.

AI-generated description