Color And Size Legend Ludo
This example demonstrates two distinct legend designs for mapping data to visual encodings in D3 v5: a qualitative color legend and a combined size and color legend. The qualitative legend assigns categorical colors to fruit names using `d3.scaleOrdinal`, while the size legend uses `d3.scaleSqrt` to map numeric values to circle radii, with a corresponding `scaleOrdinal` color scale. The code implements reusable legend components (`colorLegend.js` and `sizeLegend.js`) that update via D3's select-merge-append pattern. The size legend animates its circle positions and text labels over 1000 milliseconds using `.transition().duration(1000)`, while both legends render as SVG elements with `<circle>` and `<text>` marks.
AI-generated descriptionLearn about update pattern - from video