Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

21_color and size legends - General Update Pattern Special Cases

Public visualization

Viewing a saved revision (read-only)

303b1670af8f47e3a0d59410bb4bb8e6

21_color and size legends - General Update Pattern Special Cases

0 stars1🌍 Public
FFMajid-ops
Last edited Dec 20, 2020
Created on Dec 20, 2020

This example demonstrates how to implement reusable color and size legends using the general update pattern in D3 v5. The color legend displays four ordinal categories with distinct colors, while the size legend uses a square root scale to visualize continuous values through circle radii. Both legends are rendered as SVG groups, with data-driven tick marks that update gracefully when the underlying data changes. The code leverages `scaleOrdinal`, `scaleSqrt`, and the `selection.join` pattern to handle enter, update, and exit selections.

AI-generated description