On this page

InstallationOne lineA title that leads somewhere, and its (i)Two to four linesA named color, and its strengthFour linesShort of roomAny width, any heightThe scaleHow values are writtenHours nobody measuredWhile a new range loadsBefore the first values arriveZeroNo dataWhat it is notIn the dashboardAccessibilityAPI ReferenceRulesWritten down

Metric card

A number with its graph, in a card: a title, the number, and one to four lines over time on one scale, with a legend, the scale's values and a tooltip that follows the pointer from point to point.

Tool calls
3,855
  • Tool calls3,855
  • Denied342
Tool calls3,855
  • Tool calls3,855
  • Denied342
  • Tool calls3,855
  • Denied342
0100200300400
1<MetricCard2  title="Tool calls"3  titleHref="/tools"4  titleLink={ScopedLink}5  value={3855}6  series={[7    { label: "Tool calls", value: 3855 },8    { label: "Denied", color: "error", value: 342 },9  ]}10  data={points}11/>

Installation

import { MetricCard } from "@catalog-developer/components";

One line

With no series the card draws one line, named by its title in the tooltip, in the info blue, with the fill under it. There is no legend: the number already says what the line adds up to. A number given as a number is written by the card: whole under 100,000, compact from there (“4.8M”) with the whole one in a Hint.

Tool calls
3,855
0100200300400
1<MetricCard title="Tool calls" value={3855} data={points} />

A title that leads somewhere, and its (i)

titleHref makes the title a link to the page that breaks the number down: its word, then a small chevron. The chevron shows only while the card is under the pointer or the title holds the keyboard's focus (always on a touch screen). titleHint is a 12px (i) after the title, with its own tooltip and its own tab stop: it is never part of the link, and it slides aside as the chevron comes. The chevron waits 150ms after the card is pointed, so a pointer that only crosses the card, or is on its way to the (i), moves nothing; and the (i) never moves while the pointer is on it. titleLink is what renders the link, an a unless set; the dashboard passes its ScopedLink, as the Table takes one in rowLink.

Tokens
4.7M
0100K200K300K400K500K
1<MetricCard2  title="Tokens"3  titleHref="/models"4  titleLink={ScopedLink}5  titleHint="Input includes cached tokens: cache reads and cache writes."6  value={4741650}7  data={points}8/>

Two to four lines

Each entry of series is a line, one value per point in data, in the same order. A series that names no color takes one by its place: the info blue at 100, 70, 45 and 20 percent, the card's own line whole and each next one lighter. The legend stands at the header's right: each series' dot and name, with its own value under it, at 15px. Only the largest series has a fill.

Tokens
4.7M
  • Total4,741,650
  • Input3,181,568
  • Output1,131,625
Tokens4.7M
  • Total4,741,650
  • Input3,181,568
  • Output1,131,625
  • Total4,741,650
  • Input3,181,568
  • Output1,131,625
0100K200K300K400K500K
1<MetricCard2  title="Tokens"3  value={4741650}4  series={[5    { label: "Total", value: 4741650 },6    { label: "Input", value: 3181568 },7    { label: "Output", value: 1131625 },8  ]}9  data={points}10/>

A named color, and its strength

color is one of the design system's eight named colors, the Status dot's: neutral, primary, success, warning, error, info, fuchsia, yellow. Never a hex. strength, 1 to 100, mixes that color with the card's own fill: a lighter line of the same hue, solid in both themes, so two lines that cross never show through each other. A named color is whole unless it is given a strength.

Tool calls
3,855
  • Tool calls3,855
  • Denied342
  • Failed96
Tool calls3,855
  • Tool calls3,855
  • Denied342
  • Failed96
  • Tool calls3,855
  • Denied342
  • Failed96
0100200300400
1<MetricCard2  title="Tool calls"3  value={3855}4  series={[5    { label: "Tool calls", value: 3855 },6    { label: "Denied", color: "error", value: 342 },7    { label: "Failed", color: "error", strength: 45, value: 96 },8  ]}9  data={points}10/>

Four lines

Four is the most: a fifth series is not drawn. With three entries or fewer the legend writes its amounts whole (“4,741,650”); with four it shortens them as the card shortens its number (“4.8M”, the whole one in a Hint), and short of room it cuts its longest name first, down to the next longest, with the whole word in a tooltip.

Tokens
4.7M
  • Total4.7M
  • Input3.2M
  • Output1.1M
  • Reasoning428.5K
Tokens4.7M
  • Total4.7M
  • Input3.2M
  • Output1.1M
  • Reasoning428.5K
  • Total4.7M
  • Input3.2M
  • Output1.1M
  • Reasoning428.5K
