Color and Size Legends - Component Experiment
This example demonstrates two custom legend components—one for a categorical color scale and one for a quantitative size scale—rendered as SVG within a D3 v5 visualization. The color legend uses `scaleOrdinal` to map fruit names to colors, while the size legend uses `scaleSqrt` to map numeric values to circle radii. Both legends are implemented as reusable functions that receive their parameters via `Object.assign`, following the "Towards Reusable Charts" pattern. The code explicitly sets properties on the component functions before invoking them with `.call()`, and each legend updates its groups, circles, and text elements through D3's select, enter, merge, and exit operations.
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.