hydroxy

Cartogram

Regions resized by value. A Dorling cartogram swaps each region for a circle whose area is its value, nudged apart near its centroid; a non-contiguous cartogram shrinks each region about its centroid so area tracks density.

Population of the western states

Each circle's area is the state's 2023 population, placed as near its home as the neighbours allow.

CAWAAZCOORUTNVNMIDMTWY
Population of the western US states, 2023
RegionPeople (m)
Washington7.8m
Oregon4.2m
California39.0m
Nevada3.2m
Idaho2.0m
Montana1.1m
Wyoming0.6m
Utah3.4m
Colorado5.9m
Arizona7.4m
New Mexico2.1m

Same data, non-contiguous

Each state shrinks about its centre until its area matches its population; California, the densest, keeps its size.

Population of the western US states as a non-contiguous cartogram, 2023
RegionPeople (m)
Washington7.8m
Oregon4.2m
California39.0m
Nevada3.2m
Idaho2.0m
Montana1.1m
Wyoming0.6m
Utah3.4m
Colorado5.9m
Arizona7.4m
New Mexico2.1m

Usage

use hydroxy_leptos::cartogram_chart::*;
use hydroxy_leptos::chart_frame::ChartFrame;
use leptos::prelude::*;

/// Rough outlines of the eleven western US states as (longitude, latitude), with their
/// 2023 populations in millions.
#[allow(clippy::too_many_lines, reason = "a table of state outlines")]
fn west() -> Vec<Region> {
    let state = |id: &str, name: &str, people: f64, ring: &[(f64, f64)]| Region::new(id, name, people, ring.to_vec());
    vec![
        state(
            "WA",
            "Washington",
            7.81,
            &[
                (-124.7, 48.4),
                (-123.0, 49.0),
                (-117.0, 49.0),
                (-117.0, 46.0),
                (-119.0, 45.9),
                (-121.2, 45.6),
                (-123.0, 46.2),
                (-124.0, 46.3),
            ],
        ),
        state(
            "OR",
            "Oregon",
            4.23,
            &[
                (-124.0, 46.3),
                (-123.0, 46.2),
                (-121.2, 45.6),
                (-119.0, 45.9),
                (-117.0, 46.0),
                (-116.9, 45.0),
                (-117.2, 44.3),
                (-117.0, 42.0),
                (-124.2, 42.0),
                (-124.5, 43.0),
            ],
        ),
        state(
            "CA",
            "California",
            38.97,
            &[
                (-124.2, 42.0),
                (-120.0, 42.0),
                (-120.0, 39.0),
                (-114.6, 35.0),
                (-114.7, 32.7),
                (-117.1, 32.5),
                (-118.5, 34.0),
                (-120.6, 34.6),
                (-122.5, 37.5),
                (-123.8, 39.8),
            ],
        ),
        state("NV", "Nevada", 3.19, &[(-120.0, 42.0), (-114.0, 42.0), (-114.0, 36.2), (-114.6, 35.0), (-120.0, 39.0)]),
        state(
            "ID",
            "Idaho",
            1.96,
            &[
                (-117.0, 49.0),
                (-116.0, 49.0),
                (-116.0, 47.9),
                (-114.3, 46.6),
                (-113.9, 45.7),
                (-111.0, 44.5),
                (-111.0, 42.0),
                (-117.0, 42.0),
                (-117.2, 44.3),
                (-116.9, 45.0),
                (-117.0, 46.0),
            ],
        ),
        state(
            "MT",
            "Montana",
            1.13,
            &[
                (-116.0, 49.0),
                (-104.0, 49.0),
                (-104.0, 45.0),
                (-111.0, 45.0),
                (-111.0, 44.5),
                (-113.9, 45.7),
                (-114.3, 46.6),
                (-116.0, 47.9),
            ],
        ),
        state("WY", "Wyoming", 0.58, &[(-111.0, 45.0), (-104.0, 45.0), (-104.0, 41.0), (-111.0, 41.0)]),
        state(
            "UT",
            "Utah",
            3.42,
            &[(-114.0, 42.0), (-111.0, 42.0), (-111.0, 41.0), (-109.0, 41.0), (-109.0, 37.0), (-114.0, 37.0)],
        ),
        state("CO", "Colorado", 5.88, &[(-109.0, 41.0), (-102.0, 41.0), (-102.0, 37.0), (-109.0, 37.0)]),
        state(
            "AZ",
            "Arizona",
            7.43,
            &[
                (-114.0, 37.0),
                (-109.0, 37.0),
                (-109.0, 31.3),
                (-111.0, 31.3),
                (-114.8, 32.5),
                (-114.6, 35.0),
                (-114.0, 36.2),
            ],
        ),
        state(
            "NM",
            "New Mexico",
            2.11,
            &[(-109.0, 37.0), (-103.0, 37.0), (-103.0, 32.0), (-106.6, 32.0), (-108.2, 31.8), (-109.0, 31.3)],
        ),
    ]
}

#[component]
pub fn Demo() -> impl IntoView {
    view! {
        <div style="display: grid; gap: 24px;">
            <ChartFrame title="Population of the western states" description="Each circle's area is the state's 2023 population, placed as near its home as the neighbours allow.">
                <CartogramChart regions=west() label="Population of the western US states, 2023" measure="People (m)" projection=Projection::Mercator format=|v: f64| format!("{v:.1}m") />
            </ChartFrame>
            <ChartFrame title="Same data, non-contiguous" description="Each state shrinks about its centre until its area matches its population; California, the densest, keeps its size.">
                <CartogramChart
                    regions=west()
                    kind=CartogramKind::NonContiguous
                    label="Population of the western US states as a non-contiguous cartogram, 2023"
                    measure="People (m)"
                    projection=Projection::Mercator
                    format=|v: f64| format!("{v:.1}m")
                />
            </ChartFrame>
        </div>
    }
}

