GitHub - fordnox/flight-indicators: SVG flight instruments for React

GitHub

27 min read Original article ↗

npm downloads

Live demo: every instrument running on simulated flight data, with sliders to drive them by hand.

flight-indicators demo: airspeed, attitude, altimeter, turn coordinator, heading, vertical speed, engine, VOR, VOR / ILS, HSI, ADF, radio, fuel, flaps, tachometer, manifold pressure / fuel flow, fuel quantity, oil, vacuum / ammeter, EGT / fuel flow, annunciator, magnetic compass, elevator trim, Hobbs meter, clock, angle of attack, wind / runway and data panel instruments

Modern SVG flight instruments for React, with no runtime dependencies.

  • Seventeen instruments: Attitude, Heading, HSI (horizontal situation indicator), Airspeed, Altimeter, Vertical speed, Turn coordinator, VOR / CDI, VOR / ILS (crossed needles with glideslope), ADF, Radio panel (NAV / ADF / DME), Wind / runway, Fuel, Flaps, Angle of attack, Engine monitor and a custom Data panel for any readouts you like
  • A classic Cessna 182T style steam-gauge set: Tachometer with hour meter, Manifold pressure / fuel flow, dual-needle Fuel quantity, Oil temperature / pressure, Vacuum / ammeter and EGT / fuel flow gauges (or build your own with DualGauge), a Magnetic compass, Elevator trim, a Hobbs meter and an Annunciator strip
  • Plus RadioStack, an interactive NAV / ADF / DME radio (with an optional NAV2) with editable standby frequencies, and DigitalClock, an interactive panel clock with OAT and voltmeter, flight time, a stopwatch / count-down timer and alarms
  • Pure SVG with no image files, so instruments stay sharp at any size and work with any bundler
  • Written in TypeScript and ships its type declarations
  • Ships ESM and CommonJS builds, works with server-side rendering, and is marked "use client" for the Next.js App Router
  • Smooth CSS animation; the heading and roll take the shortest way round (359° → 1° moves 2°, not 358°)
  • Bad input (NaN, undefined, out of range) is clamped instead of breaking the drawing
  • Accessible: each instrument is an role="img" with a live text label (e.g. "Altimeter: 12340 feet, 29.92 inHg")

Install

Requires React 18 or newer.

Usage

import {
  AttitudeIndicator,
  HeadingIndicator,
  Airspeed,
  Altimeter,
  VerticalSpeed,
  TurnCoordinator,
  VorIndicator,
  IlsIndicator,
  HsiIndicator,
  AdfIndicator,
  RadioPanel,
  relativeBearing,
  WindIndicator,
  FuelIndicator,
  FlapIndicator,
  AoaIndicator,
  EngineIndicator,
  DataPanel,
  DigitalClock,
  Tachometer,
  ManifoldFuelFlowGauge,
  FuelQuantityGauge,
  OilGauge,
  VacuumAmmeterGauge,
  MagneticCompass,
  TrimIndicator,
  HobbsMeter,
  AnnunciatorPanel,
} from 'flight-indicators';

