Foundations
Data visualisation
Chart colour that respects the two colour axes, a fixed y-axis, and the table twin every chart needs.
opsinjs is not a charting library. TrendSparkline shows change over time, RangeBar one value against a reference range and ScoreDial a composite score. Apply these rules to any plotting library.
Chart colour
Chart colour follows the two colour axes, and neither axis may tell series apart.
- No series in a status colour. It asserts urgency about the whole dataset and spends the colour kept for escalation (Alerts).
- No series in a category colour either. As thin lines the accents look alike.
- A flagged reading's status goes in words, as a StatusPill beside the chart.
- Reference bands are neutral, labelled and sourced, never green (Reference ranges).
- Colour comes third, after direct labels and a dash, marker or thickness difference, so a greyscale print still parses.
- Pin series one to colour one, and stop at about five series.
- A diverging ramp needs a labelled midpoint set by the product's clinical governance rather than the mean of the visible data.
NOT IMPLEMENTED. This component does not exist in any released version of opsinjs. There is no package to install, no module to import and no props interface to generate code against. Everything on this page is a specification of intended behaviour and may change without notice. Do not write code against it.
The third ramp is not built yet
tokens/color.json declares no chart ramp, so no --opsin-chart-* property exists. TrendSparkline strokes its line with the category -line role in the meantime.
PlannedRoadmapWhat “planned” means
Below, only each caption's StatusPill carries status.
trend-sparkline-a-band-and-a-marked-reading · base base · style base-lyraOpen under the product themeimport { EXAMPLE_SOURCE, type TrendPoint } from "@/lib/opsinjs"
import { TrendSparkline } from "@/components/ui/trend-sparkline"
/**
* How many readings this imaginary product decided make a trend.
*
* It is the product's number, not opsinjs's, which is why it lives in the
* example rather than in the component and why the component has no default for
* it. A design system that picked one would be deciding, for every metric and
* every reader, when three readings become a pattern.
*/
const EXAMPLE_READINGS_A_TREND_NEEDS = 4
const SERIES: TrendPoint[] = [
{ at: "2026-02-01T08:00:00Z", value: 12 },
{ at: "2026-02-02T08:00:00Z", value: 14 },
{ at: "2026-02-03T08:00:00Z", value: 13 },
{ at: "2026-02-04T08:00:00Z", value: 16 },
{ at: "2026-02-05T08:00:00Z", value: 18 },
{ at: "2026-02-06T08:00:00Z", value: 22, status: "attention" },
]
export default function TrendSparklineABandAndAMarkedReading() {
return (
<div className="flex w-full max-w-md flex-col gap-opsin-6 text-opsin-body">
<div className="flex flex-col gap-opsin-1">
{/* The label is drawn by the surface, not by the sparkline. The component
takes `label` for its accessible name and never renders it, because the
card, tile or row a sparkline sits in has already said what it is
about, and a second copy is a second thing to keep in step. */}
<span className="text-opsin-headline">Example measurement</span>
<TrendSparkline
label="Example measurement"
unit="steps"
precision={0}
category="activity"
locale="en-GB"
window="the last 6 entries"
series={SERIES}
minimumPoints={EXAMPLE_READINGS_A_TREND_NEEDS}
range={{ low: 10, high: 20, source: EXAMPLE_SOURCE }}
/>
</div>
<div className="flex flex-col gap-opsin-1">
<span className="text-opsin-headline">Second example measurement</span>
<TrendSparkline
label="Second example measurement"
unit="steps"
precision={0}
category="activity"
locale="en-GB"
window="the last 6 entries"
series={SERIES}
minimumPoints={EXAMPLE_READINGS_A_TREND_NEEDS}
range={{ high: 20, source: EXAMPLE_SOURCE }}
/>
</div>
</div>
)
}Axes
- Fix the y-axis per metric, with its units and precision (Numbers and units). Never fit it to the visible data.
- Start at zero where zero means something, such as steps, and always for bars and areas. Otherwise span the clinically relevant range and state that range beside the chart.
- A new window never rescales the y-axis, and nothing animates.
- Gaps stay gaps (States). TrendSparkline takes one as an entry with
value: null. - Place readings by time taken, not by index.
- Label the last value directly, and give the axis its unit.
- No dual y-axes or projections.
- Draw no trend from too few points. The product sets the minimum (Trends and uncertainty), so TrendSparkline's
minimumPointshas no default.
NOT IMPLEMENTED. This component does not exist in any released version of opsinjs. There is no package to install, no module to import and no props interface to generate code against. Everything on this page is a specification of intended behaviour and may change without notice. Do not write code against it.
A chart that renders every part named here is not built yet
TrendSparkline draws one series and an optional band, with no axes and no interaction.
PlannedRoadmapWhat “planned” means
Table twin
Every chart must ship a table twin, which is the same data in a real table on the same screen. It is never behind a hover, in a modal or visually hidden. Put the summary first, the chart second and the table last.
- Summary. One sentence generated from the data: metric, window, direction, magnitude, coverage and caveat. For example, "Systolic blood pressure, last 14 days: 11 readings, ranging from 118 to 134, with no clear direction. Three days have no reading."
- Chart. One labelled image named by the summary, or hidden when the table sits beside it.
- Table. Units in the header, a caption naming metric and window, and each missing reading as an empty cell with a reason.
NOT IMPLEMENTED. This component does not exist in any released version of opsinjs. There is no package to install, no module to import and no props interface to generate code against. Everything on this page is a specification of intended behaviour and may change without notice. Do not write code against it.
A chart with a table twin is not built yet
No chart in the registry provides a table twin yet.
PlannedRoadmapWhat “planned” means
Build one with Table.
<Table
caption="Example series by period, the readable twin of the chart above, showing an example count for each period"
columns={[
{ key: "period", header: "Period" },
{ key: "count", header: "Count", numeric: true },
]}
rows={[
{ period: "Period one", count: "12" },
{ period: "Period two", count: "1,000" },
]}
/>Accessibility
- WCAG 2.2 SC 1.1.1 is met by the table twin, not by alt text.
- SC 1.4.11 applies to every mark, gridline and tick.
- Whatever hover reveals, keyboard focus reveals.
- The plot shrinks as axis labels grow with text size.
- Test with the screen off: what does the chart show, and what was day three?