Anatomy

Componentdata-partRenders
CartogramChartrootfigure; `data-kind` is dorling or non-contiguous, `data-active` while a region is picked out
marksFocusable SVG; arrow keys step through the regions in the order given
landA faint dashed outline of the map, for reference
cellDorling: a group with the region's circle and label; grows out of the centroid
circleDorling circle, area proportional to value, shaded by value
regionNon-contiguous: the region's shape scaled about its centroid
labelThe region's id, on circles big enough to hold it
tooltipName and value of the active region
legendReadout of the active region and the shade scale
sr-tableEvery region with its value

Keyboard

KeyDoes
Arrow keysStep through the regions
Home / EndFirst or last region
EscapeClear the active region

Props

PropTypeNotes
regionsVec<Region>Required. Region::new(id, name, value, ring); .with_colour(n) fills with a series colour instead of the shade
labelStringRequired. What the map shows; the accessible name
measureStringRequired. Name of the value; heads the table column
kindCartogramKindDorling (default) or NonContiguous
projectionProjectionEquirectangular (default), Mercator or Custom(fn)
formatFn(f64) -> StringFormats values in the tooltip, legend and table

Events

PropTypeNotes
on_hoverCallback<Option<Datum>>The mark under the pointer or keyboard focus changes, or is left. Fires only on a change
on_selectCallback<Datum>Click, tap or Enter on a mark
Actions
Button
Icon button
Toolbar
Theme menu
Display
Avatar
Badge
Card
Chip
Code block
Markdown
Doc card
Due pill
Kbd
Priority mark
Source chip
Space icon
Status diamond
Tag
Value diff
Carousel
Reveal
Media timeline
QR code
Transcript viewer
Audio waveform
Audio player
Forms
Calendar
Checkbox
Combobox
Date picker
Color picker
Cron builder
Theme editor
Mention input
Signature pad
Image cropper
Date field
Date range picker
Duration field
Quantity stepper
Filter chip
Input
Markdown editor
Radio group
Search field
Segmented control
Select
Slider
Range slider
Rating
Toggle button
File dropzone
Upload queue
Attachment
Switch
Tags input
Number field
Money field
Phone field
Time field
OTP input
Password field
Questionnaire
Availability picker
Voice input
Recording control
Inline edit
Async validated input
Shortcut recorder
Data
Spreadsheet grid
Week scheduler
Virtual list
Stat card
Step track
Kanban board
Sortable list
Filter builder
Data table
Grid
Access editor
File manager
Gantt chart
Log stream
Diff viewer
JSON inspector
Terminal
Node editor
Whiteboard
Navigation
Table of contents
Breadcrumb
Tabs
Wizard
Nav item
Nav section
Tree view
Pagination
Menubar
Navigation menu
Saved views
Layout
Master detail
App shell
Sidebar layout
Resizable panels
Dashboard layout
Dock layout
Feedback
Callout
Check list
Empty state
Progress bar
Toast
Approval card
Skeleton
Notification center
Bars
Bar chart
Diverging bar chart
Span chart
Pictogram chart
Stacked bar chart
Funnel chart
Bullet chart
Waffle chart
Marimekko chart
Dot plot chart
Error bar chart
Pareto chart
Waterfall chart
Lollipop chart
Grouped bar chart
Bar race chart
KPIs and frames
Chart frame
Metric card
Sparkline
Points
Scatter chart
Smith chart
Strip plot
Beeswarm chart
Parallel coordinates
Ternary chart
Bland-Altman chart
Quiver chart
Connected scatter chart
Grids and tables
Heatmap chart
Chart table
Cohort chart
Radial
Radial charts
Radar chart
Polar area chart
Stat ring
Clock chart
Spiral chart
Lines and areas
Bump chart
Slope chart
Line chart
Composed chart
Small multiples
Cycle plot chart
Horizon chart
Stacked area chart
Threshold chart
Split line chart
Linked charts
Confidence band chart
Forecast fan chart
Step chart
Range area chart
Distributions
Contour chart
Histogram
Box plot
Density chart
Ridgeline chart
Violin chart
Q-Q chart
Survival chart
ECDF chart
Raincloud plot
Forest plot
Maps
Geo map
Bubble map
Hexbin map
Cartogram
Flow map
Parts of a whole
Donut chart
Voronoi treemap
Nested donut chart
Treemap chart
Sunburst chart
Bubble pack chart
Icicle chart
Flame graph chart
Pie chart
Word cloud
Relationships
Sankey chart
Network chart
Chord chart
UpSet chart
Venn chart
Alluvial chart
Adjacency matrix chart
Dependency graph chart
Tree chart
Arc diagram
Hive plot
Edge bundling
Finance
Candlestick chart
OHLC chart
Depth chart
Renko chart
Time
Timeline chart
Calendar heatmap chart
Spectrogram chart
Marey chart
Overlays
Tour
Lightbox
Alert dialog
Command palette
Dialog
Menu
Popover
Tooltip
Sheet
Hover card
Context menu
Utilities
Pacer
Hotkeys
Disclosure
Accordion
Collapsible
Chat
Chat bubble
Voice session
Composer
Thread
Thread list
Assistant composer
Assistant MCP
Assistant modal
Assistant thread
Assistant thread list
Message scroller
Insight note
Emoji picker
Tool trace
Model picker
Citation popover
Activity
Activity feed
Comment thread
Timeline
Presence bar
Live cursors
Reaction bar
Guides
Getting started
All components
All charts