0100K200K300K400K500K
1<MetricCard2  title="Tokens"3  value={4741650}4  series={[5    { label: "Total", value: 4741650 },6    { label: "Input", value: 3181568 },7    { label: "Output", value: 1131625 },8    { label: "Reasoning", value: 428457 },9  ]}10  data={points}11/>

Short of room

The card fits any width. The legend gives way in a set order: its longest name is cut (four entries); it takes a line of its own under the number; then every name goes at once and each dot keeps its amount; then the amounts go and the dots stand alone. What is cut or dropped is still said under the pointer and to a screen reader. The title is cut with its whole text in a tooltip, and the scale leaves a card too narrow to keep a plot beside it. Here, the same card at 312px and at 231px.

Tokens
4.7M
  • Total4.7M
  • Input3.2M
  • Output1.1M
  • Reasoning428.5K
Tokens4.7M
  • Total4.7M
  • Input3.2M
  • Output1.1M
  • Reasoning428.5K
  • Total4.7M
  • Input3.2M
  • Output1.1M
  • Reasoning428.5K
0100K200K300K400K500K
Tokens
4.7M
  • Total4.7M
  • Input3.2M
  • Output1.1M
  • Reasoning428.5K
Tokens4.7M
  • Total4.7M
  • Input3.2M
  • Output1.1M
  • Reasoning428.5K
  • Total4.7M
  • Input3.2M
  • Output1.1M
  • Reasoning428.5K
0100K200K300K400K500K
1<div className="w-[231px]">2  <MetricCard title="Tokens" value={4741650} series={series} data={points} />3</div>

Any width, any height

