Color and Size Legends - Component Experiment
This example demonstrates two reusable legend components rendered with SVG: an ordinal color legend for categorical fruit data and a square-root size legend for a numeric 0–10 scale. Using d3.scaleOrdinal and d3.scaleSqrt, it assigns colors and circle radii, while the legends derive their tick marks from the scale’s domain and d3’s `ticks` method. The code follows the “Towards Reusable Charts” pattern by assigning configuration properties directly onto each component function before invoking it with `selection.call`. The resulting graphic shows both legends side-by-side with distinct spacing, text offsets, and transparent circle fills.
AI-generated descriptionAn 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.