Instrument

<o-instrument> is a needle gauge with ticks, a scale, color zones and a digital readout. Presets cover cars, aircraft and computers.

Ticks are .vectors spread over the range with fit-range, the scale is a ring of satellites, zones are arcs on the tick ring and the needle is a vector from the center. They all share one --o-from and --o-range, so they always agree. Changing value only turns the needle.

Presets

tachometer, speedometer, fuel, temp, boost, voltmeter, airspeed, altimeter, cpu, gpu and vu. A preset is a set of defaults: any attribute you write wins over it.

Attributes

AttributeDefaultWhat it does
presetOne of the presets above.
valueminThe reading, kept in the scale: the needle and the readout stop at its ends.
min / max0 / 100Scale range.
range / from270 / autoSweep and start angle.
ticks7Major ticks, each with a scale label.
minor5Minor ticks between two majors.
zones[]Color bands in value units: [{ from, to, color }].
redlineShorthand for a red zone from this value to max.
tick-labelsnumbersYour own scale labels, as a JSON array: '["E", "½", "F"]'.
stepnoneSnaps the reading. See min, max and step.
unit / labelUnit and caption under the readout. With format="unit", unit is an Intl unit and the readout writes it.
digitalondigital="false" hides the number.
caseautoround, square, rounded or bare. Sweeps of 180° or less default to bare: a track band, centered in the box, without a dial.
accent / needle-colorpresetNeedle color. needle-color wins.
face / bezel / tick-colorDial background, its rim and the minor ticks.
size240pxWidth of the widget.
glowoffA glow on the needle and the zones.
format, decimals, currency, localeNumber format of the readout, the scale and aria-valuetext, through Intl.NumberFormat. See Shared options.
themedark, light or glass. Also inherited from an ok-theme-* class on a container. See Shared options.

Styling

The attributes above set these properties on the element. Each one falls back to a kit-wide name, so --ok-accent on a parent colors every instrument and clock inside it.

PropertyFalls back toWhat it does
--ok-inst-accent--ok-accentNeedle and center cap.
--ok-inst-face--ok-faceDial background.
--ok-inst-bezel--ok-bezelDial rim.
--ok-inst-tick--ok-tickMinor ticks.
--ok-inst-tick-MMajor ticks.
--ok-inst-label--ok-textScale numbers and caption.
--ok-inst-readout-colorThe digital value.
--ok-inst-track--ok-trackTrack band of a bare instrument.
--ok-inst-case-bg--ok-caseBackground of a square or rounded case.
--ok-font-sizeBase text size, 7.2cqmin by default.

More examples

Your own scale

A themed panel

A moving needle

Accessibility

An instrument has role="meter" with aria-valuenow, aria-valuemin, aria-valuemax and aria-valuetext, and a name made of its caption, value and range, like “CPU: 64%; range 0 to 100”. Set aria-label to replace it. The needle eases to a new value, except with reduced motion.