Bowl of fruit
This example demonstrates how D3 data joins manage the lifecycle of DOM elements. It shows a bowl of fruits where apples change into lemons, are removed, or disappear entirely, with each fruit rendered as a circle and label. The visualization uses D3 v5’s `selectAll`, `data`, and explicit `enter`, `update`, and `exit` handlers to add, modify, or delete SVG elements based on changing array data. Color and radius are mapped via `scaleOrdinal` based on fruit type.
AI-generated description/* When we call selectAll and data, we create a "data join", we join data (in this case our 5 apples (array) and some elements (DOM elements in this case: our circle)
We have 3 case > Enter : we only have data, no elements
Update : we have both data and elements Exit : we only have elements but no data
In d3 we need to explicitly call thos 3 functions (.enter, .update, .exit)
selectAll give the elements part, .data give the data (always an array)
thanks to that d3 know exactly how much element are on the enter, update and exit */