Distribution

One quantity spread across a fixed set of bins — hours of the day, days of the week, cohorts, buckets — with an optional REFERENCE distribution drawn over it.

data displayclient320pxuiv1.1.0

Preview

Distribution — live rendercharts-distribution--audience-clock

Rendered from the story the storybook (a11y) CI gate runs axe against — the preview can't show something that hasn't been verified.

Install

Two equivalent paths — the URL works in any shadcn-CLI setup; the alias works once you've registered @interlace in your components.json.

Via shadcn URL
npx shadcn@latest add https://ds.interlace.tools/r/distribution.json
With the @interlace alias
npx shadcn@latest add @interlace/distribution

Behavior

What this component does — the keyboard path, the measured colour, the text equivalent and the states it can be in. Every figure below is read out of the test or the source that enforces it by scripts/build-behavior-map.mjs, so nothing here can outlive the gate that keeps it true.

4 steps, 5 key presses — replayed on every PR by the play function of KeyboardCrosshair. Axe cannot press a key, so this — not the a11y scan — is what proves the component is operable without a mouse.

  1. 1the plot is reachable by keyboard at all
  2. 2Home reads out the first bin, naming both seriesHome
  3. 3an unmeasured bin reads "not measured", never zeroArrowRightArrowRightArrowRight
  4. 4Escape clears the crosshair (WCAG 2.1.2)Escape

9 states, one closed union — not a boolean per condition. Partial is a state, not an absence: a spinner that hides progress, or a missing prior rendered as 0, is the failure this model exists to make impossible.

StateReads asRoleEncoding
loadingloadingStands instead of the bodymuted
error! errorStands instead of the bodydanger
not-applicablen/aStands instead of the bodyhatchedrecede
not-countednot countedStands instead of the bodyhatchedmuted
emptynoneStands instead of the bodymuted
partialpartialStands next to the body and changes how to read itdashedmuted
truncatedtruncatedStands next to the body and changes how to read itdashedmuted
first-measurement· first measurementStands next to the body and changes how to read itdashedaccent
idleThe absence of absencemuted

Hatched and dashed are the two absences drawn apart on purpose: not-counted means no measurement was taken and is never a zero; truncated means the total is unknown and must never be used as a denominator. Each state also carries a spoken announcement — transitions, never ticks.

Every semantic colour pair this component's own source uses, measured against the shipped hexes in all 4 theme × scheme combinations. The tightest is viz-axis on card at 3.54:1 (interlace · dark), against a floor of 3:1.

Measured WCAG contrast ratios per token pair and theme
PairinterlacelightinterlacedarkharborlightharbordarkFloor
viz-axis on cardchart axis inside a card3.64:13.54:13.77:14.39:13.0:1SC 1.4.11
viz-axis on backgroundchart axis (SC 1.4.11)3.64:13.82:13.57:14.84:13.0:1SC 1.4.11
destructive on backgrounddestructive tint on the page surface8.31:110.43:17.60:110.03:13.0:1SC 1.4.11
muted-foreground on backgroundsecondary copy9.41:111.32:17.82:19.52:14.5:1SC 1.4.3
destructive on carddestructive tint inside a card8.31:19.66:18.02:19.09:13.0:1SC 1.4.11
muted-foreground on cardsecondary copy in a card9.41:110.48:18.25:18.64:14.5:1SC 1.4.3
foreground on backgroundbody copy19.65:116.97:117.74:116.19:14.5:1SC 1.4.3

Text pairs are held to 4.5:1 (WCAG 2.2 SC 1.4.3); borders, rings and chart axes to 3:1 (SC 1.4.11 non-text). Bold is the worst cell in the row — the one a brand fork has to keep an eye on.

A chart's alt text is not a sentence about the chart — the equivalent of the data is the data. This is what a screen reader gets, read out of the source the install writes into your tree.

Full data equivalentShips a real <table> of every value

Renders <SeriesTable> alongside the graphic: every plotted value is available as a real table row, sr-only by default.