export function Panel({ data }) {
  return (
    <div style={{ display: 'flex', flexWrap: 'wrap', gap: 12 }}>
      <Airspeed speed={data.ias} />
      <AttitudeIndicator roll={data.roll} pitch={data.pitch} />
      <Altimeter altitude={data.altitude} pressure={1013} />
      <TurnCoordinator turnRate={data.turnRate} slip={data.slip} />
      <HeadingIndicator heading={data.heading} />
      <VerticalSpeed verticalSpeed={data.vs} />
      <WindIndicator runway={90} windDirection={data.windDir} windSpeed={data.windSpeed} />
      <VorIndicator course={data.obs} radial={data.navRadial} />
      <IlsIndicator course={data.obs} radial={data.navRadial} glideslope={data.gsDeviation} />
      <HsiIndicator heading={data.heading} headingBug={data.hdgBug} course={data.obs} radial={data.navRadial} glideslope={data.gsDeviation} />
      <AdfIndicator heading={data.heading} bearing={relativeBearing(data.heading, data.ndbBearing)} />
      <RadioPanel nav={{ active: data.nav1, standby: data.nav1Stby }} adf={{ active: data.adf }} dme={data.dme} />
      <DigitalClock oat={data.oat} volts={data.busVolts} flightTimeRunning={data.ias > 50} />
      <FuelIndicator capacity={26} tanks={[{ name: 'Left', quantity: data.fuelL }, { name: 'Right', quantity: data.fuelR }]} />
      <FlapIndicator flaps={data.flaps} airspeed={data.ias} speedLimits={[{ flaps: 0, speed: 160 }, { flaps: 10, speed: 110 }]} />
      <EngineIndicator manifold={{ value: data.map }} rpm={{ value: data.rpm }} cht={data.cht} egt={data.egt} fuelLeft={data.fuelL} fuelRight={data.fuelR} />
      <Tachometer rpm={data.rpm} hours={data.tachHours} />
      <ManifoldFuelFlowGauge manifold={data.map} fuelFlow={data.fuelFlow} />
      <FuelQuantityGauge leftQuantity={data.fuelL} rightQuantity={data.fuelR} />
      <OilGauge temperature={data.oilTemp} pressure={data.oilPress} />
      <VacuumAmmeterGauge vacuum={data.suction} amps={data.amps} />
      <MagneticCompass heading={data.heading} />
      <TrimIndicator trim={data.elevatorTrim} />
      <HobbsMeter hours={data.hobbs} running={data.oilPress > 20} />
      <AnnunciatorPanel lights={{ fuel: data.fuelL < 5 ? 'left' : false, oil: data.oilPress < 20, volts: data.busVolts < 24.5 }} />
      <DataPanel
        heading="Radios"
        fields={[
          { name: 'OAT', value: data.oat, unit: '°C' },
          { name: 'VLOC', value: data.nav1, unit: 'MHz', decimals: 2 },
          { name: 'COM', value: data.com1, unit: 'MHz', decimals: 3 },
          { name: 'Squawk', value: data.squawk },
        ]}
      />
    </div>
  );
}

Common props

Every instrument accepts these props:

Prop Type Default Description
size number | string 200 Width and height. A number means pixels; a string can be any CSS length, e.g. "100%".
showBox boolean true Draw the square mounting plate with screws.
showKnobs boolean true Draw the setting knobs on instruments that have them: OBS on VorIndicator and IlsIndicator, CRS and HDG on HsiIndicator, baro on Altimeter, PUSH (gyro set) on HeadingIndicator, HDG on AdfIndicator and the adjustment knob on AttitudeIndicator. Each knob's rim turns with the value it sets.
animationDuration number 300 Animation time in ms. 0 turns animation off.
className string Class for the root <svg>.
style CSSProperties Inline style for the root <svg>.
title string Overrides the automatic accessible label.

Instruments

<AttitudeIndicator />

Prop Type Default Description
roll number 0 Bank angle in degrees. Positive means right wing down.
pitch number 0 Pitch angle in degrees. Positive means nose up.
pitchLimit number 40 Largest pitch the display shows, in degrees.

<HeadingIndicator />

Prop Type Default Description
heading number 0 Heading in degrees. Any value is accepted and wrapped to 0–359.

<Airspeed />

Prop Type Default Description
speed number 0 Indicated airspeed. Clamped to 0…max.
max number 200 Top of the scale.
arcs AirspeedArcs similar to a Cessna 172 { white?: [min, max], green?: [min, max], yellow?: [min, max], red?: vne }. Pass {} to hide all arcs.
unit string "KNOTS" Unit text printed on the dial.

<Altimeter />

Prop Type Default Description
altitude number 0 Altitude in feet. Negative values work.
pressure number 1013 / 29.92 Altimeter setting shown in the pressure (Kollsman) window.
pressureUnit "hPa" | "inHg" "hPa" Unit of pressure.

<VerticalSpeed />

Prop Type Default Description
verticalSpeed number 0 Vertical speed in ft/min. Positive means climbing.
max number 2000 Full-scale value in ft/min.

<TurnCoordinator />

Prop Type Default Description
turnRate number 0 Rate of turn in °/s. Positive means a right turn. At 3 °/s (a standard-rate turn) the wings line up with the L/R marks.
slip number 0 Position of the slip ball, from -1 (full left) to 1 (full right).

<WindIndicator />

A north-up compass rose with the runway drawn to scale on its heading and the wind arrow on the rim. The runway end facing into the wind is the one in use: its number is lit and green chevrons mark the approach. Two windows show the wind (134° 12G20KT, or CALM) and the headwind and crosswind for the runway in use (HW 8 XW 9R).

