Skip to main content
100%

Color and Size Legends - Component Experiment

✓ Published5🌍 Public
CCurran Kelleher
Last edited Jun 9, 2019
Created on Sep 29, 2018

A color legend and a size legend appear side by side in an SVG, each listing categorical or quantitative values with corresponding visual encodings. The color legend uses d3.scaleOrdinal to map fruit names to colors, while the size legend uses d3.scaleSqrt to map numeric values to circle radii. Both legends are implemented as reusable component functions that take their configuration via Object.assign, following the Towards Reusable Charts pattern. The code uses D3 v5 selection methods like .call, .merge, and .attr to update the DOM.

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