Skip to main content
๐ŸŒ Public

Share visualization

Send this visualization to others.

Color and Size Legends

Public visualization

Color and Size Legends

0 stars0๐ŸŒ Public
JJames Malvern
Last edited Mar 23, 2021
Created on Mar 23, 2021

This example demonstrates two reusable legend components rendered as SVG: a color legend using an ordinal scale mapping fruit categories to distinct colors, and a size legend using a square-root scale to encode numeric values through circle area. The color legend displays evenly spaced colored circles with labels, while the size legend computes ticks via `sizeScale.ticks()`, filters out zero, and reverses their order. Both components are built with D3 v5, using `selection.merge()`, `enter()`, and `exit()` patterns to handle dynamic updates, and accept configuration props such as spacing, text offset, and circle styling.

AI-generated description

This is a reusable component using props in a similar way to Reactjs

  • creating a colour legend component
  • encoding area using a square root scale
  • computing ticks from a size scale

Comments

Sign in to join the discussion.

MIT Licensed