Skip to main content
100%

Fork of Color and Size Legends

✓ Published0🌍 Public
ZZach2826
Last edited Apr 30, 2022
Created on Apr 30, 2022

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
MIT Licensed

Similar vizzes