Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Fork of Color and Size Legends

Public visualization

Viewing a saved revision (read-only)

511ddc31ce184fe69447b9ada8c2e0ea

Fork of Color and Size Legends

0 stars0🌍 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