Skip to main content
100%

Color and Size Legends

✓ Published0🌍 Public
KKaavya Lakshmanan
Last edited Apr 2, 2019
Created on Apr 2, 2019

Two reusable legend components demonstrate color and size encoding in D3 v5. The color legend uses `scaleOrdinal` to map fruit categories to distinct colors with fixed-radius circles, while the size legend uses `scaleSqrt` to map numeric values to circle radii. Both legends render as SVG groups with tick marks, using D3’s data join pattern and `.call()` to apply each component. The size legend filters out zero values and reverses tick order, with text offset dynamically calculated from each circle’s radius.

AI-generated description
MIT Licensed

Similar vizzes