One reading on a half dial, with bands that say whether it's fine and a mark for the target.
- 2.1 kB JS 3.0 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Right-to-left
- 13 tests
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Gauge } from "./ui/uicontext/components/charts/Gauge.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ row: { display: "flex", flexWrap: "wrap", justifyContent: "center", gap: space.xl } })const ms = { style: "unit", unit: "millisecond" } as const// a service's health at a glance: latency against its budget, error rate against the SLO, CPU loadexport const ServiceHealth = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.row)).children( Gauge(h, { label: "p95 latency", value: 182, max: 400, format: ms, target: 250, bands: [{ upTo: 250, tone: "good", label: "Within budget" }, { upTo: 320, tone: "warning", label: "Slow" }, { upTo: 400, tone: "danger", label: "Too slow" }], }), Gauge(h, { label: "Error rate", value: 0.0071, max: 0.01, format: { style: "percent", digits: 2 }, bands: [{ upTo: 0.005, tone: "good", label: "Healthy" }, { upTo: 0.008, tone: "warning", label: "Near the SLO" }, { upTo: 0.01, tone: "danger", label: "Breaching" }], }), Gauge(h, { label: "CPU", value: 0.93, max: 1, format: { style: "percent", digits: 0 }, bands: [{ upTo: 0.7, tone: "good", label: "OK" }, { upTo: 0.85, tone: "warning", label: "Busy" }, { upTo: 1, tone: "danger", label: "Saturated" }], }), )When to use
One reading on a half dial, with bands that say whether it's fine and a mark for the target. Use Meter instead when the value sits in a row, not on its own.
Usage
import { Gauge } from "./ui/uicontext/components/charts/Gauge.ts"export const Storage = <M>(h: Html.H<M>) => Gauge(h, { label: "Disk", value: 0.62, max: 1, format: { style: "percent" }, bands: [{ upTo: 0.8, tone: "good", label: "OK" }, { upTo: 1, tone: "danger", label: "Nearly full" }] })Examples
A score against a goal
Without bands the arc takes the first chart color. target marks the goal on the track.
import type { Html } from "effect/ui/html"import { Gauge } from "./ui/uicontext/components/charts/Gauge.ts"// customer satisfaction this quarter, out of 5, with the team's goal markedexport const Satisfaction = <M>(h: Html.H<M>) => Gauge(h, { label: "Customer satisfaction, Q4", value: 4.3, min: 1, max: 5, target: 4.5, size: 240, format: { style: "number", digits: 1 }, })API reference
Options
| Name | Type | Default | Description |
|---|---|---|---|
labelrequired | string | — | What's measured: "p95 latency" |
valuerequired | number | — | — |
min | number | — | — |
maxrequired | number | — | — |
format | ChartFormat | — | — |
bands | GaugeBand[] | — | Stretches of the track that mean something, low to high |
target | number | — | A goal, marked with a tick on the track |
size | number | 200 | Pixels wide; 200 by default |
locale | string | — | — |
style | Style | — | — |
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/gauge