Where it renders, how narrow it survives, and whether its lines are inside the coverage gate — three answers a consumer needs before the paste, not after the bug.

Render boundary
'use client'

Hydrates. It brings JavaScript to any route that imports it — put the boundary here, not at the page.

Minimum viewport
MIN_VIEWPORT = 320

Declared, not assumed. Below 320 CSS px the preflight contract draws a dev-mode outline — how to switch it on.

Coverage gate
100% × 4

Inside the v8 gate: lines 100, statements 100, functions 100, branches 100. A threshold under 100 only records how much you stopped caring, so there isn't one.

History

This component is at v1.1.0, first shipped in @interlace/ui 1.1.0. The version is stamped as a banner into the file the install writes, so the copy in your tree says which one you have — compare it with the number above before deciding whether to re-run the install.

@interlace/ui 1.1.01 entry

  • Addedminor

    New Distribution chart — a quantity spread over a fixed set of named bins, read against a reference distribution. It is a new component rather than an extension of TimeSeries because three of that component's properties are chronological and cannot be parameterised out: its axis keys are sorted (['Thu','Fri','Sat'] sorts into a week that does not exist), a line asserts the metric passed through every value between two samples when between two hourly aggregates there is nothing to pass through, and delta() first-to-last is arithmetic performed on a circle. An unmeasured bin **hatches**. Everywhere else a null can simply be dropped, but for bars a height of zero and a bar never drawn are the same picture — this is null ≠ zero at its hardest case. bin.note prints a second axis reading under the first, replacing the timezone toggle a caller would otherwise build; a toggle hides half the truth and is missing from every screenshot. Also: error states on every chart that fetches — TimeSeries, Sparkline, MetricTable, NetworkGraph, Distribution — resolved through resolveDataState so the precedence is the array in data-state-model rather than five hand-rolled ladders. In a dashboard "the fetch failed" and "there is no data" are different statements. Delta and SeriesTable get none: neither has a fetch lifecycle. StatItem gains tone, carried by three signals rather than a hue alone — the rail, the value colour, and an sr-only judgement.

Import

25 named exports — pull the parts you need.

Public API
import { ANNOTATION_KINDS, AnnotationKind, Direction, Distribution, MIN_VIEWPORT, NumericPoint, areaPath, axisSlots, bandScales, compact, day, delta, describeDistribution, describeSeries, keepAtNarrow, linePath, nearestIndex, nearestSlot, numeric, peakBin, plotScales, seriesScales, slotAt, stepPath, ticks } from '@/components/ui/charts/distribution';

Anatomy

Extracted from the primitive's JSDoc header. The source is the only documentation that can't drift.

<figure data-slot="distribution" data-min-viewport="320" data-peak-bin="14">
    <figcaption>{label}</figcaption>
    <ul data-slot="distribution-legend" />        // only with a reference
    <svg data-slot="distribution-plot" role="img" tabIndex={0}>
      <rect data-slot="distribution-gap" />       // hatched: not measured
      <rect data-slot="distribution-bar" />       // observed
      <path data-slot="distribution-reference" /> // step, never sloped
    </svg>
    <div data-slot="distribution-axis" />         // HTML labels + notes
    <div data-slot="distribution-readout"><output aria-live="polite" /></div>
    <SeriesTable axis="category" />
  </figure>

API reference

Parsed from the type declarations in the source — the same file the install writes into your tree, so this table can't drift from the component you get.

DistributionProps

Also accepts every <figure> attribute.

PropTypeDescription
bins*readonly DistributionBin[]The bins, in the order they belong on the axis. That order is the axis — nothing here sorts them.
labelstringName of the plotted quantity — used in the caption, label, readout and table.
unitstringNoun for the values, e.g. "views", "%".
referenceLabelstringName of the reference overlay. Drawn whenever any bin has a `reference`.
binLabelstringColumn header for the bin column of the data table — "Hour", "Weekday".
heightnumberDrawing height in user units. The rendered height follows the container width.
showTablebooleanRender the data table visibly under the chart instead of `sr-only`.
loadingbooleanRender a `<Skeleton variant="chart" />` placeholder at the chart's own height.
errorunknownThe fetch failed. A different statement from "every bin is empty", which is a real and interesting finding about the subject; this is a fact about the request. Ranked directly under `loading`, per `DATA_STATES`.
announceAnnouncementOptionsContext for the absence sentences — noun, coverage, reason.