Prop Type Default Description
runway number 0 Runway heading in degrees, either end (90 means runway 09/27).
runwaySide "L" | "C" | "R" Parallel-runway letter for the runway end. The other end gets the mirrored letter.
windDirection number 0 Direction the wind blows from, in degrees.
windSpeed number 0 Wind speed in knots. Under 1 kt shows as calm.
windGust number Gust speed in knots. Shown when higher than windSpeed.
crosswindLimit number 15 Crosswind in knots (gusts included) above which the crosswind turns amber.

<VorIndicator />

A VOR / course deviation indicator with an OBS card. The card turns so the selected course sits under the top index, the needle shows how far the course line is to the left or right (5 dots each side, 2° per dot, ±10° full scale) and a triangle points TO or FROM the station. Give it the selected course and the radial the aircraft is on, and it works out the deflection and the TO/FROM flag. Alternatively pass deviation and toFrom straight from your avionics data.

Prop Type Default Description
course number 0 Selected course (OBS) in degrees.
radial number Radial from the station the aircraft is on, in degrees. Drives the needle and the TO/FROM flag.
deviation number Course deviation in degrees, positive when the course is to the right. Clamped to ±10. Overrides radial.
toFrom "TO" | "FROM" | "OFF" TO/FROM flag. Overrides radial. "OFF" hides both triangles.
signal boolean true false shows the red NAV flag, centres the needle and hides TO/FROM.
needle "slide" | "swing" "slide" How the needle moves. "slide" moves a vertical bar sideways over a straight row of dots. "swing" hinges the needle just below the top index so it swings like a pendulum over a curved row of dots, as on older VOR heads, with a TO/FR window on the right.

vorDeviation(course, radial) is exported too and returns { deviation, toFrom } if you want the same maths without the drawing.

<IlsIndicator />

A crossed-needle VOR / ILS head with an OBS card, as found in many light aircraft. The vertical needle shows course (VOR or localizer) deviation and the horizontal needle glideslope deviation, each over a scale of 5 dots either side of the centre circle. Small windows show TO (upper right) or FR (lower left), and orange flags with arrows drop into the window at the bottom when the NAV signal is lost and into the window on the right when there is no glideslope. Course inputs work just like <VorIndicator />: give course and radial, or pass deviation and toFrom directly.

Prop Type Default Description
course number 0 Selected course (OBS) in degrees.
radial number Radial from the station the aircraft is on, in degrees. Drives the course needle and the TO/FROM window.
deviation number Course deviation in degrees, positive when the course is to the right. Overrides radial.
fullScale number 10 Course deviation at full scale (5 dots). 10 suits a VOR; use 2.5 for a localizer.
toFrom "TO" | "FROM" | "OFF" TO/FROM indication. Overrides radial.
signal boolean true false drops the NAV flag, centres the course needle and blanks TO/FROM.
glideslope number Glideslope deviation in degrees, positive when the glidepath is above you (fly up). Leave it out when no glideslope is received.
glideslopeFullScale number 0.7 Glideslope deviation at full scale (5 dots).
glideslopeSignal boolean Whether the glideslope is received. Defaults to true when glideslope is a number; false drops the GS flag and parks the needle.
needles "slide" | "swing" "slide" "slide" moves both needles parallel to themselves over hatched scales. "swing" hinges the course needle near the bottom and the glideslope needle near the left, so they pivot like on older heads; without a glideslope the hinged needle is parked above the scale.
// VOR only: the glideslope flag stays down.
<IlsIndicator course={270} radial={84} />
// ILS approach on a localizer, with the older hinged-needle look.
<IlsIndicator course={265} deviation={-0.8} fullScale={2.5} glideslope={0.2} needles="swing" />

<HsiIndicator />

A horizontal situation indicator: a heading indicator and a VOR / ILS head in one dial. The compass card turns with the heading under a fixed aircraft symbol, so the instrument shows the course line the way you would see it from above. The yellow course pointer turns with the selected course, and its middle section, the deviation bar, slides sideways to show where the course line lies relative to the aircraft (2 dots each side). A white triangle points TO or FROM the station, an orange heading bug marks headingBug, and green pointers on both sides show glideslope deviation. Red flags show NAV when the signal is lost and GS when there is no glideslope. Course inputs work just like <VorIndicator /> and <IlsIndicator />: give course and radial, or pass deviation and toFrom directly. The CRS knob (lower left) turns with the course and the HDG knob (lower right) with the heading bug.

