Uncertainty Meter
A horizontal axis with a single dot at the point estimate and fading bands at ±1σ, ±2σ, and ±3σ. The standard rendering for a value with calibrated uncertainty — Bayesian posteriors, ensemble predictions, calibrated regression output.
Accuracy0.720 ± 0.080
Customize
Value
0.72
0.080
Display
±2σ
accent
Installation
npx shadcn@latest add https://craftbits.dev/r/uncertainty-meter.jsonUsage
import { UncertaintyMeter } from "@craft-bits/core";
<UncertaintyMeter value={0.72} stddev={0.08} label="Accuracy" />Set sigmaLevels={3} to draw the faintest ±3σ band as well, or pin the axis with range:
<UncertaintyMeter value={50} stddev={5} range={[0, 100]} unit="ms" />Understanding the component
- Two motion-values, four transforms. A
useMotionValueholds the current value, another the current stddev. Per-band x / width are derived from these viauseTransform, so React never re-renders during the spring — every band, the dot, and both whisker ticks track the same two drivers in sync. - Bands fade out with distance. The ±1σ band paints at 42% alpha, ±2σ at 22%, ±3σ at 10%. The same
tonecolor fills all three layers, so the visual reads as a single Gaussian-tinted error bar rather than three discrete rectangles. Outer-to-inner z-order means the ±1σ band stays crisp on top. - Auto-fit range. When
rangeis omitted, the axis spans roughly ±(sigmaLevels + 0.5)σ around the value so the widest band always sits inside the plot with a small breathing margin. The numeric readout's decimal precision is picked from the resolved span. - Springs. Value uses
SPRINGS.smooth(caller can override via thetransitionprop) — it reads as the model's belief drifting. Stddev usesSPRINGS.snap— it reads as a discrete state change (the model just learned how uncertain it is). - Reduced motion. When
prefers-reduced-motion: reduceis set, both motion-values snap to their targets with no spring, regardless oftransition.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | — | Point estimate. |
stddev | number | — | One standard deviation. Clamped to >= 0. |
range | [number, number] | auto-fit | Axis bounds. Auto-fits to roughly ±(sigmaLevels + 0.5)σ when omitted. |
sigmaLevels | 1 | 2 | 3 | 2 | How many sigma bands to draw. |
label | string | — | Optional label rendered to the left of the readout. |
unit | string | — | Optional unit suffix appended to the readout. |
tone | 'default' | 'accent' | 'success' | 'warning' | 'accent' | Semantic color for bands, dot, and readout. |
transition | Transition | SPRINGS.smooth | Spring transition for value updates. |
className | string | — | Merged onto the rendered <div>. |
Accessibility
- Renders with
role="figure"and anaria-labelsummarizing the value, one-sigma uncertainty, and unit — e.g. "Accuracy: 0.72 plus or minus 0.08 (one sigma)." - When
labelis provided, the rendered label element gets anidand becomes the figure'saria-labelledbytarget, so screen readers announce the label too. - The SVG is marked
aria-hidden="true"— the figure's label fully describes the data, and the SVG carries no information not in the readout. - Reduced motion: both value and stddev springs collapse to instant snaps when
prefers-reduced-motion: reduceis set.
Credits
- Extracted from:
craftingattention(app/src/lessons/primitives/nn/UncertaintyMeter.tsx). - The source primitive renders an interactive entropy gauge for a 3-class distribution; this library version is the simpler, generic "point estimate with error bar" pattern.