Skip to main content
100%

General Update Pattern

✓ Published0🌍 Public
CCurran Kelleher
Last edited Aug 3, 2017
Created on Aug 3, 2017

This example demonstrates how to construct a reusable color legend using D3 v4’s General Update Pattern for nested elements. The code defines a `colorLegend` function that binds a color scale to a group, then appends and merges tick marks for each categorical domain value (setosa, versicolor, virginica). Using selections, enter, and merge, it updates circle radii and fill colors, while text labels are positioned with padding. The legend is rendered as SVG, driven by an ordinal scale with custom hex colors, explicitly showing how to handle enter, update, and exit phases for nested data.

AI-generated description

This is an example intended to show how to work with the General Update Pattern for nested elements using D3 version 4.

mit Licensed

Similar vizzes