🌍 Public
Viewing a saved revision (read-only)
11cee86b5c2f4dffa63bc287b1bf9f82
Fork of Color and Size Legends
This example demonstrates two reusable legend components built with D3 v5: a color legend using `scaleOrdinal` for categorical data and a size legend using `scaleSqrt` for quantitative values. The SVG rendering shows each legend as a series of labeled circles, with the size legend filtering out zero values and reversing tick order. The code defines exportable functions `colorLegend` and `sizeLegend` that accept scales and layout props, using D3’s data joins and `selection.merge` for enter-update-exit patterns. Styling comes from CSS classes, with the size legend using a semi-transparent circle fill.
AI-generated description