Charts

Gauge

A gauge — one value against a bounded scale, with optional threshold bands.

Server safePure SVG0 dependenciesSource

Import

Charts live at their own subpath with their own stylesheet, so an app that never draws one pays nothing for them.

import { Gauge } from '@the_viveksingh/vivek-ui/charts'
import '@the_viveksingh/vivek-ui/charts.css'

One value against zones

The needle against a coloured band answers "is it in the healthy zone" before the number is read. The accessible name carries the value, the range and the band label - the SVG is decoration around a figure.

CPU load72CPUCPU load: 72 of 0 to 100, elevated
<Gauge
  title="CPU load"
  value={72}
  caption="CPU"
  bands={[
    { to: 60, color: 'var(--vk-color-success)', label: 'healthy' },
    { to: 85, color: 'var(--vk-color-warning)', label: 'elevated' },
    { to: 100, color: 'var(--vk-color-danger)', label: 'critical' },
  ]}
/>

// For plain percent-complete, ProgressRing is the lighter component.

Accessibility

A chart is not an image

Every chart carries role="img" with a generated accessible name, and renders a real <table> alongside it — visually hidden, never display: none — so a screen-reader user gets the actual numbers instead of "chart". Set accessibleTable={false} only if you have provided the data in a table elsewhere on the page.

No series is ever encoded by colour alone: each carries a distinct dash pattern and marker shape on top of its colour, so the chart survives greyscale printing and every common form of colour blindness.

The palette is verified rather than asserted. Each theme has its own six colours, because one set cannot clear the 3:1 non-text contrast threshold against both a white and a near-black plot surface. Separation is measured under simulated protanopia, deuteranopia and tritanopia: for one to four series — which is nearly every chart — the closest pair sits at ΔE 17, slightly better than the unmodified Okabe-Ito palette it is derived from. Past four series the dash patterns and marker shapes carry the distinction.

Hostile data

Real series contain gaps and rubbish. Every chart is tested against empty arrays, a single point, all-equal values, negatives crossing zero, NaN, ±Infinity, 1e308 and 1e-320, with an assertion that no rendered SVG attribute ever contains NaN. A bad row degrades the chart; it does not blank your page.


Props

Generated from the package's own type declarations, so this table cannot drift from the code.

Props for Gauge
PropTypeDefaultDescription
value requirednumber——
minnumber——
maxnumber——
bandsreadonly GaugeBand[]—Threshold bands under the arc — the "green / amber / red" zones a dashboard gauge exists for. Without bands the track is a single neutral arc.
diameternumber—Diameter of the `viewBox`, in px. The chart scales to its container width.
thicknessnumber—Arc thickness in px.
captionstring—Text under the value, e.g. a unit.
showValueboolean——