Prop Type Default Description
heading number 0 Aircraft heading in degrees. Any value is accepted and wrapped to 0–359.
headingBug number Heading bug in degrees. Leave it out to hide the bug.
course number 0 Selected course in degrees.
radial number Radial from the station the aircraft is on, in degrees. Drives the deviation bar and the TO/FROM triangle.
deviation number Course deviation in degrees, positive when the course is to the right. Overrides radial.
fullScale number 10 Course deviation at full scale (2 dots). 10 suits a VOR; use 2.5 for a localizer.
toFrom "TO" | "FROM" | "OFF" TO/FROM indication. Overrides radial.
signal boolean true false shows the NAV flag, centres the deviation bar and hides TO/FROM.
glideslope number Glideslope deviation in degrees, positive when the glidepath is above you (fly up). Leave it out when no glideslope is received.
glideslopeFullScale number 0.7 Glideslope deviation at full scale (2 dots).
glideslopeSignal boolean Whether the glideslope is received. Defaults to true when glideslope is a number; false shows the GS flag and hides the pointers.
// Tracking a VOR radial with the heading bug set to the intercept heading.
<HsiIndicator heading={60} headingBug={60} course={90} radial={262} />
// On an ILS approach: localizer sensitivity and glideslope.
<HsiIndicator heading={262} headingBug={265} course={265} deviation={-0.8} fullScale={2.5} glideslope={0.2} />

<AdfIndicator />

An automatic direction finder. The needle points at the tuned NDB: give it the bearing of the station relative to the nose. With heading left at 0 it is a fixed-card ADF that reads relative bearing. Pass the aircraft heading and the card turns with it (a rotatable-card ADF or RMI), so the needle head reads the magnetic bearing to the station and the tail the bearing from it.

Prop Type Default Description
bearing number 0 Relative bearing to the station in degrees, clockwise from the nose.
heading number 0 Heading set on the compass card. 0 gives a fixed card.
signal boolean true false parks the needle at 90° and shows the red ADF flag.

relativeBearing(heading, bearingToStation) is exported too, for when your data gives the magnetic bearing to the station rather than the relative one.

<RadioPanel />

A navigation radio stack: NAV and ADF receivers, each with an active and a standby frequency, and a DME distance readout. Anything you leave out shows as dashes.

Prop Type Default Description
nav { active?: number; standby?: number } NAV (VOR/LOC) frequencies in MHz, shown with two decimals.
adf { active?: number; standby?: number } ADF frequencies in kHz.
dme number DME distance in nautical miles.
color string amber Colour of the digits.

formatNav, formatAdf and formatDme are exported if you want the same number formatting elsewhere.

<RadioStack />

An interactive radio, for when the user tunes the frequencies themselves. Unlike the instruments it is an HTML control rather than an SVG dial: a faceplate with NAV and ADF receivers, each with an active display, an editable standby display and a transfer button, plus a DME readout. Type a frequency in a STBY box and press Enter to tune it (the old active frequency drops to standby), or leave the box to keep it in standby and press ⇄ later. Text that is not a tunable frequency (NAV 108.00–117.95 MHz, ADF 190–1750 kHz) is rejected. The small CLR button above the transfer buttons clears every NAV and ADF frequency.

Pass nav2 (or defaultNav2) to add a second NAV receiver. The rows are then labelled NAV1, NAV2, ADF and DME, CLR clears NAV2 as well, and the DME readout stays with NAV1. Without either prop the panel has a single NAV row, as before.

const [nav, setNav] = useState({ active: 113.4 });
const [adf, setAdf] = useState({});

<RadioStack nav={nav} adf={adf} onNavChange={setNav} onAdfChange={setAdf} navIdent="KNA" dme={12.4} />

// With a second NAV receiver:
const [nav2, setNav2] = useState({ active: 110.5 });

