Speed gauge
The speed through the water on a 225 degree arc, with a needle, advice zones and a setpoint marker.
On this page
Code
import {
AdviceType,
ObcSpeedGaugeNeedleType,
Priority,
SpeedGauge,
TickmarkStyle,
type SpeedAdvice,
} from "@bosunkit/instruments";
import { useEffect, useState, type CSSProperties, type Dispatch, type ReactElement, type SetStateAction } from "react";
export const description: string =
"Surfing downwind on a live feed: the speed through water climbs past the polar target and into the caution zone " +
"on each wave, while a second gauge shows the speed over ground on a scale that runs astern, with the speed " +
"needed to make the bridge opening being adjusted.";
/** Hull speed of a Hanse 460 is about 8.8 knots; a surf past 10 knots is where she starts to broach. */
const STW_ADVICES: SpeedAdvice[] = [
{ minSpeed: 7, maxSpeed: 8.8, type: AdviceType.advice, hinted: true },
{ minSpeed: 10, maxSpeed: 12, type: AdviceType.caution, hinted: true },
];
const SOG_ADVICES: SpeedAdvice[] = [{ minSpeed: -2, maxSpeed: 0, type: AdviceType.caution, hinted: false }];
const PANEL: CSSProperties = {
display: "flex",
flexWrap: "wrap",
alignItems: "flex-end",
justifyContent: "center",
gap: 32,
width: "100%",
maxWidth: 660,
};
const FIGURE: CSSProperties = { display: "flex", flexDirection: "column", alignItems: "center", gap: 6, margin: 0 };
const CAPTION: CSSProperties = { fontSize: 13, color: "var(--text-dim)", textAlign: "center", maxWidth: 240 };
/** Speed through water in knots at a time in seconds: a steady run with a surf on every set of waves. */
function speedAt(time: number): number {
const surf: number = Math.max(0, Math.sin((2 * Math.PI * time) / 12)) ** 2;
return 7.2 + 0.4 * Math.sin(time / 3) + 3.4 * surf * (0.6 + 0.4 * Math.sin(time / 17));
}
export default function Showcase(): ReactElement {
const [second, setSecond]: [number, Dispatch<SetStateAction<number>>] = useState<number>(0);
useEffect((): (() => void) => {
const interval: number = window.setInterval((): void => {
setSecond((previous: number): number => previous + 1);
}, 1000);
return (): void => {
window.clearInterval(interval);
};
}, []);
const speed: number = speedAt(second);
// A 1.2 knot foul tide takes off part of the speed through water.
const overGround: number = speed - 1.2;
// The navigator moves the speed needed to make the bridge opening between 6 and 7 knots every ten seconds,
// turning the knob for the last two.
const target: number = Math.floor(second / 10) % 2 === 0 ? 6 : 7;
const adjusting: boolean = second % 10 >= 8;
return (
<div style={PANEL}>
<figure style={FIGURE}>
<SpeedGauge
speed={speed}
minSpeed={0}
maxSpeed={12}
needleType={ObcSpeedGaugeNeedleType.full}
priority={Priority.enhanced}
tickmarkStyle={TickmarkStyle.enhanced}
tickmarkInterval={1}
showLabels
speedAdvices={STW_ADVICES}
setpoint={7.4}
autoAtSetpoint
autoAtSetpointDeadband={0.3}
animateSetpoint
hasReadout
label="STW"
unit="KN"
fractionDigits={1}
faceDiameter={230}
/>
<figcaption style={CAPTION}>Through the water, against the 7.4 knot polar target</figcaption>
</figure>
<figure style={FIGURE}>
<SpeedGauge
speed={overGround}
minSpeed={-2}
maxSpeed={10}
needleType={ObcSpeedGaugeNeedleType.bar}
tickmarkInterval={2}
tickmarksInside
showLabels
speedAdvices={SOG_ADVICES}
setpoint={target}
newSetpoint={adjusting ? (target === 6 ? 7 : 6) : undefined}
touching={adjusting}
setpointAtZeroDeadband={0.2}
setpointOverride
hasReadout
label="SOG"
unit="KN"
fractionDigits={2}
faceDiameter={170}
/>
<figcaption style={CAPTION}>
Over the ground, astern below zero, against the speed needed for the bridge
</figcaption>
</figure>
</div>
);
}
The speed gauge shows the speed on a 225 degree arc that runs clockwise from nine o'clock to half past four. A
full-length needle or a short bar points at the value, advice zones mark ranges on the scale, and an optional readout
prints the number with its label (STW by default) and unit (KN). A scale that includes negative speeds extends
below zero. It ports obc-speed-gauge; the overview lists the other instruments.
Examples
Speed
Code
import { SpeedGauge } from "@bosunkit/instruments";
import type { ReactElement } from "react";
export const description: string = "A speed of 6.4 knots on a scale that ends at 12.";
export default function Speed(): ReactElement {
return (
<div style={{ width: 200, height: 200 }}>
<SpeedGauge speed={6.4} maxSpeed={12} />
</div>
);
}
Small face
Code
import { SpeedGauge } from "@bosunkit/instruments";
import type { ReactElement } from "react";
export const description: string =
"A speed gauge on a face pinned to 180 pixels, which sizes itself and needs no surrounding box.";
export default function SmallFace(): ReactElement {
return <SpeedGauge speed={6.4} maxSpeed={12} faceDiameter={180} />;
}
Speed basis and scale
Set the label to the quantity being supplied: speed through water and speed over ground can differ materially. The component does not convert a sensor's units when the unit label changes. Convert the value, limits, advice and setpoint together in the application.
Keep the scale stable for comparisons and include astern values only when the source defines signed speed. The setpoint represents a target, not measured performance. Pair the dial with source and integrity information; a default or fallback value must not make a disconnected source look stationary.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| speed | number | undefined | 0 | Current speed, in the unit of minSpeed and maxSpeed (knots with the default KN unit). Clamped to the range.
Default 0. |
| maxSpeed | number | undefined | 100 | Speed at the end of the scale, in the same unit as speed. A value that is not a positive number falls back to
100. |
| minSpeed | number | undefined | 0 | Speed at the start of the scale, in the same unit as speed. A negative value extends the scale below zero.
Default 0. |
| showLabels | boolean | undefined | false | Show numeric labels at primary tickmarks. |
| tickmarksInside | boolean | undefined | false | Whether to render tickmarks inside the ring. |
| tickmarkInterval | number | undefined | 20 | Interval for tickmarks in speed units. When undefined or <= 0, no tickmarks are shown (only the zero mark). |
| priority | Priority | undefined | Priority.regular | Color priority: regular (gray palette, default) or enhanced (blue palette) for the needle, the arc and the
setpoint marker. |
| needleType | ObcSpeedGaugeNeedleType | undefined | ObcSpeedGaugeNeedleType.full | Needle type: full (pointer with center dot) or bar (short indicator). |
| speedAdvices | SpeedAdvice[] | undefined | [] | Caution/alert arcs; triggered state derives from the current speed. |
| tickmarkStyle | TickmarkStyle | undefined | TickmarkStyle.regular | Tickmark color style. regular (default) draws every tick in the dim tertiary color; enhanced draws ticks in the
brighter primary color and tertiary ticks in the secondary color. |
| hasReadout | boolean | undefined | false | When true, shows a centered readout (label STW, unit KN) below the
gauge with the current speed. Default false. |
| label | string | undefined | "STW" | Readout label. Default STW. |
| unit | string | undefined | "KN" | Readout unit. Default KN. |
| fractionDigits | number | undefined | 1 | Number of fraction digits shown in the readout. Default 1. |
| faceDiameter | number | undefined | – | Outer-ring diameter in CSS pixels. When set, the instrument renders at a fixed intrinsic size derived from the ring, arc shape and label reserve — so instruments sharing the same value have identical ring circumference regardless of label width or arc extent. When unset (default), the instrument fills its container. |
| className | string | undefined | – | Class names added to the instrument's root element. |
| setpoint | number | undefined | – | Target setpoint value. |
| newSetpoint | number | undefined | – | Adjustment preview (2-step interface): while defined, the original setpoint marker dims and a focus-state marker renders at this value. |
| atSetpoint | boolean | undefined | false | Manual at-setpoint override; used when autoAtSetpoint is false. |
| touching | boolean | undefined | false | User is physically interacting with the control. Forces focus rendering and suppresses at-setpoint detection while true. |
| autoAtSetpoint | boolean | undefined | true | Enable automatic at-setpoint detection (default true). |
| autoAtSetpointDeadband | number | undefined | 2 | Tolerance for auto at-setpoint detection (default 2). |
| setpointAtZeroDeadband | number | undefined | 0.5 | Zero-snap tolerance for the marker's equalZero state (default 0.5). |
| setpointOverride | boolean | undefined | false | Derive the setpoint color from priority even when loading/off. |
| animateSetpoint | boolean | undefined | false | Enable the CSS-animated confirm transition. |
Related
- Speed arrows: the speed as chevrons.
- Gauge radial: the general radial gauge for other values.
- Data integrity: the states a value can be in, and what the crew does.