🌍 Public
Viewing a saved revision (read-only)
ba5e50eea79449d5b917bcb4de81e67d
Color and Size Legends
NNico Donovan
Last edited Jul 17, 2020
Created on Jul 16, 2020
Forked from Bowl of Fruit - Nested General Update Pattern
This example demonstrates how to create categorical color legends and quantitative size legends using D3.js v5’s `scaleOrdinal` and `scaleSqrt` APIs. The color legend maps fruit names to distinct hues, while the size legend encodes numeric values through circle radii using a square root transformation, with tick marks generated from the scale’s `ticks` method. Both legends are rendered as SVG groups containing circles and text, using the nested general update pattern to handle enter/update/exit transitions efficiently.
AI-generated descriptioncreating a color legend component
encoding area using a square root scale
computing ticks from size scale
creating a size legend component
tweaking the styles