<RadioStack nav={nav} onNavChange={setNav} nav2={nav2} onNav2Change={setNav2} nav2Ident="KLO" adf={adf} onAdfChange={setAdf} dme={12.4} />
Prop Type Default Description
nav { active?: number; standby?: number } NAV frequencies in MHz. Pass it to control the component.
nav2 { active?: number; standby?: number } Second NAV receiver in MHz. Pass it to control it. Shows the NAV2 row.
adf { active?: number; standby?: number } ADF frequencies in kHz. Pass it to control the component.
defaultNav { active?: number; standby?: number } Starting NAV frequencies when nav is left out and the component keeps its own state.
defaultNav2 { active?: number; standby?: number } Starting NAV2 frequencies when nav2 is left out. Shows the NAV2 row.
defaultAdf { active?: number; standby?: number } Starting ADF frequencies when adf is left out.
onNavChange (next) => void Called when the NAV standby is entered, the frequencies are swapped or CLR is pressed.
onNav2Change (next) => void Called when the NAV2 standby is entered, the frequencies are swapped or CLR is pressed.
onAdfChange (next) => void Called when the ADF standby is entered, the frequencies are swapped or CLR is pressed.
navIdent string Identifier of the station being received, shown under the NAV label.
nav2Ident string Identifier of the station being received, shown under the NAV2 label.
adfIdent string Identifier of the station being received, shown under the ADF label.
dme number DME distance in nautical miles (to the NAV1 station).
color string amber Colour of the digits.
width number | string 320 Rendered width in pixels or any CSS length. Everything scales with it.
title string "Radio panel" Accessible name of the group.

It also takes className and style, but not the other common props. parseNav and parseAdf are exported for validating frequencies yourself.

<DigitalClock />

A two-window panel clock as fitted to many light aircraft, with working buttons. The upper display shows bus voltage or outside air temperature; the lower display shows universal time (UT), local time (LT), flight time (FT) or the elapsed timer (ET), with a triangle under the active mode. It keeps running on its own (from the system clock, or from now if you pass simulator time) and is an svg role="group" whose three buttons can be clicked, tapped or used from the keyboard (Tab, then Enter or Space).

<DigitalClock oat={data.oat} volts={data.busVolts} flightTimeRunning={data.ias > 50} onAlarm={(a) => console.log(a)} />
Button Press Hold (2 s)
O.A.T / VOLTS (top) Upper display: volts → °F → °C Display test: every segment lights while held
SELECT Lower display: UT → LT → FT → ET. In set mode: next digit, and confirm after the last one Enter set mode (same as SELECT + CONTROL together)
CONTROL In ET: start → stop → reset. In set mode: step the flashing digit In FT or ET: reset that timer to zero
SELECT + CONTROL together Enter set mode for the mode shown, or confirm it

What set mode sets in each mode:

  • UT: hours and minutes of universal time (onTimeSet reports the new time).
  • LT: the hours of local time; its minutes always follow UT (onLocalOffsetChange reports the new offset).
  • FT: the flight time alarm, HH:MM. 00:00 turns it off.
  • ET: a count-down, MM:SS. CONTROL then starts it; at zero the alarm goes off and ET carries on counting up. 00:00 makes ET a plain stopwatch again.

FT and ET show MM:SS for the first hour and HH:MM after that. ET keeps running while another mode is shown.

Alarms flash their display until any button is pressed (that first press does nothing else) and call onAlarm:

  • "voltage": the bus voltage is below lowVoltage or above highVoltage. The upper display switches to volts while it flashes.
  • "countdown": the ET count-down reached zero. The lower display switches to ET.
  • "flightTime": flight time reached the alarm time. The lower display switches to FT.
