Skip to main content

USMap

Every example on this page is live, drawn by the library's Storybook, where you can also change its props and see the result.

A monochromatic SVG map of the United States, shading the 50 states and the District of Columbia using fill patterns and optional numeric labels. Uses the AlbersUSA projection, which composites the contiguous 48 states with insets for Alaska and Hawaii. The map keeps its proportions, filling as much of its box as it can and centered in the rest, in any box it is laid out in.

Import​

import { USMap } from "~lib/data-display/maps/us-map";

Props​

NameTypeRequiredDefaultDescription
dataPartial<Record<USStateName, USMapEntry>>YesN/APer-state shading and optional value
showValuesbooleanNofalseRender numeric labels at state centroids
markersMapMarker[]NoN/APlaces to mark, each in its shape with an optional name beside it
legendMapLegendEntry[]NoN/AWhat each marker shape stands for, in a row under the map
widthnumber | stringNo400Component width (px or CSS string); with height="fill", the column's width unless given
heightnumber | "fill" | stringNo250Component height (px or CSS string), or "fill" to be as tall as its width makes it at the map's proportion

USStateName​

One of the 50 US states or the District of Columbia (51 entries total): "Alabama", "Alaska", "Arizona", ..., "Wisconsin", "Wyoming".

USMapEntry​

type USMapEntry = {
shading: "solid" | "diagonal" | "dots" | "crosshatch";
value?: number;
};

MapMarker​

type MapMarker = {
latitude: number;
longitude: number;
label?: string;
shape?: "circle" | "square" | "triangle" | "diamond"; // "circle" by default
};

type MapLegendEntry = {
shape: "circle" | "square" | "triangle" | "diamond";
label: string;
};

Examples​

Default​

Open Default in Storybook

With Values​

Open With Values in Storybook

All Patterns​

Open All Patterns in Storybook

With Markers​

markers puts a dot on each place you give, with its label beside it where there is room, and a marker's shape draws it as a square, a triangle or a diamond instead, which legend names under the map. height="fill" makes the box as tall as its width makes it at the map's proportion. See WorldMap for how labels are placed, how the legend gives way and how a filled map shrinks.

Open With Markers in Storybook

See Also​

  • WorldMap - Global equivalent using the same pattern system
  • UKMap - United Kingdom equivalent
  • Badge - Inline label for status or counts