Color and Size Legends
✓ Published0🌍 Public
JJames Malvern
Last edited Mar 23, 2021
Created on Mar 23, 2021
This example demonstrates two reusable legend components rendered as SVG: a color legend using an ordinal scale mapping fruit categories to distinct colors, and a size legend using a square-root scale to encode numeric values through circle area. The color legend displays evenly spaced colored circles with labels, while the size legend computes ticks via `sizeScale.ticks()`, filters out zero, and reverses their order. Both components are built with D3 v5, using `selection.merge()`, `enter()`, and `exit()` patterns to handle dynamic updates, and accept configuration props such as spacing, text offset, and circle styling.
AI-generated descriptionThis is a reusable component using props in a similar way to Reactjs
- creating a colour legend component
- encoding area using a square root scale
- computing ticks from a size scale
MIT Licensed