Prop Type Default Description
oat number Outside air temperature in °C. Left out or NaN shows dashes.
volts number Bus voltage. Left out or NaN shows dashes.
upperDisplay "volts" | "F" | "C" Upper display reading. Pass it to control the component.
defaultUpperDisplay "volts" | "F" | "C" "volts" Starting reading when upperDisplay is left out.
onUpperDisplayChange (next) => void Called when O.A.T / VOLTS is pressed.
mode "UT" | "LT" | "FT" | "ET" Lower display mode. Pass it to control the component.
defaultMode "UT" | "LT" | "FT" | "ET" "UT" Starting mode when mode is left out.
onModeChange (next) => void Called when SELECT is pressed or an alarm brings its mode up.
now number | Date system clock Current time (ms since the epoch or a Date). Pass simulator time to run the clock, FT and ET from it.
localOffset number Local time offset from UT in minutes, e.g. 120 for UTC+2. Pass it to control the component.
defaultLocalOffset number browser time zone Starting offset when localOffset is left out.
onLocalOffsetChange (minutes) => void Called when LT is set with the buttons.
onTimeSet (utc: Date) => void Called with the new universal time when UT is set with the buttons.
flightTimeRunning boolean true Whether flight time is counting. Wire it to airspeed or the engine.
defaultFlightTime number 0 Flight time already logged when the clock mounts, in seconds.
defaultFlightTimeAlarm number 0 (off) Flight time alarm in seconds.
defaultCountdown number 0 (off) ET count-down in seconds.
lowVoltage number 24.5 / 12.4 Low voltage alarm. The default depends on whether volts looks like a 28 V or a 14 V system.
highVoltage number 32 / 16 High voltage alarm.
onAlarm (alarm) => void Called with "voltage", "countdown" or "flightTime" when an alarm goes off.

It also takes the common props (showKnobs does nothing, since its buttons are always drawn). formatTimer(seconds) is exported to format a timer the way the clock shows it, and HOLD_TIME is the hold time in ms.

<FuelIndicator />

A digital fuel quantity gauge: one vertical bar graph per tank with a numeric readout underneath, FULL when a tank is at capacity, and red when it drops to the low threshold.

Prop Type Default Description
tanks FuelTank[] Left and Right, empty Tanks shown left to right, each { name, quantity, capacity? }. Up to four.
capacity number 50 Full-tank quantity for tanks that don't set their own.
unit string "gal" Unit printed under each readout.
low number 10% of capacity Quantity at or below which a tank turns red.
decimals number 1 Decimal places in the readouts.
label string "FUEL" Caption along the bottom of the display.

<FlapIndicator />

A wing flap position indicator: a vertical LED bar graph that fills from the top as the flaps extend, green at the top through yellow and orange to red at full deflection, with a degree scale beside it and a pointer at the exact position. Optionally shows the maximum flap extension speed for the current setting, which turns red when airspeed exceeds it.

Prop Type Default Description
flaps number 0 Flap position in degrees. Clamped to 0…max.
max number 40 Full flap deflection in degrees.
detents number[] every 10° Scale labels in degrees.
segments number 20 Number of LED segments in the bar.
speedLimits FlapSpeedLimit[] { flaps, speed } pairs in knots: the max speed once flaps are at or beyond flaps. The highest reached entry is shown. Omit to hide the readout.
airspeed number Current airspeed in knots, used to flag an overspeed.
showMph boolean true Also print the limit in mph.
label string "WING FLAP" Caption at the bottom of the dial.

<AoaIndicator />

An angle of attack indicator modelled on panel-mount LED AoA displays. Eleven rows light from the bottom up as the AoA rises: four green bars, a green donut at the optimum AoA, an amber bar, an amber split bar, two amber chevrons and two red chevrons pointing down ("lower the nose"). Rows below the donut are spaced evenly from min to optimum, rows above it from optimum to max. At max every row is lit and the chevrons flash.

Prop Type Default Description
aoa number 0 Current angle of attack in degrees.
min number 0 AoA at which the bottom bar lights.
optimum number halfway to max AoA at which the green donut lights (approach / L/Dmax).
max number 20 Critical AoA: all rows lit and the chevrons flash.
showValue boolean false Print the AoA in degrees under the display.
label string "AOA" Caption at the bottom of the dial.

<EngineIndicator />

An all-in-one engine monitor in the style of a JPI EDM. The top holds a percent-power readout and two arc gauges for manifold pressure and RPM. The left half shows the hottest CHT, EGT and TIT with a per-cylinder bar graph (green CHT, blue EGT, white TIT) and a dashed red CHT limit line. The right half has up to four horizontal bar gauges, and the bottom row shows alternator amps, the two fuel tanks and bus volts. Sections you pass no data for are left blank.

Scaled gauges share one shape, EngineGauge: { value, min, max, green?, yellow?, low?, high?, unit?, decimals? }. green and yellow are [from, to] bands; low and high are red limits. A readout turns yellow inside the yellow band and red at or beyond a red limit.

