Skip to main content
100%

Fork of Color and Size Legends - Component Experiment

✓ Published0🌍 Public
AAnthony Zornig
Last edited Oct 17, 2021
Created on Oct 17, 2021

This example shows two legends rendered side-by-side in an SVG: one for ordinal color scales and one for square-root size scales. The color legend maps fruit categories to distinct fills, while the size legend displays circular marks scaled by numeric tick values. Both legends are built as reusable component functions that receive parameters via `Object.assign` properties, following the “Towards Reusable Charts” pattern. The code uses d3.v5 APIs including `scaleOrdinal`, `scaleSqrt`, and selection methods like `.call()`, `.enter()`, and `.merge()` to bind data and update the visualization.

AI-generated description

An experiment in passing parameters into "components" by setting properties on the component functions. This is closer to the Towards Reusable Charts pattern, in that you can set state once and invoke the component elsewhere. With this approach you can't tap into the getters and setters though.

MIT Licensed

Similar vizzes