Skip to main content
100%

Boll of fruit - Hover to select

✓ Published0🌍 Public
Lloicvdk
Last edited Jul 26, 2020
Created on Jul 26, 2020

Five fruit circles are rendered in an SVG, and hovering one turns its outline black. A data join in D3 v5 handles enter, update, and exit states: new fruits grow in, types change between apples and lemons, and removed fruits shrink away. The code uses `d3.selectAll`, `selection.data`, `selection.merge`, and `transition.attr` for the animated updates, with `scaleOrdinal` mapping fruit type to color and radius. The `fruitbowl.js` module manages the rendering.

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 */

MIT Licensed

Similar vizzes