Prop Type Default Description
power number Percent power printed at the top.
manifold EngineGauge 10–35 inHg Manifold pressure arc. Only value is needed to use the default scale.
rpm EngineGauge 0–3000 Engine speed arc.
cht number[] [] CHT per cylinder, up to six.
egt number[] [] EGT per cylinder, up to six.
tit number Turbine inlet temperature, drawn as the T column.
chtLimit number 400 CHT at which the dashed red line is drawn.
chtScale number 500 CHT that fills a bar to the top.
egtScale number 1700 EGT or TIT that fills a bar to the top.
temperatureUnit string "°F" Printed after the CHT/EGT/TIT headings.
gauges EngineBarGauge[] oil P, oil T, fuel P, fuel F Horizontal bar gauges, each an EngineGauge plus a label. Up to four.
amps number Alternator current.
volts number Bus voltage, shown with one decimal.
fuelLeft number Left tank quantity.
fuelRight number Right tank quantity.
fuelCapacity number 30 Full quantity of each tank, used to fill the tank icons.
fuelUnit string "GAL" Printed under the fuel quantities.

<Tachometer />

An analog tachometer marked in hundreds of RPM, with a green operating arc, a red line and an optional engine hour meter (rolling drums, tenths on the white drum) in the lower half of the dial.

Prop Type Default Description
rpm number 0 Engine speed. Clamped to 0…max.
max number 3500 Top of the scale.
green [number, number] | null [2000, 2400] Green arc. null hides it.
redline number | null 2400 Red line. null hides it.
hours number Engine hours on the hour meter. Leave it out to hide the meter.

<DualGauge /> and the dual-needle engine gauges

The small round engine gauges of a Cessna 172 / 182 panel: two independent scales in one dial, each needle pivoting at its own edge so the two meet in the middle. Both scales read upwards. DualGauge is the generic version; five presets come with Cessna 182T style scales:

Component Props Left needle Right needle
FuelQuantityGauge leftQuantity, rightQuantity Left tank, 0–44 gal Right tank, 0–44 gal
OilGauge temperature, pressure Oil temp 75–250 °F, green 100–245 Oil pressure 0–115 PSI, green 50–90
VacuumAmmeterGauge vacuum, amps Suction 3–7 inHg, green 4.5–5.5 Centre-zero ammeter −60…+60 A
EgtFuelFlowGauge egt, fuelFlow EGT 1250–1650 °F, unnumbered Fuel flow 0–20 GPH
ManifoldFuelFlowGauge manifold, fuelFlow Manifold pressure 10–35 inHg, green 15–23 Fuel flow 0–20 GPH

Every preset also takes leftScale and rightScale to override any part of its scales, e.g. leftScale={{ min: 25, max: 120, unit: '°C' }}. The default scales are exported as FUEL_QUANTITY_SCALE, OIL_TEMPERATURE_SCALE, OIL_PRESSURE_SCALE, VACUUM_SCALE, AMMETER_SCALE, EGT_SCALE, FUEL_FLOW_SCALE and MANIFOLD_SCALE. Check the limits against your own aircraft's POH.

DualGauge props:

Prop Type Default Description
left DualGaugeScale 0–100 Left scale and needle.
right DualGaugeScale 0–100 Right scale and needle.
label string Caption across the top of the dial.
sublabel string Caption across the bottom of the dial.

Each DualGaugeScale: { value, min, max, label, unit, marks, ticks, green, yellow, low, high, decimals }. marks are the numbered scale positions (a number, or { value, text } to print text such as "F"); ticks is the number of minor tick intervals; green and yellow are [from, to] arcs; low and high are red limit lines. Values are clamped to the scale.

<MagneticCompass />

The wet ("whiskey") compass on the glareshield: the card floats behind a window with a vertical lubber line. As on the real thing you read the back of the card, so the numbers grow to the left: heading north, the 3 and 6 are to the left of the lubber line.

Prop Type Default Description
heading number 0 Magnetic heading in degrees. Takes the shortest way round.
deviationCard Array<{ for: number; steer: number }> Compass correction card printed under the window (up to six columns).

<TrimIndicator />

Elevator trim wheel and position indicator as on the pedestal: NOSE DOWN at the top, NOSE UP at the bottom, a white TAKE OFF band and a pointer. The wheel's ribs roll with the trim.

Prop Type Default Description
trim number 0 -1 full nose down, 0 neutral, 1 full nose up.
takeoff [number, number] | null [0.05, 0.35] Take-off range on the same scale. null hides it.