The card has no size of its own to set: it is as wide as what holds it, and it fills the height it is given (a grid's row, a box with a height), the graph taking what the header leaves. Given no height, its graph is 160px tall; given little, the graph stops at 64px. Here, the same card in a box 215px tall and in one 360px tall.

Tool calls
3,855
0100200300400
Tool calls
3,855
0100200300400
1<div className="h-[215px]">2  <MetricCard title="Tool calls" value={3855} data={points} />3</div>4<div className="h-[360px]">5  <MetricCard title="Tool calls" value={3855} data={points} />6</div>

The scale

The scale stands at the graph's right, each value on its line, at round steps from zero: as many as the graph's height holds 28px apart, two to six. yAxis off takes the scale and its lines away, and the line then fills the height.

Tool calls
3,855
1<MetricCard title="Tool calls" value={3855} data={points} yAxis={false} />

How values are written

format is Intl's options (a currency, a percent, a unit) for the card's number, the legend, the scale and the tooltip. write is for what Intl cannot say, an estimate's “~”: two functions, one for a value in the tooltip and one for a value of the scale, where it stands in for format. A value given as text is shown as the screen wrote it, and valueHint is then its whole form, in a Hint.

Est. model cost
~$37.66
~$0~$1~$2~$3~$4
1<MetricCard2  title="Est. model cost"3  titleHint="Estimated from your model rates. Not your provider invoice."4  value="~$37.66"5  data={points}6  write={{ value: (usd) => formatCost("model", usd), scale: (usd) => formatCostAxis("model", usd) }}7/>

Hours nobody measured

A null in a point's values is a value nobody measured, which is not zero: the line stops there and starts again, and the tooltip says a dash. A measured point with none on either side is a dot. The last point is left off the line while its time is still being counted, so an hour that is not over does not read as a drop; the card's number still counts it.

Tool calls
2,744
0100200300400
1<MetricCard title="Tool calls" value={3855} data={[{ at, values: [210] }, { at, values: [null] }, …]} />

While a new range loads

pending says the numbers shown belong to a range that is being replaced: the number, the legend's amounts and the plot dim to half, in 150ms, until the new ones arrive. The title stays, and the card keeps its size.

Tool calls
3,855
  • Tool calls3,855
  • Denied342
Tool calls3,855
  • Tool calls3,855
  • Denied342
  • Tool calls3,855
  • Denied342
0100200300400
1<MetricCard title="Tool calls" value={3855} series={series} data={points} pending />

Before the first values arrive

loading says nothing has arrived yet. The card looks as it does with no data, no number and no legend over the soft wave, and the pill at its middle says “Loading data” after the Loader. The title stays, with its link and its (i), and the card is as tall as it will be with its values.

Tool calls
0
Loading data
1<MetricCard title="Tool calls" value={0} series={[{ label: "Tool calls" }, { label: "Denied", color: "error" }]} data={[]} loading />

Zero

Zero is a measure. A range that was measured and counted nothing is not “No data”: the card says 0, and its own line runs flat on the zero line, with the scale's zero beside it.

Tool calls
0
0
1<MetricCard title="Tool calls" value={0} data={[{ at, values: [0] }, { at, values: [0] }, …]} />

No data

A card with nothing measured at all (no points, or no point that holds a number) keeps its place and its height and shows no number and no legend: a soft wave where the line would be, and “No data” in a small pill at the card's own middle. The title stays, with its link and its (i).

Tool calls
0
No data
1<MetricCard title="Tool calls" titleHref="/tools" titleLink={ScopedLink} value={0} data={[]} />

What it is not

It is one number and how it moved over a range: up to four lines on one scale, read point by point through the tooltip. It is not a chart to explore: no range picker, no zoom, no second scale, no fifth line, and no color of a screen's own. A glance at recent activity that leads to a log, with no number to read, is the Activity chart.

It is the whole card: it draws its own box, title, number, legend and graph, and takes no children. A screen sets it through its props and sizes it through what holds it (a grid's column and row, a flex item, a box): it has no width or height prop.

In the dashboard

No screen draws it yet. It was first drawn for the Home page's analytics cards, and every value here was settled there; those cards move onto it in a following change.

Accessibility

The plot is one tab stop, announced as an interactive chart (role="slider") named by the title and the range it covers (“Tool calls, Nov 18, 2 PM to Nov 19, 2 PM”). Keyboard focus opens the tooltip on the last point, with the focus ring; the left and right arrows move a point, Home and End go to the ends, Escape closes it. Each point is read as a sentence (“Nov 19, 2 PM – 3 PM: 300 tool calls, 54 denied”). Every value is also in a table only a screen reader meets, captioned by the title, since stepping through the points one by one is slow.

A title that is a link is one tab stop, and its (i) the next, named “About” and the title. The keyboard's focus shows the chevron at once. A legend entry that lost its name or its amount still says both under the pointer and to a screen reader.

A finger on the plot opens the tooltip and drags it from point to point; a vertical swipe still scrolls the page.

While loading, the card says it is busy (aria-busy) and its pill is a status that says “Loading data”; there is no plot to reach.

Each series is told by its color and by its name beside its dot, in the legend and the tooltip, never by color alone. In high contrast (forced colors) every line takes the system's text color, each one after the first dashed its own way, and the fill is not drawn. Under reduced motion the tooltip does not slide, its digits change in place, and the title's chevron and (i) change at once, with no slide.

API Reference

Besides these, the props of a <div> (className, aria-*…), which go to the card. No children.

PropTypeDefaultDescription
titlestring—Required. What the number counts (“Tool calls”). One line, cut with its whole text in a tooltip.
titleHrefstring—The page that breaks the number down. The title is then a link to it: its word and a chevron that shows on the card's hover or the title's focus.
titleLinkElementType"a"What renders the title's link, given its href. The dashboard passes ScopedLink.
titleHintstring—What the title means, in a sentence: a 12px (i) after the title, with its own tooltip and tab stop. Never part of the link.
valuenumber | string—Required. The number. A number is written by the card: whole under 100,000, compact from there with the whole one in a Hint. Text is shown as written.
valueHintstring—The whole form of a value the screen shortened itself: the value is then a Hint.
series{ label; color?; strength?; value?; valueHint? }[]—The lines, one to four; a fifth is not drawn. label names the line in the legend and the tooltip. color is one of the Status dot's eight named colors and strength its percent, 1 to 100; with neither, the info blue at 100, 70, 45, 20 by place. value is the line's own amount, under its name in the legend, and valueHint the whole form of an amount given as text. Left out: one line, named by the title, in the info blue.
data{ at: number; values: (number | null)[] }[]—Required. The points: when each one's bucket starts, in ms, and one value per series. null is a value nobody measured; zero is a measure. With no number in it at all, the card says “No data”. Any order; the card sorts them by time.
yAxisbooleantrueThe scale: its values at the graph's right, each on its line.
formatIntl.NumberFormatOptions—How values are written: the card's number, the legend, the scale and the tooltip.
write{ value: (n) => string; scale: (n) => string }—How a value is written where Intl's options cannot say it (an estimate's “~”): in the tooltip, and on the scale, where it stands in for format.
pendingbooleanfalseThe numbers shown are a range's that is being replaced: the number, the legend's amounts and the plot dim to half.
loadingbooleanfalseNothing has arrived yet: the card looks as it does with no data, and its pill says “Loading data” after the Loader. The card keeps its size.

Rules

Written down

One to four lines, in the design system's named colors

A line's color is one of the Status dot's eight, at a strength of 1 to 100 percent. No hex, and no fifth series (METRIC_CARD_SERIES_MAX). A series that names no color takes the info blue at 100, 70, 45, 20 by its place (METRIC_CARD_TONES): one color in four shades stays readable for a color-blind eye whatever the count.

From ds/README.md (Metric card) and ds/lib/metric-card.ts (metricCardTone).

Only the largest series has a fill

The series whose values add up to the most has its color under its line, at 12% in light and 6% in dark. Fills laid over each other would mix into a color no series has. The first line is drawn last, so it is the one seen where lines meet. A line is 1.5px, and turns 6px round at a point.

From ds/components/metric-card.tsx.

The legend gives way in a set order

Whole at the header's right while it fits beside the title and the number. Then its longest name is cut down to the next longest's width (from four entries; an amount is never cut). Then a line of its own under the number, whole, then with that name cut. Past that, all at once: the names go and each dot keeps its amount, then the amounts go.

From ds/lib/metric-card.ts (metricCardLegend, metricCardLegendCut).

A legend's amounts are whole with three entries, shortened with four

Three entries or fewer are written whole (“4,741,650”), so parts can be added up by eye. Four are written as the card writes its number (“4.8M”), the whole one in a Hint, and so is any legend holding an amount of a billion or more. One answer for the whole legend: its amounts are all written alike.

From ds/lib/metric-card.ts (metricCardLegendWhole).

The card's number is whole under 100,000

From 100,000 it is compact with one decimal (“294K”, “4.8M”), the whole number in a Hint whose dotted line shows only while the card is under the pointer or holds the keyboard's focus.

From ds/lib/metric-card.ts (metricCardValue).

The tooltip sits beside the point

Level with the plot's top, to the point's right, or to its left near the end, never over the point. It may cover the scale's values while it is open. Only a chart too narrow to hold it on either side puts it under the chart. It says the point's date and hours (“2 PM – 3 PM”), then each series by its name, its dot and its value. It slides to the next point without closing, and closes 120ms after the pointer leaves the plot.

From ds/components/metric-card.tsx and ds/components/chart-tip.tsx.

Zero is zero, and No data is no data

A range measured at zero says 0 and draws the card's own line flat on the zero line. Only a card with nothing measured (no points, or no point that holds a number) says “No data”: no number, no legend, no scale, the wave and the pill laid over the whole card, 16px in from every edge, so the pill stands at the card's middle. The card is as tall as one with data. A page whose read failed shows its own notice instead, never a row of “No data” cards.

From ds/lib/metric-card.ts (metricCardEmpty) and ds/components/metric-card.tsx (NoData).

The card fills the box it is given

As wide as what holds it; as tall as what holds it says, the graph taking what the header leaves. With no height given, the graph is 160px tall. The graph is never shorter than 64px: three of the scale's values with half a line above and under.

From ds/lib/metric-card.ts (METRIC_CARD_HEIGHT, METRIC_CARD_HEIGHT_MIN).

The title's chevron and (i) move as one

The chevron fades in over a 4px slide and the (i) slides 10px aside for it: 200ms in, 150ms back, as transitions. They wait 150ms after the card is pointed, so a pointer crossing the card moves nothing, and one that came for the (i) is on it before it moves. While the (i) is pointed it and the chevron stay where they stood. The gaps are 6px as the eye sees them, between the word, the chevron and the (i). The room for the chevron is always kept, so nothing else in the card moves.

From ds/components/metric-card.tsx.

Catalog
Foundations
  • Overview
  • Components
  • Tokens
  • Token usage
  • Typography
  • Icons
Atoms
  • Avatar
  • Badge
  • Button
  • Checkbox
  • Color picker
  • Copy button
  • Icon tooltip
  • Inline code
  • Input
  • Hint
  • Kbd
  • Loader
  • Native select
  • Progress bar
  • Progress ring
  • Radio
  • Select
  • Status dot
  • Switch
  • Text link
  • Textarea
  • Tooltip
  • Truncate
Molecules
  • Accordion
  • Activity chart
  • AI elements
  • Alert
  • Button group
  • Card
  • Code block
  • Combobox trigger
  • Command
  • Content table
  • Context switcher
  • Dropdown menu
  • Empty state
  • Field
  • Field group
  • Filter chip
  • Flow
  • Heading
  • Icon picker
  • Icon flow card
  • Metric card
  • Modal
  • Modal confirmation
  • Pagination
  • Popover
  • Scroll area
  • Sidebar
  • Table
  • Tabs
  • Toggle group
LibraryPublished release