Colour and size legends
✓ Published0🌍 Public
This example demonstrates two types of legends for scatterplots: a color legend using `d3.scaleOrdinal` and a size legend with `d3.scaleSqrt`, both rendered as SVG groups with `circle` and `text` elements. The color legend maps fruit names to distinct colors, while the size legend uses `scaleSqrt` with `ticks()` and `reverse()` to display descending circle radii. The reusable `colorLegend` and `sizeLegend` functions handle enter, update, and exit selections via `selection.merge()`, with spacing and text offsets configured through props. Styling for tick labels and circles comes from CSS classes defined in `styles.css`.
AI-generated descriptionMIT Licensed