<HobbsMeter />

A Hobbs (flight hour) meter: rolling drums with tenths on a white drum, and a small indicator wheel that turns while the meter runs. It is a rectangular panel item: size sets the width and the height follows. drumPositions(value, digits) is exported if you want to draw drums of your own.

Prop Type Default Description
hours number 0 Hours run.
digits number 6 Number of drums, tenths included.
running boolean false Turns the running indicator.
label string "HOURS" Caption above the counter.

<AnnunciatorPanel />

The annunciator strip above the panel: legends stay dark until lit in red (warning), amber (caution) or green (advisory). Split legends such as L FUEL R light only the side with the fault. The default set is the Cessna 182T's: L FUEL R, OIL PRESS, PITCH TRIM, L VAC R and VOLTS (exported as DEFAULT_ANNUNCIATORS, ids fuel, oil, trim, vac, volts). Like the Hobbs meter it is rectangular, so size sets the width.

Prop Type Default Description
annunciators Annunciator[] DEFAULT_ANNUNCIATORS Legends { id, label, level?, split? }, laid out in up to two rows.
lights Record<string, AnnunciatorState> {} Which lights are on, by id: true, or "left" / "right" / "both" for split legends.
test boolean false Lamp test: lights every legend.

Example: <AnnunciatorPanel lights={{ fuel: 'left', oil: true }} />.

<DataPanel />

A general-purpose instrument for readouts that have no dedicated gauge: temperatures, radio frequencies, transponder code, fuel, timers, anything. It draws a square panel inside the usual round bezel and fills it with a grid of up to six cells. Each cell shows a name, a value and an optional unit. One or two fields stack vertically; three or more use two columns. Long values shrink to fit.

Prop Type Default Description
fields DataField[] [] Readouts to show. Only the first six are drawn.
heading string Caption printed above the panel, also used in the accessible label.

Each DataField:

Field Type Default Description
name string Caption above the value, e.g. "COM1".
value string | number Strings are printed as given. Numbers are formatted with decimals; NaN shows as ---.
unit string Printed in the corner of the cell, e.g. "MHz".
decimals number 0 Decimal places for numeric values.
color string white Colour of the value text, e.g. amber for a caution.

Examples

Examples live under examples/, one folder each:

  • examples/instruments: the gallery behind the live demo, with every instrument on simulated flight data and sliders to drive each one by hand.
  • examples/instruments/navigation.html (live): VOR, ILS and HSI in depth. Track a radial around a VOR station on a map, fly an ILS approach with plan and profile views and LOC / GS failures, and browse snapshots of every needle and flag state with the props behind each one.
  • examples/instruments/panel182.html (live): a Cessna 182T steam-gauge panel laid out like the real one: six-pack with HSI, tachometer, MAP / FF and the small dual-needle engine gauges, NAV 2 and ADF, a radio stack, the annunciator and magnetic compass on the glareshield, Hobbs meter, and the elevator trim and flaps on the pedestal. It flies on simulated data, and buttons trigger low fuel, low oil pressure, vacuum and alternator failures.
  • IFR trainer (separate repository): a radio navigation simulator built with this library.

Development

npm install
npm run dev         # interactive playground (Vite) at http://localhost:5173
npm run build:demo  # static build of the playground in demo-dist/
npm run deploy:demo # build and deploy the playground to harvis.dev (the live demo)
npm test            # unit tests (Vitest)
npm run typecheck
npm run build       # outputs dist/ (ESM + CJS + .d.ts)

Releasing

Releases run from GitHub Actions:

  • CI (ci.yml) runs on every push and pull request. It typechecks, tests and builds on Node 22 and 24, then installs the packed tarball on Node 18, 20 and 22 and checks that every component renders.
  • Release (release.yml) is started by hand from the Actions tab, where you choose patch, minor or major. It bumps the version, commits, tags, creates a GitHub release and then triggers Publish.
  • Publish (publish.yml) publishes to npm with provenance using trusted publishing, so no npm token is stored. It skips versions that are already on npm, so it is safe to re-run.

One-time setup:

  1. Publish the first version by hand (npm login && npm publish), because npm can only set a trusted publisher on a package that already exists.
  2. On npmjs.com, open the package's Settings, then Trusted publishing, and add GitHub Actions with this repository and the workflow file publish.yml.

License

MIT