UNPKG

@patricksurry/g3

Version:

A flexible Javascript framework for building steam gauge instrument panels that display live external metrics from flight (or other) simulators like XPlane or MS FS2020

72 lines (71 loc) • 3.88 kB
import type { GaugeComponent, SelectorOrSelection } from '../types'; /** * The DOM element of the gauge being drawn into sel. * Child renderers may be called with a d3 enter placeholder rather than a real node, * so we find the enclosing gauge element via a temporary marker. */ export declare function gaugeNode(sel: SelectorOrSelection, cls?: string): Element; /** * Two-position linear on/off toggle switch; clicking sets the metric to the opposite of its reported value. * @param metric - Metric name to indicate and set (default 'status') * @param label - Text label displayed above the switch (defaults to `metric`) */ export declare function toggleFactory(metric?: string, label?: string): GaugeComponent; export interface ButtonOptions { /** Cap shape (default `'round'`). */ shape?: 'round' | 'rect'; /** Cap width and height for `'rect'` buttons (default 84 x 54). */ width?: number; height?: number; /** * What a press sends (default `'momentary'`): * `'momentary'` sets the metric to 1 while pressed and 0 on release, * `'latch'` sets it to the opposite of its reported value on each click, * and `'trigger'` sends a single `trigger` action for `event` on each press. */ mode?: 'momentary' | 'latch' | 'trigger'; /** Event name for `'trigger'` mode (defaults to `metric`). */ event?: string; /** Called on each press instead of sending any action, e.g. to update local UI state. */ onPress?: (e: Event, g: GaugeComponent) => void; } /** * Push-button (round or rectangular) that looks pressed while held, or while a latched metric is 1. * @param metric - Metric name to set (default 'button'; may be omitted for `trigger` or `onPress` buttons) * @param label - Text label displayed above a round button or on the cap of a rectangular button (defaults to `metric`) * @param opts - Optional `shape`, `width`, `height`, `mode`, `event` and `onPress` */ export declare function buttonFactory(metric?: string, label?: string, opts?: ButtonOptions): GaugeComponent; export interface RotaryOptions { /** Change per click or wheel notch (default 1). */ step?: number; /** Limits passed to the hub as `adjust` hints, e.g. `{min: 0, max: 360, wrap: true}` for a heading bug. */ min?: number; max?: number; wrap?: boolean; /** Number of steps per full turn of the knob (default 12). */ detents?: number; } /** * Rotary encoder knob that sends `adjust` actions (click left/right half, or scroll wheel) * and turns to show the reported value of the metric it adjusts. * @param metric - Metric name to adjust and indicate (default 'rotary') * @param label - Text label displayed above the knob (defaults to `metric`) * @param opts - Optional `step`, `min`, `max`, `wrap` and `detents` */ export declare function rotaryFactory(metric?: string, label?: string, opts?: RotaryOptions): GaugeComponent; export interface SelectorOptions { /** Angles of the first and last positions (default `[-60, 60]`). */ range?: [number, number]; /** Whether stepping past the last position wraps to the first, and vice versa (default `false`). */ wrap?: boolean; } /** * Multi-position detented rotary selector switch, e.g. a magneto or mode selector. * Positions are evenly spaced; clicking (left/right half) or scrolling sets the next position, stopping at the ends. * @param metric - Metric name to indicate and set (default 'selector') * @param label - Text label displayed below the switch (defaults to `metric`) * @param positions - Position labels, whose values are their indices, or a map of value to label (default `['OFF', 'ON']`) * @param opts - Optional angular `range` and `wrap` */ export declare function selectorFactory(metric?: string, label?: string, positions?: string[] | Record<number, string>, opts?: SelectorOptions): GaugeComponent;