color and size legends
✓ Published0🌍 Public
Two legends demonstrate how to encode data with color and size in D3 v5. The color legend maps fruit categories to distinct colors using `scaleOrdinal`, while the size legend uses `scaleSqrt` to represent numeric values with scaled circle radii. Each legend is built as a reusable component that appends SVG groups with circles and text labels, spacing them vertically and offsetting text from the markers. The code uses selection joins to update the legends’ marks and labels, with `enter()` handling new elements.
AI-generated descriptionMIT Licensed