Skeleton

Pass loading and the component renders a shape-matched <Skeleton /> in its own place — same box, so nothing reflows when the data lands. Below is the same story with loading={true}.

Distribution — loading statecharts-distribution--loading
Usage
<ANNOTATION_KINDS loading={isPending} />

Accessibility

Every story for this component is rendered headlessly and checked with axe-core (wcag2aa, wcag22aa, best-practice, ACT) on every PR. That gate has no continue-on-error, so what ships has zero known violations.

What follows is what static analysis can see. Axe cannot press a key and never sees an overlay open, so the operable-without-a-mouse claim lives in Behavior instead, where the keyboard path is replayed step by step.

Focus + keyboard behaviour
Native element semantics — no interaction layer to get wrong.
Focus ring (WCAG 2.2 SC 2.4.13)
Inherited from the preflight focus contract shipped in @interlace/theme.
Reduced motion
No animation to gate.
ARIA in the source
  • role="alert"
  • role="img"
  • aria-label
  • aria-live

Examples

10 more states from the same story file.

R-rule compliance

Every primitive in @interlace/ui models to the portable 26-rule floor enforced by the componentApi ESLint preset. The cells below pin exactly where each rule applies in this file.

RuleConceptWhere
R6data-slot on every part`"distribution" / "-plot" / "-bar" / "-gap" / "-axis"`
R7className merged + ...rest`cn(...)` + `{...props}`
R8No `isXxx`; enums`axis="category"` downstream; no boolean modes
R10Composition seams`<SeriesTable>` renders the data; the caller owns the bins
R13Ecosystem firstno charting dep — `bandScales` + SVG is the engine
R14Declares min viewport`data-min-viewport={String(MIN_VIEWPORT)}`
R18Tailwind onlyzero inline `style`
R19Tokens only`fill-chart-1`, `stroke-chart-2`, `stroke-viz-axis`
R20AA contrastaxis + hatch on `--viz-axis` (3.49:1 light / 3.83:1 dark)
R23Absence is a vocabulary`loading` / `error` / no-bins / unmeasured-bin are four
R25Client componentpointer + key handlers, `useState`
R26A11y`role="img"` + label + focusable + live readout + table

Minimum viewport

This primitive declares MIN_VIEWPORT = 320 CSS px (DESIGN_PRINCIPLES #14). When mounted in a container narrower than this, the preflight contract draws a dev-mode outline so the regression is visible during local development.

Opt-in to the dev-mode warning
<body data-interlace-dev>...</body>

Add the data-interlace-dev attribute to the body in development builds only — preflight then outlines any primitive whose container is below its declared data-min-viewport.

Dependencies

Base UI primitive
Native / no Base UI dependency
Lucide icons
none
NPM dependencies
none

Source

The full implementation — components/ui/charts/distribution.tsx once installed.

726 lines · TypeScript
'use client';

import * as React from 'react';

// @interlace/distribution v1.1.0 — Interlace design system.
// Docs, props and live preview: https://ds.interlace.tools/c/distribution
// What changed since: https://ds.interlace.tools/c/distribution#history
// Generated banner — keep it, the upgrade diff reads this version.

/**
 * @interlace/ui — Distribution
 *
 * One quantity spread across a fixed set of bins — hours of the day, days of
 * the week, cohorts, buckets — with an optional REFERENCE distribution drawn
 * over it.
 *
 * ## Why this is not `TimeSeries` with three more props
 *
 * It was attempted that way first. Every part of `TimeSeries` is chronological
 * in a way that cannot be parameterised out:

…706 more lines…

Registry JSON

The raw registry record — what the shadcn CLI fetches.