@oicl/openbridge-webcomponents-full-bundle 2.2.0-next.24 → 2.2.0-next.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/bundle/openbridge-webcomponents.bundle.js +528 -198
  2. package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
  3. package/custom-elements.json +271 -0
  4. package/dist/navigation-instruments/attitude/attitude.css_inline.js +64 -0
  5. package/dist/navigation-instruments/attitude/attitude.css_inline.js.map +1 -0
  6. package/dist/navigation-instruments/attitude/attitude.d.ts +121 -0
  7. package/dist/navigation-instruments/attitude/attitude.d.ts.map +1 -0
  8. package/dist/navigation-instruments/attitude/attitude.js +255 -0
  9. package/dist/navigation-instruments/attitude/attitude.js.map +1 -0
  10. package/dist/navigation-instruments/watch/tickmark.d.ts.map +1 -1
  11. package/dist/navigation-instruments/watch/tickmark.js +35 -13
  12. package/dist/navigation-instruments/watch/tickmark.js.map +1 -1
  13. package/dist/svghelpers/math.d.ts +7 -0
  14. package/dist/svghelpers/math.d.ts.map +1 -1
  15. package/dist/svghelpers/math.js +10 -1
  16. package/dist/svghelpers/math.js.map +1 -1
  17. package/llms/components/obc-attitude.md +69 -0
  18. package/llms/llms-full.txt +72 -0
  19. package/llms/llms.txt +1 -0
  20. package/package.json +1 -1
  21. package/src/navigation-instruments/attitude/attitude.css +54 -0
  22. package/src/navigation-instruments/attitude/attitude.spec.ts +208 -0
  23. package/src/navigation-instruments/attitude/attitude.stories.ts +87 -0
  24. package/src/navigation-instruments/attitude/attitude.ts +351 -0
  25. package/src/navigation-instruments/watch/tickmark.spec.ts +22 -0
  26. package/src/navigation-instruments/watch/tickmark.ts +49 -5
  27. package/src/svghelpers/math.spec.ts +25 -0
  28. package/src/svghelpers/math.ts +10 -0
@@ -0,0 +1,255 @@
1
+ import attitude_default from "./attitude.css_inline.js";
2
+ import { WatchCircleType } from "../watch/watch.js";
3
+ import { TickmarkType } from "../watch/tickmark.js";
4
+ import { HdgArrowStyle, hdgArrow } from "../course-arrows/course-arrows.js";
5
+ import { customElement } from "../../decorator.js";
6
+ import { Priority } from "../types.js";
7
+ import { clamp, normalizeSignedAngle } from "../../svghelpers/math.js";
8
+ import { applyPinnedHostSize, computeRadialFrame, estimateLabelWidthPx, measureContainerPx, observeInnerBox } from "../../svghelpers/radial-frame.js";
9
+ import __decorate from "../../_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/decorate.js";
10
+ import { LitElement, html, svg, unsafeCSS } from "lit";
11
+ import { property } from "lit/decorators.js";
12
+ import { ResizeController } from "@lit-labs/observers/resize-controller.js";
13
+ // src/navigation-instruments/attitude/attitude.ts
14
+ /** Radius of the face, which is the watch's outer ring. */
15
+ var FACE_RADIUS = 184;
16
+ /** Distance between two ladder rungs; one rung is `pitchTickInterval` degrees. */
17
+ var RUNG_SPACING = 64;
18
+ var RUNG_HALF_WIDTH = 12;
19
+ /**
20
+ * Range of `pitchTickInterval` that is drawn. The upper end keeps the ground
21
+ * band at least two rungs tall, so the face never holds more than a few bands.
22
+ * The lower end keeps ladder distances small enough to count rungs exactly.
23
+ */
24
+ var MIN_PITCH_TICK_INTERVAL = .1;
25
+ var MAX_PITCH_TICK_INTERVAL = 90;
26
+ /** Stands in for a `pitchTickInterval` that is not a positive number. */
27
+ var DEFAULT_PITCH_TICK_INTERVAL = 10;
28
+ /**
29
+ * Marks of the roll scale, which turns with the horizon under the fixed
30
+ * pointer. The pointer sits on the side of the zero mark the vehicle rolls to.
31
+ *
32
+ * TODO(designer): Figma 20108:142406 labels this arc 270/315/0/45/90, the
33
+ * generic watch-face preset. Confirm the roll labels.
34
+ */
35
+ var ROLL_SCALE_MARKS = [
36
+ {
37
+ angle: 270,
38
+ type: TickmarkType.textOnly,
39
+ text: "90"
40
+ },
41
+ {
42
+ angle: 315,
43
+ type: TickmarkType.primary,
44
+ text: "45"
45
+ },
46
+ {
47
+ angle: 0,
48
+ type: TickmarkType.main,
49
+ text: "0"
50
+ },
51
+ {
52
+ angle: 45,
53
+ type: TickmarkType.primary,
54
+ text: "45"
55
+ },
56
+ {
57
+ angle: 90,
58
+ type: TickmarkType.textOnly,
59
+ text: "90"
60
+ }
61
+ ];
62
+ /** The fixed symbol, a 240 × 28 box whose bar is centred on its row 4 (Figma 35754:89010). */
63
+ var VESSEL_SYMBOL_PATH = "M100 0C102.209 0 104 1.791 104 4C104 8.243 105.686 12.313 108.687 15.313C111.687 18.314 115.757 20 120 20C124.243 20 128.313 18.314 131.313 15.313C134.314 12.313 136 8.243 136 4C136 1.791 137.791 0 140 0L236 0C238.209 0 240 1.791 240 4C240 6.209 238.209 8 236 8L143.663 8C142.838 12.881 140.517 17.424 136.971 20.971C132.47 25.472 126.365 28 120 28C113.635 28 107.53 25.472 103.029 20.971C99.483 17.424 97.162 12.881 96.337 8L4 8C1.791 8 0 6.209 0 4C0 1.791 1.791 0 4 0L100 0Z";
64
+ function isNumber(value) {
65
+ return typeof value === "number" && Number.isFinite(value);
66
+ }
67
+ var ObcAttitude = class ObcAttitude extends LitElement {
68
+ constructor(..._args) {
69
+ super(..._args);
70
+ this.pitch = 0;
71
+ this.roll = 0;
72
+ this.pitchTickInterval = 10;
73
+ this.showLabels = true;
74
+ this.priority = Priority.regular;
75
+ this._idPrefix = `attitude-${Math.random().toString(36).slice(2, 9)}`;
76
+ this._hostSizePinned = false;
77
+ this._resizeController = new ResizeController(this, {});
78
+ }
79
+ firstUpdated(changed) {
80
+ super.firstUpdated(changed);
81
+ observeInnerBox(this._resizeController, this.renderRoot);
82
+ }
83
+ updated(changed) {
84
+ super.updated(changed);
85
+ this._hostSizePinned = applyPinnedHostSize(this, this._frame, this._hostSizePinned);
86
+ }
87
+ get safeRoll() {
88
+ return isNumber(this.roll) ? this.roll : 0;
89
+ }
90
+ /** Pitch within half a turn either way, so a full turn draws like none. */
91
+ get wrappedPitch() {
92
+ return isNumber(this.pitch) ? normalizeSignedAngle(this.pitch) : 0;
93
+ }
94
+ /**
95
+ * Ladder distance for a pitch angle, in SVG units.
96
+ *
97
+ * TODO(designer): Figma 20108:141712 spaces the rungs 64 apart and gives
98
+ * them no value. The default reads one rung as 10°.
99
+ */
100
+ ladderUnits(degrees) {
101
+ const interval = isNumber(this.pitchTickInterval) && this.pitchTickInterval > 0 ? clamp(this.pitchTickInterval, MIN_PITCH_TICK_INTERVAL, MAX_PITCH_TICK_INTERVAL) : DEFAULT_PITCH_TICK_INTERVAL;
102
+ return degrees * RUNG_SPACING / interval;
103
+ }
104
+ /**
105
+ * Turn of the roll scale, in degrees clockwise. Its zero mark points at the
106
+ * sky, so it turns with the horizon and swaps sides once the pitch passes
107
+ * vertical, where the vehicle is upside down and the sky is below.
108
+ */
109
+ get rollScaleRotation() {
110
+ const upsideDown = Math.abs(this.wrappedPitch) > 90;
111
+ return -this.safeRoll + (upsideDown ? 180 : 0);
112
+ }
113
+ /** Moves the horizon from ladder coordinates onto the face: slid by the pitch, tilted against the roll. */
114
+ get horizonTransform() {
115
+ return `rotate(${-this.safeRoll}) translate(0 ${this.ladderUnits(this.wrappedPitch)})`;
116
+ }
117
+ /**
118
+ * The ground, the horizon lines and the ladder, in ladder coordinates:
119
+ * `y = 0` is the horizon and one rung is `RUNG_SPACING` up or down.
120
+ *
121
+ * The ladder repeats every full turn of pitch. Half a turn from each
122
+ * horizon lies the inverted one, with the ground above it. Only the part
123
+ * the face can show is drawn.
124
+ */
125
+ renderHorizon() {
126
+ const halfTurn = this.ladderUnits(180);
127
+ const turn = 2 * halfTurn;
128
+ const centre = -this.ladderUnits(this.wrappedPitch);
129
+ const top = centre - FACE_RADIUS;
130
+ const bottom = centre + FACE_RADIUS;
131
+ const ground = [];
132
+ for (let n = Math.ceil(top / turn - .5); n * turn <= bottom; n++) {
133
+ const y = Math.max(n * turn, top);
134
+ const height = Math.min(n * turn + halfTurn, bottom) - y;
135
+ if (height > 0) ground.push(svg`<rect class="ground" x=${-FACE_RADIUS} y=${y} width=${FACE_RADIUS * 2} height=${height} />`);
136
+ }
137
+ const horizons = [];
138
+ for (let m = Math.ceil(top / halfTurn); m * halfTurn <= bottom; m++) {
139
+ const y = m * halfTurn;
140
+ horizons.push(svg`<line class="horizon-line" x1=${-FACE_RADIUS} x2=${FACE_RADIUS} y1=${y} y2=${y} />`);
141
+ }
142
+ const rungs = [];
143
+ for (let n = Math.floor((top + halfTurn) / turn); n * turn - halfTurn <= bottom; n++) {
144
+ const origin = n * turn;
145
+ const first = Math.max(top, origin - halfTurn) - origin;
146
+ const last = Math.min(bottom, origin + halfTurn) - origin;
147
+ for (let j = Math.ceil(first / RUNG_SPACING); j * RUNG_SPACING <= last; j++) {
148
+ const offset = j * RUNG_SPACING;
149
+ if (j === 0 || halfTurn - Math.abs(offset) < .5) continue;
150
+ const y = origin + offset;
151
+ rungs.push(svg`<line class="rung" x1=${-12} x2=${RUNG_HALF_WIDTH} y1=${y} y2=${y} vector-effect="non-scaling-stroke" />`);
152
+ }
153
+ }
154
+ return svg`
155
+ <g class="horizon" transform=${this.horizonTransform}>
156
+ ${ground} ${rungs} ${horizons}
157
+ </g>
158
+ `;
159
+ }
160
+ /**
161
+ * The part of the face edge the roll scale band does not already draw. It
162
+ * turns with the band so the two keep meeting at the band's ends.
163
+ */
164
+ renderFaceOutline() {
165
+ const r = FACE_RADIUS;
166
+ return svg`<path class="face-outline" transform="rotate(${this.rollScaleRotation})" d="M ${-r} 0 A ${r} ${r} 0 0 0 ${r} 0" vector-effect="non-scaling-stroke" />`;
167
+ }
168
+ renderVesselSymbol() {
169
+ return svg`
170
+ <g class="vessel-symbol">
171
+ <path transform="translate(-120 -4)" d=${VESSEL_SYMBOL_PATH} />
172
+ <circle r="4" />
173
+ </g>
174
+ `;
175
+ }
176
+ /**
177
+ * The roll pointer. It is fixed to the vehicle like the symbol, so it stays
178
+ * straight up and the roll scale turns under it.
179
+ *
180
+ * TODO(designer): Figma 20108:142406 wraps this arrow in a rotator tool and
181
+ * keeps the scale still. The review chose the fixed pointer.
182
+ */
183
+ renderRollPointer() {
184
+ return svg`
185
+ <g class="roll-pointer">
186
+ ${hdgArrow(HdgArrowStyle.arrowHead, 0, this.priority)}
187
+ </g>
188
+ `;
189
+ }
190
+ render() {
191
+ const frame = computeRadialFrame({
192
+ basePadding: 24,
193
+ labelWidthPx: this.showLabels ? estimateLabelWidthPx(ROLL_SCALE_MARKS.map((mark) => mark.text)) : 0,
194
+ containerPx: measureContainerPx(this),
195
+ faceDiameter: this.faceDiameter
196
+ });
197
+ this._frame = frame;
198
+ const areas = [{
199
+ startAngle: -90,
200
+ endAngle: 90,
201
+ roundOutsideCut: true,
202
+ roundInsideCut: true
203
+ }];
204
+ const showLabels = this.showLabels && !frame.labelsHidden;
205
+ const tickmarks = ROLL_SCALE_MARKS.filter((mark) => showLabels || mark.type !== TickmarkType.textOnly).map((mark) => ({
206
+ ...mark,
207
+ text: showLabels ? mark.text : void 0
208
+ }));
209
+ const faceClip = `${this._idPrefix}-face`;
210
+ const enhanced = this.priority === Priority.enhanced;
211
+ return html`
212
+ <div class="container ${enhanced ? "enhanced" : ""}">
213
+ <svg viewBox=${frame.viewBox}>
214
+ <defs>
215
+ <clipPath id=${faceClip}>
216
+ <circle r=${FACE_RADIUS} />
217
+ </clipPath>
218
+ </defs>
219
+ <g clip-path="url(#${faceClip})">${this.renderHorizon()}</g>
220
+ ${this.renderFaceOutline()}
221
+ </svg>
222
+ <obc-watch
223
+ .arcFrame=${frame}
224
+ .rotation=${this.rollScaleRotation}
225
+ .watchCircleType=${WatchCircleType.single}
226
+ .areas=${areas}
227
+ .tickmarks=${tickmarks}
228
+ .priority=${this.priority}
229
+ ></obc-watch>
230
+ <svg viewBox=${frame.viewBox}>
231
+ ${this.renderVesselSymbol()} ${this.renderRollPointer()}
232
+ </svg>
233
+ </div>
234
+ `;
235
+ }
236
+ static {
237
+ this.styles = unsafeCSS(attitude_default);
238
+ }
239
+ };
240
+ __decorate([property({ type: Number })], ObcAttitude.prototype, "pitch", void 0);
241
+ __decorate([property({ type: Number })], ObcAttitude.prototype, "roll", void 0);
242
+ __decorate([property({ type: Number })], ObcAttitude.prototype, "pitchTickInterval", void 0);
243
+ __decorate([property({
244
+ type: Boolean,
245
+ attribute: false
246
+ })], ObcAttitude.prototype, "showLabels", void 0);
247
+ __decorate([property({ type: String })], ObcAttitude.prototype, "priority", void 0);
248
+ __decorate([property({
249
+ type: Number,
250
+ attribute: "face-diameter"
251
+ })], ObcAttitude.prototype, "faceDiameter", void 0);
252
+ ObcAttitude = __decorate([customElement("obc-attitude")], ObcAttitude);
253
+ export { ObcAttitude };
254
+
255
+ //# sourceMappingURL=attitude.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attitude.js","names":["componentStyle","_decorate"],"sources":["../../../src/navigation-instruments/attitude/attitude.ts"],"sourcesContent":["import {\n LitElement,\n PropertyValues,\n html,\n svg,\n unsafeCSS,\n type SVGTemplateResult,\n} from 'lit';\nimport {property} from 'lit/decorators.js';\nimport {ResizeController} from '@lit-labs/observers/resize-controller.js';\nimport componentStyle from './attitude.css?inline';\nimport '../watch/watch.js';\nimport {\n OUTER_RING_RADIUS,\n WatchCircleType,\n type WatchArea,\n} from '../watch/watch.js';\nimport {Tickmark, TickmarkType} from '../watch/tickmark.js';\nimport {HdgArrowStyle, hdgArrow} from '../course-arrows/course-arrows.js';\nimport {customElement} from '../../decorator.js';\nimport {Priority} from '../types.js';\nimport {clamp, normalizeSignedAngle} from '../../svghelpers/math.js';\nimport {\n applyPinnedHostSize,\n computeRadialFrame,\n estimateLabelWidthPx,\n measureContainerPx,\n observeInnerBox,\n type RadialFrame,\n} from '../../svghelpers/radial-frame.js';\n\n/** Radius of the face, which is the watch's outer ring. */\nconst FACE_RADIUS = OUTER_RING_RADIUS;\n/** Distance between two ladder rungs; one rung is `pitchTickInterval` degrees. */\nconst RUNG_SPACING = 64;\nconst RUNG_HALF_WIDTH = 12;\n/**\n * Range of `pitchTickInterval` that is drawn. The upper end keeps the ground\n * band at least two rungs tall, so the face never holds more than a few bands.\n * The lower end keeps ladder distances small enough to count rungs exactly.\n */\nconst MIN_PITCH_TICK_INTERVAL = 0.1;\nconst MAX_PITCH_TICK_INTERVAL = 90;\n/** Stands in for a `pitchTickInterval` that is not a positive number. */\nconst DEFAULT_PITCH_TICK_INTERVAL = 10;\n\n/**\n * Marks of the roll scale, which turns with the horizon under the fixed\n * pointer. The pointer sits on the side of the zero mark the vehicle rolls to.\n *\n * TODO(designer): Figma 20108:142406 labels this arc 270/315/0/45/90, the\n * generic watch-face preset. Confirm the roll labels.\n */\nconst ROLL_SCALE_MARKS: readonly Tickmark[] = [\n {angle: 270, type: TickmarkType.textOnly, text: '90'},\n {angle: 315, type: TickmarkType.primary, text: '45'},\n {angle: 0, type: TickmarkType.main, text: '0'},\n {angle: 45, type: TickmarkType.primary, text: '45'},\n {angle: 90, type: TickmarkType.textOnly, text: '90'},\n];\n\n/** The fixed symbol, a 240 × 28 box whose bar is centred on its row 4 (Figma 35754:89010). */\nconst VESSEL_SYMBOL_PATH =\n 'M100 0C102.209 0 104 1.791 104 4C104 8.243 105.686 12.313 108.687 15.313C111.687 18.314 115.757 20 120 20C124.243 20 128.313 18.314 131.313 15.313C134.314 12.313 136 8.243 136 4C136 1.791 137.791 0 140 0L236 0C238.209 0 240 1.791 240 4C240 6.209 238.209 8 236 8L143.663 8C142.838 12.881 140.517 17.424 136.971 20.971C132.47 25.472 126.365 28 120 28C113.635 28 107.53 25.472 103.029 20.971C99.483 17.424 97.162 12.881 96.337 8L4 8C1.791 8 0 6.209 0 4C0 1.791 1.791 0 4 0L100 0Z';\n\nfunction isNumber(value: number | undefined | null): value is number {\n return typeof value === 'number' && Number.isFinite(value);\n}\n\n/**\n * `<obc-attitude>` – Attitude instrument that shows pitch and roll as a moving\n * horizon behind a fixed vessel symbol, the way an artificial horizon does.\n *\n * The symbol in the centre stays level. The ground half of the face slides\n * down as the pitch rises and tilts against the roll, so the picture matches\n * what is seen looking forward. A ladder of short rungs on the horizon gives\n * the pitch. The roll scale turns with the horizon, and the pointer at the\n * top, which stays straight up like the symbol, reads the roll on it.\n *\n * ## Features / Variants\n *\n * - **Roll scale:** the band over the sky half of the face, labelled\n * 90/45/0/45/90. It turns with the horizon, so the fixed pointer sits on\n * the side the vehicle rolls to. `showLabels` turns the labels off.\n * - **Full turns:** `pitch` and `roll` take any angle. Past ±90° of pitch the\n * ladder runs on to the inverted horizon, with the ground above the sky,\n * and the roll scale follows the sky to the lower half.\n * - **Pitch ladder:** one rung per `pitchTickInterval` degrees. A smaller\n * interval magnifies the pitch; a larger one shows more of it.\n * - **Priority:** `priority` switches the symbol and the pointer between the\n * `regular` and `enhanced` palette.\n *\n * ## Usage Guidelines\n *\n * Use for a vehicle that is steered in three dimensions and whose operator\n * needs pitch and roll together at a glance. For readings against a scale\n * with advice zones use `obc-pitch`, `obc-roll` or `obc-pitch-roll`; for\n * pitch, roll and yaw deviation as a dot on a polar grid use\n * `obc-pitch-roll-yaw`.\n *\n * The scales carry no numbers besides the roll labels. Put the values next to\n * the instrument with `obc-readout` when they have to be read exactly.\n *\n * **TODO(designer)**: Figma 20108:142407 shows no pitch values on the ladder.\n *\n * @property pitch - Pitch in degrees, positive with the front up. The horizon drops below the\n * symbol as it rises. Any angle is accepted and wraps over a full turn.\n * @property roll - Roll in degrees, positive with the right side down. The horizon and the\n * roll scale turn the other way, as they appear from on board. Any angle is accepted.\n * @property pitchTickInterval - Degrees of pitch between two ladder rungs, from 0.1 to 90. Default\n * `10`, which shows about ±29° on the face.\n * @property showLabels - When `true` (default), labels the roll scale.\n * @property priority - Palette of the symbol and the pointer: `regular` or `enhanced`.\n * @property faceDiameter - Outer-ring diameter in CSS pixels. When set, the instrument renders at a\n * fixed size, so instruments that share the value have rings of the same size.\n * @experimental\n */\n@customElement('obc-attitude')\nexport class ObcAttitude extends LitElement {\n @property({type: Number}) pitch = 0;\n @property({type: Number}) roll = 0;\n @property({type: Number}) pitchTickInterval = 10;\n @property({type: Boolean, attribute: false}) showLabels = true;\n @property({type: String}) priority: Priority = Priority.regular;\n @property({type: Number, attribute: 'face-diameter'})\n faceDiameter: number | undefined;\n\n /** Clip ids are looked up in the whole document, so each instance needs its own. */\n private _idPrefix = `attitude-${Math.random().toString(36).slice(2, 9)}`;\n private _frame: RadialFrame | undefined;\n private _hostSizePinned = false;\n private _resizeController = new ResizeController(this, {});\n\n override firstUpdated(changed: PropertyValues): void {\n super.firstUpdated(changed);\n observeInnerBox(this._resizeController, this.renderRoot);\n }\n\n override updated(changed: PropertyValues): void {\n super.updated(changed);\n this._hostSizePinned = applyPinnedHostSize(\n this,\n this._frame,\n this._hostSizePinned\n );\n }\n\n private get safeRoll(): number {\n return isNumber(this.roll) ? this.roll : 0;\n }\n\n /** Pitch within half a turn either way, so a full turn draws like none. */\n private get wrappedPitch(): number {\n return isNumber(this.pitch) ? normalizeSignedAngle(this.pitch) : 0;\n }\n\n /**\n * Ladder distance for a pitch angle, in SVG units.\n *\n * TODO(designer): Figma 20108:141712 spaces the rungs 64 apart and gives\n * them no value. The default reads one rung as 10°.\n */\n private ladderUnits(degrees: number): number {\n const interval =\n isNumber(this.pitchTickInterval) && this.pitchTickInterval > 0\n ? clamp(\n this.pitchTickInterval,\n MIN_PITCH_TICK_INTERVAL,\n MAX_PITCH_TICK_INTERVAL\n )\n : DEFAULT_PITCH_TICK_INTERVAL;\n return (degrees * RUNG_SPACING) / interval;\n }\n\n /**\n * Turn of the roll scale, in degrees clockwise. Its zero mark points at the\n * sky, so it turns with the horizon and swaps sides once the pitch passes\n * vertical, where the vehicle is upside down and the sky is below.\n */\n private get rollScaleRotation(): number {\n const upsideDown = Math.abs(this.wrappedPitch) > 90;\n return -this.safeRoll + (upsideDown ? 180 : 0);\n }\n\n /** Moves the horizon from ladder coordinates onto the face: slid by the pitch, tilted against the roll. */\n private get horizonTransform(): string {\n return `rotate(${-this.safeRoll}) translate(0 ${this.ladderUnits(this.wrappedPitch)})`;\n }\n\n /**\n * The ground, the horizon lines and the ladder, in ladder coordinates:\n * `y = 0` is the horizon and one rung is `RUNG_SPACING` up or down.\n *\n * The ladder repeats every full turn of pitch. Half a turn from each\n * horizon lies the inverted one, with the ground above it. Only the part\n * the face can show is drawn.\n */\n private renderHorizon(): SVGTemplateResult {\n const halfTurn = this.ladderUnits(180);\n const turn = 2 * halfTurn;\n const centre = -this.ladderUnits(this.wrappedPitch);\n const top = centre - FACE_RADIUS;\n const bottom = centre + FACE_RADIUS;\n\n const ground: SVGTemplateResult[] = [];\n for (let n = Math.ceil(top / turn - 0.5); n * turn <= bottom; n++) {\n const y = Math.max(n * turn, top);\n const height = Math.min(n * turn + halfTurn, bottom) - y;\n if (height > 0) {\n ground.push(\n svg`<rect class=\"ground\" x=${-FACE_RADIUS} y=${y} width=${FACE_RADIUS * 2} height=${height} />`\n );\n }\n }\n\n const horizons: SVGTemplateResult[] = [];\n for (let m = Math.ceil(top / halfTurn); m * halfTurn <= bottom; m++) {\n const y = m * halfTurn;\n horizons.push(\n svg`<line class=\"horizon-line\" x1=${-FACE_RADIUS} x2=${FACE_RADIUS} y1=${y} y2=${y} />`\n );\n }\n\n // Rungs count out from each upright horizon and stop short of the inverted\n // one, so the ladder repeats with the ground whatever the interval.\n const rungs: SVGTemplateResult[] = [];\n for (\n let n = Math.floor((top + halfTurn) / turn);\n n * turn - halfTurn <= bottom;\n n++\n ) {\n const origin = n * turn;\n const first = Math.max(top, origin - halfTurn) - origin;\n const last = Math.min(bottom, origin + halfTurn) - origin;\n for (\n let j = Math.ceil(first / RUNG_SPACING);\n j * RUNG_SPACING <= last;\n j++\n ) {\n const offset = j * RUNG_SPACING;\n if (j === 0 || halfTurn - Math.abs(offset) < 0.5) {\n continue;\n }\n const y = origin + offset;\n rungs.push(\n svg`<line class=\"rung\" x1=${-RUNG_HALF_WIDTH} x2=${RUNG_HALF_WIDTH} y1=${y} y2=${y} vector-effect=\"non-scaling-stroke\" />`\n );\n }\n }\n\n return svg`\n <g class=\"horizon\" transform=${this.horizonTransform}>\n ${ground} ${rungs} ${horizons}\n </g>\n `;\n }\n\n /**\n * The part of the face edge the roll scale band does not already draw. It\n * turns with the band so the two keep meeting at the band's ends.\n */\n private renderFaceOutline(): SVGTemplateResult {\n const r = FACE_RADIUS;\n return svg`<path class=\"face-outline\" transform=\"rotate(${this.rollScaleRotation})\" d=\"M ${-r} 0 A ${r} ${r} 0 0 0 ${r} 0\" vector-effect=\"non-scaling-stroke\" />`;\n }\n\n private renderVesselSymbol(): SVGTemplateResult {\n return svg`\n <g class=\"vessel-symbol\">\n <path transform=\"translate(-120 -4)\" d=${VESSEL_SYMBOL_PATH} />\n <circle r=\"4\" />\n </g>\n `;\n }\n\n /**\n * The roll pointer. It is fixed to the vehicle like the symbol, so it stays\n * straight up and the roll scale turns under it.\n *\n * TODO(designer): Figma 20108:142406 wraps this arrow in a rotator tool and\n * keeps the scale still. The review chose the fixed pointer.\n */\n private renderRollPointer(): SVGTemplateResult {\n return svg`\n <g class=\"roll-pointer\">\n ${hdgArrow(HdgArrowStyle.arrowHead, 0, this.priority)}\n </g>\n `;\n }\n\n override render() {\n const frame = computeRadialFrame({\n basePadding: 24,\n labelWidthPx: this.showLabels\n ? estimateLabelWidthPx(ROLL_SCALE_MARKS.map((mark) => mark.text))\n : 0,\n containerPx: measureContainerPx(this),\n faceDiameter: this.faceDiameter,\n });\n this._frame = frame;\n\n const areas: WatchArea[] = [\n {\n startAngle: -90,\n endAngle: 90,\n roundOutsideCut: true,\n roundInsideCut: true,\n },\n ];\n const showLabels = this.showLabels && !frame.labelsHidden;\n const tickmarks: Tickmark[] = ROLL_SCALE_MARKS.filter(\n (mark) => showLabels || mark.type !== TickmarkType.textOnly\n ).map((mark) => ({...mark, text: showLabels ? mark.text : undefined}));\n\n const faceClip = `${this._idPrefix}-face`;\n const enhanced = this.priority === Priority.enhanced;\n\n return html`\n <div class=\"container ${enhanced ? 'enhanced' : ''}\">\n <svg viewBox=${frame.viewBox}>\n <defs>\n <clipPath id=${faceClip}>\n <circle r=${FACE_RADIUS} />\n </clipPath>\n </defs>\n <g clip-path=\"url(#${faceClip})\">${this.renderHorizon()}</g>\n ${this.renderFaceOutline()}\n </svg>\n <obc-watch\n .arcFrame=${frame}\n .rotation=${this.rollScaleRotation}\n .watchCircleType=${WatchCircleType.single}\n .areas=${areas}\n .tickmarks=${tickmarks}\n .priority=${this.priority}\n ></obc-watch>\n <svg viewBox=${frame.viewBox}>\n ${this.renderVesselSymbol()} ${this.renderRollPointer()}\n </svg>\n </div>\n `;\n }\n\n static override styles = unsafeCSS(componentStyle);\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'obc-attitude': ObcAttitude;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAgCA,IAAM,cAAA;;AAEN,IAAM,eAAe;AACrB,IAAM,kBAAkB;;;;;;AAMxB,IAAM,0BAA0B;AAChC,IAAM,0BAA0B;;AAEhC,IAAM,8BAA8B;;;;;;;;AASpC,IAAM,mBAAwC;CAC5C;EAAC,OAAO;EAAK,MAAM,aAAa;EAAU,MAAM;CAAI;CACpD;EAAC,OAAO;EAAK,MAAM,aAAa;EAAS,MAAM;CAAI;CACnD;EAAC,OAAO;EAAG,MAAM,aAAa;EAAM,MAAM;CAAG;CAC7C;EAAC,OAAO;EAAI,MAAM,aAAa;EAAS,MAAM;CAAI;CAClD;EAAC,OAAO;EAAI,MAAM,aAAa;EAAU,MAAM;CAAI;AACrD;;AAGA,IAAM,qBACJ;AAEF,SAAS,SAAS,OAAmD;CACnE,OAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK;AAC3D;AAmDO,IAAM,cAAN,MAAM,oBAAoB,WAAW;;;EACR,KAAA,QAAA;EACD,KAAA,OAAA;EACa,KAAA,oBAAA;EACY,KAAA,aAAA;EACX,KAAA,WAAA,SAAS;EAKpC,KAAA,YAAA,YAAY,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC;EAE3C,KAAA,kBAAA;EACE,KAAA,oBAAA,IAAI,iBAA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AC;CAC3B,GACA,iBAAiB,GAAG,iBAAiB,EAAE,CAoGzC;AAmFD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACpC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,6DAA6D;IAC7D,UAAU,EAAE,OAAO,CAAC;IACpB,qFAAqF;IACrF,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,+FAA+F;IAC/F,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,2EAA2E;IAC3E,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,kFAAkF;AAClF,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAY3C,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,YAAY,GACtB,YAAY,CAId;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,uBAAuB,GAC/B,QAAQ,EAAE,CAmFZ"}
@@ -74,13 +74,23 @@ function tickmark(angle, { size, style, scale, text, inside, textRadius, rotatio
74
74
  } else if (size === "tertiary") {
75
75
  innerRadius = 164 + rOff;
76
76
  outerRadius = 168 + rOff;
77
- } else return [textSvg(text ?? "", {
78
- angle,
79
- inside,
80
- scale: safeScale,
81
- textRadius,
82
- endLabelsMaxMin
83
- })];
77
+ } else {
78
+ if (text && rotation !== void 0) return [turningLabelSvg(text, {
79
+ rad,
80
+ inside,
81
+ scale: safeScale,
82
+ textRadius,
83
+ rotation,
84
+ maxDigits
85
+ })];
86
+ return [textSvg(text ?? "", {
87
+ angle,
88
+ inside,
89
+ scale: safeScale,
90
+ textRadius,
91
+ endLabelsMaxMin
92
+ })];
93
+ }
84
94
  if (inside) {
85
95
  const outerRingRadius = 184 + rOff;
86
96
  const ring2Radius = 160 + rOff;
@@ -102,15 +112,27 @@ function tickmark(angle, { size, style, scale, text, inside, textRadius, rotatio
102
112
  textRadius,
103
113
  endLabelsMaxMin
104
114
  })];
105
- else {
106
- const newRadius = textRadius + (4 / safeScale + 5) * (inside ? -1 : 1) * maxDigits / 2;
107
- const textX = Math.sin(rad) * newRadius;
108
- const textY = -Math.cos(rad) * newRadius;
109
- return [tick, svg`<text x=${textX} y=${textY} class="label rotate ${inside ? "inside" : ""}" transform="rotate(${-rotation})" transform-origin="${textX} ${textY}">${text}</text>`];
110
- }
115
+ else return [tick, turningLabelSvg(text, {
116
+ rad,
117
+ inside,
118
+ scale: safeScale,
119
+ textRadius,
120
+ rotation,
121
+ maxDigits
122
+ })];
111
123
  }
112
124
  return tick;
113
125
  }
126
+ /**
127
+ * A label on a card that turns: centred on its mark, far enough out to clear
128
+ * the ring at any angle, and turned back so the text stays upright.
129
+ */
130
+ function turningLabelSvg(text, { rad, inside, scale, textRadius, rotation, maxDigits }) {
131
+ const newRadius = textRadius + (4 / scale + 5) * (inside ? -1 : 1) * maxDigits / 2;
132
+ const textX = Math.sin(rad) * newRadius;
133
+ const textY = -Math.cos(rad) * newRadius;
134
+ return svg`<text x=${textX} y=${textY} class="label rotate ${inside ? "inside" : ""}" transform="rotate(${-rotation})" transform-origin="${textX} ${textY}">${text}</text>`;
135
+ }
114
136
  function textSvg(text, { angle, inside, scale, textRadius, endLabelsMaxMin = false }) {
115
137
  const radHoriz = degToRad(angle);
116
138
  if (endLabelsMaxMin && Math.abs(Math.cos(radHoriz)) < 1e-6) {
@@ -1 +1 @@
1
- {"version":3,"file":"tickmark.js","names":[],"sources":["../../../src/navigation-instruments/watch/tickmark.ts"],"sourcesContent":["import {SVGTemplateResult, svg} from 'lit';\nimport {degToRad} from '../../svghelpers/math.js';\n\nexport interface Tickmark {\n angle: number;\n type: TickmarkType;\n text?: string;\n color?: string;\n}\n\nexport enum TickmarkType {\n zeroLineThick = 'zeroLineThick',\n zeroLine = 'zeroLine',\n main = 'main',\n primary = 'primary',\n secondary = 'secondary',\n tertiary = 'tertiary',\n textOnly = 'textOnly',\n}\n\nexport enum TickmarkStyle {\n regular = 'regular',\n enhanced = 'enhanced',\n}\n\n/**\n * Secondary tickmark ladder spanning a watch arc.\n *\n * Emits a `secondary` mark every `interval` degrees strictly inside the arc,\n * skipping the arc centre — which carries its own `main` mark — and the arc\n * ends, where the band's rounded end cap already reads as a boundary. Angles\n * are returned signed relative to `centerAngle`, matching the convention the\n * inclinometers already use for needles and bar areas.\n *\n * @param centerAngle Watch angle the arc is centred on.\n * @param halfExtent Half-extent of the arc in degrees; the arc spans `centerAngle ± halfExtent`.\n * @param interval Spacing between ladder marks in degrees.\n */\nexport function arcTickmarks(\n centerAngle: number,\n halfExtent: number,\n interval = 5\n): Tickmark[] {\n if (\n !Number.isFinite(centerAngle) ||\n !Number.isFinite(halfExtent) ||\n !Number.isFinite(interval) ||\n interval <= 0\n ) {\n return [];\n }\n const marks: Tickmark[] = [];\n const epsilon = 1e-6;\n for (\n let offset = interval;\n offset < halfExtent - epsilon;\n offset += interval\n ) {\n marks.push({angle: centerAngle - offset, type: TickmarkType.secondary});\n marks.push({angle: centerAngle + offset, type: TickmarkType.secondary});\n }\n return marks;\n}\n\nexport function tickmarkColor(\n style: TickmarkStyle,\n tickmarkType?: TickmarkType\n): string {\n if (style === TickmarkStyle.regular) {\n return 'var(--instrument-tick-mark-tertiary-color)';\n } else {\n if (tickmarkType === TickmarkType.tertiary) {\n return 'var(--instrument-tick-mark-secondary-color)';\n }\n return 'var(--instrument-tick-mark-primary-color)';\n }\n}\n\nexport function tickmark(\n angle: number,\n {\n size,\n style,\n scale,\n text,\n inside,\n textRadius,\n rotation,\n maxDigits,\n color,\n radiusOffset = 0,\n endLabelsMaxMin = false,\n }: {\n size: TickmarkType;\n style: TickmarkStyle;\n scale: number;\n text?: string;\n inside: boolean;\n textRadius: number;\n rotation?: number;\n maxDigits: number;\n color?: string;\n radiusOffset?: number;\n endLabelsMaxMin?: boolean;\n }\n): SVGTemplateResult | SVGTemplateResult[] {\n // Before layout settles the caller can pass a scale of 0 (or a non-finite\n // value). Label offsets are computed as `px / scale`, so a 0 scale would emit\n // ±Infinity coordinates that the browser rejects. Fall back to a 1:1 scale\n // until a real one is available (issue #1032).\n const safeScale = Number.isFinite(scale) && scale > 0 ? scale : 1;\n const rOff = radiusOffset;\n let innerRadius: number;\n let outerRadius: number;\n textRadius = textRadius + (3 / safeScale + 3) * (inside ? -1 : 1);\n const rad = degToRad(angle);\n if (size === TickmarkType.primary) {\n innerRadius = 328 / 2 + rOff;\n outerRadius = 368 / 2 + rOff;\n } else if (size === TickmarkType.secondary) {\n innerRadius = 328 / 2 + rOff;\n outerRadius = 344 / 2 + rOff;\n } else if (size === TickmarkType.main || size === TickmarkType.zeroLine) {\n innerRadius = 320 / 2 + rOff;\n outerRadius = 368 / 2 + rOff;\n } else if (size === TickmarkType.zeroLineThick) {\n innerRadius = 224 / 2 + rOff;\n outerRadius = 368 / 2 + rOff;\n } else if (size === TickmarkType.tertiary) {\n innerRadius = 328 / 2 + rOff;\n outerRadius = 336 / 2 + rOff;\n } else {\n return [\n textSvg(text ?? '', {\n angle,\n inside,\n scale: safeScale,\n textRadius,\n endLabelsMaxMin,\n }),\n ];\n }\n\n // When inside, anchor ticks at the outer ring edge and grow inward,\n // preserving the same gap from the ring edge as the outside case.\n // Outside: gap = innerRadius - RING2 (320/2). E.g. secondary: 164 - 160 = 4px gap.\n // Inside: mirror that gap from the outer ring (368/2).\n if (inside) {\n const outerRingRadius = 368 / 2 + rOff;\n const ring2Radius = 320 / 2 + rOff;\n const tickLength = outerRadius - innerRadius;\n const gapFromRingEdge = Math.max(0, innerRadius - ring2Radius);\n outerRadius = outerRingRadius - gapFromRingEdge;\n innerRadius = outerRadius - tickLength;\n }\n const colorName = color ?? tickmarkColor(style, size);\n\n const x1 = Math.sin(rad) * innerRadius;\n const y1 = -Math.cos(rad) * innerRadius;\n const x2 = Math.sin(rad) * outerRadius;\n const y2 = -Math.cos(rad) * outerRadius;\n const strokeWidth =\n size === TickmarkType.zeroLine || size === TickmarkType.zeroLineThick\n ? 4\n : 1;\n const tick = svg`<line x1=${x1} y1=${y1} x2=${x2} y2=${y2} stroke=${colorName} stroke-width=${strokeWidth} vector-effect=\"non-scaling-stroke\"/>`;\n if (text) {\n if (rotation === undefined) {\n return [\n tick,\n textSvg(text, {\n angle,\n inside,\n scale: safeScale,\n textRadius,\n endLabelsMaxMin,\n }),\n ];\n } else {\n const newRadius =\n textRadius + ((4 / safeScale + 5) * (inside ? -1 : 1) * maxDigits) / 2;\n const textX = Math.sin(rad) * newRadius;\n const textY = -Math.cos(rad) * newRadius;\n return [\n tick,\n svg`<text x=${textX} y=${textY} class=\"label rotate ${inside ? 'inside' : ''}\" transform=\"rotate(${-rotation})\" transform-origin=\"${textX} ${textY}\">${text}</text>`,\n ];\n }\n }\n return tick;\n}\n\nfunction textSvg(\n text: string,\n {\n angle,\n inside,\n scale,\n textRadius,\n endLabelsMaxMin = false,\n }: {\n angle: number;\n inside: boolean;\n scale: number;\n textRadius: number;\n endLabelsMaxMin?: boolean;\n }\n) {\n const radHoriz = degToRad(angle);\n // \"Max-min\" placement: horizontal end labels (±90°) sit off the dead-center\n // tick (below outside / lifted inside), inset inward by label width.\n if (endLabelsMaxMin && Math.abs(Math.cos(radHoriz)) < 1e-6) {\n const sin = Math.sin(radHoriz);\n const inward = inside ? (6 + (text.length - 1) * 2.5) / scale : 14 / scale;\n const x = sin * (textRadius - inward);\n const y = inside ? -(6 / scale) : 12 / scale;\n return svg`<text x=${x} y=${y} class=\"label bottom ${inside ? 'inside' : ''}\">${text}</text>`;\n }\n\n let positionClass;\n if (angle === 0) {\n positionClass = 'top';\n } else if (angle < 180 && angle > 0) {\n positionClass = 'right';\n } else if (angle === 180) {\n positionClass = 'bottom';\n } else {\n positionClass = 'left';\n }\n const rad = degToRad(angle);\n const insideGain = inside ? -1 : 1;\n const yOffset = (7 / scale) * insideGain;\n const xOffset = (6 / scale) * insideGain;\n\n let textX = Math.sin(rad) * (textRadius + xOffset);\n if (angle > 180) {\n textX += (4 / scale) * insideGain;\n } else if (angle < 180 && angle > 0) {\n textX -= (4 / scale) * insideGain;\n }\n const textY = -Math.cos(rad) * (textRadius + yOffset);\n return svg`<text x=${textX} y=${textY} class=\"label ${positionClass} ${inside ? 'inside' : ''}\">${text}</text>`;\n}\n\nexport interface IntervalTickmarkOptions {\n minValue: number;\n maxValue: number;\n /** Value→angle mapping (degrees, 0° = 12 o'clock). */\n mapAngle: (value: number) => number;\n primaryInterval?: number;\n secondaryInterval?: number;\n tertiaryInterval?: number;\n /** Label the primary-interval ticks and the min/max ends. */\n showLabels: boolean;\n /** Keep interval ticks unlabeled even with `showLabels` (end labels still apply). */\n suppressIntervalLabels?: boolean;\n /** Mark zero when the range spans it: `main` on a bipolar range, `textOnly` at a range end. */\n zeroTick?: boolean;\n /** Skip the max end label (a full circle's max coincides with its min). */\n suppressMaxEndLabel?: boolean;\n}\n\n/** Intervals that would emit more ticks than this are ignored (runaway guard). */\nexport const MAX_INTERVAL_TICKMARKS = 1000;\n\nconst TICKMARK_TYPE_RANK: Record<TickmarkType, number> = {\n [TickmarkType.zeroLineThick]: 6,\n [TickmarkType.zeroLine]: 5,\n [TickmarkType.main]: 4,\n [TickmarkType.primary]: 3,\n [TickmarkType.secondary]: 2,\n [TickmarkType.tertiary]: 1,\n [TickmarkType.textOnly]: 0,\n};\n\nexport function strongerTickmarkType(\n existing: TickmarkType,\n candidate: TickmarkType\n): TickmarkType {\n return TICKMARK_TYPE_RANK[candidate] > TICKMARK_TYPE_RANK[existing]\n ? candidate\n : existing;\n}\n\n/**\n * Value-interval tick ladder shared by the interval-configured gauges\n * (instrument-radial, gauge-proportional, …): primary/secondary/tertiary\n * ladders deduplicated by value, optional zero tick and min/max end labels,\n * sorted by angle.\n */\nexport function buildIntervalTickmarks(\n options: IntervalTickmarkOptions\n): Tickmark[] {\n const {minValue, maxValue, mapAngle, showLabels} = options;\n const tickmarksByValue = new Map<number, Tickmark>();\n const normalizeValue = (value: number) =>\n Math.abs(value) < 1e-9 ? 0 : Number(value.toFixed(6));\n\n const upsertTickmark = (value: number, type: TickmarkType, text?: string) => {\n if (!Number.isFinite(value) || value < minValue || value > maxValue) {\n return;\n }\n const normalizedValue = normalizeValue(value);\n const existing = tickmarksByValue.get(normalizedValue);\n if (existing) {\n existing.type = strongerTickmarkType(existing.type, type);\n if (text !== undefined) {\n existing.text = text;\n }\n return;\n }\n tickmarksByValue.set(normalizedValue, {\n angle: mapAngle(normalizedValue),\n type,\n text,\n });\n };\n\n const addTickmarksAtInterval = (\n interval: number | undefined,\n type: TickmarkType,\n withLabels = false\n ) => {\n if (\n interval === undefined ||\n interval <= 0 ||\n !Number.isFinite(interval) ||\n (maxValue - minValue) / interval > MAX_INTERVAL_TICKMARKS\n ) {\n return;\n }\n const epsilon = Math.abs(interval) * 1e-6;\n const startValue = Math.ceil((minValue - epsilon) / interval) * interval;\n for (\n let value = startValue;\n value < maxValue - epsilon;\n value += interval\n ) {\n const normalizedValue = normalizeValue(value);\n if (\n normalizedValue <= minValue + epsilon ||\n normalizedValue >= maxValue - epsilon\n ) {\n continue;\n }\n upsertTickmark(\n normalizedValue,\n type,\n withLabels && showLabels && !options.suppressIntervalLabels\n ? normalizedValue.toString()\n : undefined\n );\n }\n };\n\n addTickmarksAtInterval(options.primaryInterval, TickmarkType.primary, true);\n addTickmarksAtInterval(options.secondaryInterval, TickmarkType.secondary);\n addTickmarksAtInterval(options.tertiaryInterval, TickmarkType.tertiary);\n\n if (options.zeroTick && minValue <= 0 && maxValue >= 0) {\n upsertTickmark(\n 0,\n minValue < 0 ? TickmarkType.main : TickmarkType.textOnly,\n showLabels ? '0' : undefined\n );\n }\n\n if (showLabels) {\n upsertTickmark(minValue, TickmarkType.textOnly, minValue.toString());\n if (!options.suppressMaxEndLabel) {\n upsertTickmark(maxValue, TickmarkType.textOnly, maxValue.toString());\n }\n }\n\n return [...tickmarksByValue.values()].sort((a, b) => a.angle - b.angle);\n}\n"],"mappings":";;;AAUA,IAAY,eAAL,yBAAA,cAAA;CACL,aAAA,mBAAA;CACA,aAAA,cAAA;CACA,aAAA,UAAA;CACA,aAAA,aAAA;CACA,aAAA,eAAA;CACA,aAAA,cAAA;CACA,aAAA,cAAA;;AACF,EAAA,CAAA,CAAA;AAEA,IAAY,gBAAL,yBAAA,eAAA;CACL,cAAA,aAAA;CACA,cAAA,cAAA;;AACF,EAAA,CAAA,CAAA;;;;;;;;;;;;;;AAeA,SAAgB,aACd,aACA,YACA,WAAW,GACC;CACZ,IACE,CAAC,OAAO,SAAS,WAAW,KAC5B,CAAC,OAAO,SAAS,UAAU,KAC3B,CAAC,OAAO,SAAS,QAAQ,KACzB,YAAY,GAEZ,OAAO,CAAC;CAEV,MAAM,QAAoB,CAAC;CAC3B,MAAM,UAAU;CAChB,KACE,IAAI,SAAS,UACb,SAAS,aAAa,SACtB,UAAU,UACV;EACA,MAAM,KAAK;GAAC,OAAO,cAAc;GAAQ,MAAA;EAA4B,CAAC;EACtE,MAAM,KAAK;GAAC,OAAO,cAAc;GAAQ,MAAA;EAA4B,CAAC;CACxE;CACA,OAAO;AACT;AAEA,SAAgB,cACd,OACA,cACQ;CACR,IAAI,UAAA,WACF,OAAO;MACF;EACL,IAAI,iBAAA,YACF,OAAO;EAET,OAAO;CACT;AACF;AAEA,SAAgB,SACd,OACA,EACE,MACA,OACA,OACA,MACA,QACA,YACA,UACA,WACA,OACA,eAAe,GACf,kBAAkB,SAcqB;CAKzC,MAAM,YAAY,OAAO,SAAS,KAAK,KAAK,QAAQ,IAAI,QAAQ;CAChE,MAAM,OAAO;CACb,IAAI;CACJ,IAAI;CACJ,aAAa,cAAc,IAAI,YAAY,MAAM,SAAS,KAAK;CAC/D,MAAM,MAAM,SAAS,KAAK;CAC1B,IAAI,SAAA,WAA+B;E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AAyC;CACxE,uBAAuB,QAAQ,kBAAA,UAAuC;CAEtE,IAAI,QAAQ,YAAY,YAAY,KAAK,YAAY,GACnD,eACE,GACA,WAAW,IAAA,SAAA,YACX,aAAa,MAAM,KAAA,CACrB;CAGF,IAAI,YAAY;EACd,eAAe,UAAA,YAAiC,SAAS,SAAS,CAAC;EACnE,IAAI,CAAC,QAAQ,qBACX,eAAe,UAAA,YAAiC,SAAS,SAAS,CAAC;CAEvE;CAEA,OAAO,CAAC,GAAG,iBAAiB,OAAO,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;AACxE"}
1
+ {"version":3,"file":"tickmark.js","names":[],"sources":["../../../src/navigation-instruments/watch/tickmark.ts"],"sourcesContent":["import {SVGTemplateResult, svg} from 'lit';\nimport {degToRad} from '../../svghelpers/math.js';\n\nexport interface Tickmark {\n angle: number;\n type: TickmarkType;\n text?: string;\n color?: string;\n}\n\nexport enum TickmarkType {\n zeroLineThick = 'zeroLineThick',\n zeroLine = 'zeroLine',\n main = 'main',\n primary = 'primary',\n secondary = 'secondary',\n tertiary = 'tertiary',\n textOnly = 'textOnly',\n}\n\nexport enum TickmarkStyle {\n regular = 'regular',\n enhanced = 'enhanced',\n}\n\n/**\n * Secondary tickmark ladder spanning a watch arc.\n *\n * Emits a `secondary` mark every `interval` degrees strictly inside the arc,\n * skipping the arc centre — which carries its own `main` mark — and the arc\n * ends, where the band's rounded end cap already reads as a boundary. Angles\n * are returned signed relative to `centerAngle`, matching the convention the\n * inclinometers already use for needles and bar areas.\n *\n * @param centerAngle Watch angle the arc is centred on.\n * @param halfExtent Half-extent of the arc in degrees; the arc spans `centerAngle ± halfExtent`.\n * @param interval Spacing between ladder marks in degrees.\n */\nexport function arcTickmarks(\n centerAngle: number,\n halfExtent: number,\n interval = 5\n): Tickmark[] {\n if (\n !Number.isFinite(centerAngle) ||\n !Number.isFinite(halfExtent) ||\n !Number.isFinite(interval) ||\n interval <= 0\n ) {\n return [];\n }\n const marks: Tickmark[] = [];\n const epsilon = 1e-6;\n for (\n let offset = interval;\n offset < halfExtent - epsilon;\n offset += interval\n ) {\n marks.push({angle: centerAngle - offset, type: TickmarkType.secondary});\n marks.push({angle: centerAngle + offset, type: TickmarkType.secondary});\n }\n return marks;\n}\n\nexport function tickmarkColor(\n style: TickmarkStyle,\n tickmarkType?: TickmarkType\n): string {\n if (style === TickmarkStyle.regular) {\n return 'var(--instrument-tick-mark-tertiary-color)';\n } else {\n if (tickmarkType === TickmarkType.tertiary) {\n return 'var(--instrument-tick-mark-secondary-color)';\n }\n return 'var(--instrument-tick-mark-primary-color)';\n }\n}\n\nexport function tickmark(\n angle: number,\n {\n size,\n style,\n scale,\n text,\n inside,\n textRadius,\n rotation,\n maxDigits,\n color,\n radiusOffset = 0,\n endLabelsMaxMin = false,\n }: {\n size: TickmarkType;\n style: TickmarkStyle;\n scale: number;\n text?: string;\n inside: boolean;\n textRadius: number;\n rotation?: number;\n maxDigits: number;\n color?: string;\n radiusOffset?: number;\n endLabelsMaxMin?: boolean;\n }\n): SVGTemplateResult | SVGTemplateResult[] {\n // Before layout settles the caller can pass a scale of 0 (or a non-finite\n // value). Label offsets are computed as `px / scale`, so a 0 scale would emit\n // ±Infinity coordinates that the browser rejects. Fall back to a 1:1 scale\n // until a real one is available (issue #1032).\n const safeScale = Number.isFinite(scale) && scale > 0 ? scale : 1;\n const rOff = radiusOffset;\n let innerRadius: number;\n let outerRadius: number;\n textRadius = textRadius + (3 / safeScale + 3) * (inside ? -1 : 1);\n const rad = degToRad(angle);\n if (size === TickmarkType.primary) {\n innerRadius = 328 / 2 + rOff;\n outerRadius = 368 / 2 + rOff;\n } else if (size === TickmarkType.secondary) {\n innerRadius = 328 / 2 + rOff;\n outerRadius = 344 / 2 + rOff;\n } else if (size === TickmarkType.main || size === TickmarkType.zeroLine) {\n innerRadius = 320 / 2 + rOff;\n outerRadius = 368 / 2 + rOff;\n } else if (size === TickmarkType.zeroLineThick) {\n innerRadius = 224 / 2 + rOff;\n outerRadius = 368 / 2 + rOff;\n } else if (size === TickmarkType.tertiary) {\n innerRadius = 328 / 2 + rOff;\n outerRadius = 336 / 2 + rOff;\n } else {\n if (text && rotation !== undefined) {\n return [\n turningLabelSvg(text, {\n rad,\n inside,\n scale: safeScale,\n textRadius,\n rotation,\n maxDigits,\n }),\n ];\n }\n return [\n textSvg(text ?? '', {\n angle,\n inside,\n scale: safeScale,\n textRadius,\n endLabelsMaxMin,\n }),\n ];\n }\n\n // When inside, anchor ticks at the outer ring edge and grow inward,\n // preserving the same gap from the ring edge as the outside case.\n // Outside: gap = innerRadius - RING2 (320/2). E.g. secondary: 164 - 160 = 4px gap.\n // Inside: mirror that gap from the outer ring (368/2).\n if (inside) {\n const outerRingRadius = 368 / 2 + rOff;\n const ring2Radius = 320 / 2 + rOff;\n const tickLength = outerRadius - innerRadius;\n const gapFromRingEdge = Math.max(0, innerRadius - ring2Radius);\n outerRadius = outerRingRadius - gapFromRingEdge;\n innerRadius = outerRadius - tickLength;\n }\n const colorName = color ?? tickmarkColor(style, size);\n\n const x1 = Math.sin(rad) * innerRadius;\n const y1 = -Math.cos(rad) * innerRadius;\n const x2 = Math.sin(rad) * outerRadius;\n const y2 = -Math.cos(rad) * outerRadius;\n const strokeWidth =\n size === TickmarkType.zeroLine || size === TickmarkType.zeroLineThick\n ? 4\n : 1;\n const tick = svg`<line x1=${x1} y1=${y1} x2=${x2} y2=${y2} stroke=${colorName} stroke-width=${strokeWidth} vector-effect=\"non-scaling-stroke\"/>`;\n if (text) {\n if (rotation === undefined) {\n return [\n tick,\n textSvg(text, {\n angle,\n inside,\n scale: safeScale,\n textRadius,\n endLabelsMaxMin,\n }),\n ];\n } else {\n return [\n tick,\n turningLabelSvg(text, {\n rad,\n inside,\n scale: safeScale,\n textRadius,\n rotation,\n maxDigits,\n }),\n ];\n }\n }\n return tick;\n}\n\n/**\n * A label on a card that turns: centred on its mark, far enough out to clear\n * the ring at any angle, and turned back so the text stays upright.\n */\nfunction turningLabelSvg(\n text: string,\n {\n rad,\n inside,\n scale,\n textRadius,\n rotation,\n maxDigits,\n }: {\n rad: number;\n inside: boolean;\n scale: number;\n textRadius: number;\n rotation: number;\n maxDigits: number;\n }\n) {\n const newRadius =\n textRadius + ((4 / scale + 5) * (inside ? -1 : 1) * maxDigits) / 2;\n const textX = Math.sin(rad) * newRadius;\n const textY = -Math.cos(rad) * newRadius;\n return svg`<text x=${textX} y=${textY} class=\"label rotate ${inside ? 'inside' : ''}\" transform=\"rotate(${-rotation})\" transform-origin=\"${textX} ${textY}\">${text}</text>`;\n}\n\nfunction textSvg(\n text: string,\n {\n angle,\n inside,\n scale,\n textRadius,\n endLabelsMaxMin = false,\n }: {\n angle: number;\n inside: boolean;\n scale: number;\n textRadius: number;\n endLabelsMaxMin?: boolean;\n }\n) {\n const radHoriz = degToRad(angle);\n // \"Max-min\" placement: horizontal end labels (±90°) sit off the dead-center\n // tick (below outside / lifted inside), inset inward by label width.\n if (endLabelsMaxMin && Math.abs(Math.cos(radHoriz)) < 1e-6) {\n const sin = Math.sin(radHoriz);\n const inward = inside ? (6 + (text.length - 1) * 2.5) / scale : 14 / scale;\n const x = sin * (textRadius - inward);\n const y = inside ? -(6 / scale) : 12 / scale;\n return svg`<text x=${x} y=${y} class=\"label bottom ${inside ? 'inside' : ''}\">${text}</text>`;\n }\n\n let positionClass;\n if (angle === 0) {\n positionClass = 'top';\n } else if (angle < 180 && angle > 0) {\n positionClass = 'right';\n } else if (angle === 180) {\n positionClass = 'bottom';\n } else {\n positionClass = 'left';\n }\n const rad = degToRad(angle);\n const insideGain = inside ? -1 : 1;\n const yOffset = (7 / scale) * insideGain;\n const xOffset = (6 / scale) * insideGain;\n\n let textX = Math.sin(rad) * (textRadius + xOffset);\n if (angle > 180) {\n textX += (4 / scale) * insideGain;\n } else if (angle < 180 && angle > 0) {\n textX -= (4 / scale) * insideGain;\n }\n const textY = -Math.cos(rad) * (textRadius + yOffset);\n return svg`<text x=${textX} y=${textY} class=\"label ${positionClass} ${inside ? 'inside' : ''}\">${text}</text>`;\n}\n\nexport interface IntervalTickmarkOptions {\n minValue: number;\n maxValue: number;\n /** Value→angle mapping (degrees, 0° = 12 o'clock). */\n mapAngle: (value: number) => number;\n primaryInterval?: number;\n secondaryInterval?: number;\n tertiaryInterval?: number;\n /** Label the primary-interval ticks and the min/max ends. */\n showLabels: boolean;\n /** Keep interval ticks unlabeled even with `showLabels` (end labels still apply). */\n suppressIntervalLabels?: boolean;\n /** Mark zero when the range spans it: `main` on a bipolar range, `textOnly` at a range end. */\n zeroTick?: boolean;\n /** Skip the max end label (a full circle's max coincides with its min). */\n suppressMaxEndLabel?: boolean;\n}\n\n/** Intervals that would emit more ticks than this are ignored (runaway guard). */\nexport const MAX_INTERVAL_TICKMARKS = 1000;\n\nconst TICKMARK_TYPE_RANK: Record<TickmarkType, number> = {\n [TickmarkType.zeroLineThick]: 6,\n [TickmarkType.zeroLine]: 5,\n [TickmarkType.main]: 4,\n [TickmarkType.primary]: 3,\n [TickmarkType.secondary]: 2,\n [TickmarkType.tertiary]: 1,\n [TickmarkType.textOnly]: 0,\n};\n\nexport function strongerTickmarkType(\n existing: TickmarkType,\n candidate: TickmarkType\n): TickmarkType {\n return TICKMARK_TYPE_RANK[candidate] > TICKMARK_TYPE_RANK[existing]\n ? candidate\n : existing;\n}\n\n/**\n * Value-interval tick ladder shared by the interval-configured gauges\n * (instrument-radial, gauge-proportional, …): primary/secondary/tertiary\n * ladders deduplicated by value, optional zero tick and min/max end labels,\n * sorted by angle.\n */\nexport function buildIntervalTickmarks(\n options: IntervalTickmarkOptions\n): Tickmark[] {\n const {minValue, maxValue, mapAngle, showLabels} = options;\n const tickmarksByValue = new Map<number, Tickmark>();\n const normalizeValue = (value: number) =>\n Math.abs(value) < 1e-9 ? 0 : Number(value.toFixed(6));\n\n const upsertTickmark = (value: number, type: TickmarkType, text?: string) => {\n if (!Number.isFinite(value) || value < minValue || value > maxValue) {\n return;\n }\n const normalizedValue = normalizeValue(value);\n const existing = tickmarksByValue.get(normalizedValue);\n if (existing) {\n existing.type = strongerTickmarkType(existing.type, type);\n if (text !== undefined) {\n existing.text = text;\n }\n return;\n }\n tickmarksByValue.set(normalizedValue, {\n angle: mapAngle(normalizedValue),\n type,\n text,\n });\n };\n\n const addTickmarksAtInterval = (\n interval: number | undefined,\n type: TickmarkType,\n withLabels = false\n ) => {\n if (\n interval === undefined ||\n interval <= 0 ||\n !Number.isFinite(interval) ||\n (maxValue - minValue) / interval > MAX_INTERVAL_TICKMARKS\n ) {\n return;\n }\n const epsilon = Math.abs(interval) * 1e-6;\n const startValue = Math.ceil((minValue - epsilon) / interval) * interval;\n for (\n let value = startValue;\n value < maxValue - epsilon;\n value += interval\n ) {\n const normalizedValue = normalizeValue(value);\n if (\n normalizedValue <= minValue + epsilon ||\n normalizedValue >= maxValue - epsilon\n ) {\n continue;\n }\n upsertTickmark(\n normalizedValue,\n type,\n withLabels && showLabels && !options.suppressIntervalLabels\n ? normalizedValue.toString()\n : undefined\n );\n }\n };\n\n addTickmarksAtInterval(options.primaryInterval, TickmarkType.primary, true);\n addTickmarksAtInterval(options.secondaryInterval, TickmarkType.secondary);\n addTickmarksAtInterval(options.tertiaryInterval, TickmarkType.tertiary);\n\n if (options.zeroTick && minValue <= 0 && maxValue >= 0) {\n upsertTickmark(\n 0,\n minValue < 0 ? TickmarkType.main : TickmarkType.textOnly,\n showLabels ? '0' : undefined\n );\n }\n\n if (showLabels) {\n upsertTickmark(minValue, TickmarkType.textOnly, minValue.toString());\n if (!options.suppressMaxEndLabel) {\n upsertTickmark(maxValue, TickmarkType.textOnly, maxValue.toString());\n }\n }\n\n return [...tickmarksByValue.values()].sort((a, b) => a.angle - b.angle);\n}\n"],"mappings":";;;AAUA,IAAY,eAAL,yBAAA,cAAA;CACL,aAAA,mBAAA;CACA,aAAA,cAAA;CACA,aAAA,UAAA;CACA,aAAA,aAAA;CACA,aAAA,eAAA;CACA,aAAA,cAAA;CACA,a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WAAyC;CACxE,uBAAuB,QAAQ,kBAAA,UAAuC;CAEtE,IAAI,QAAQ,YAAY,YAAY,KAAK,YAAY,GACnD,eACE,GACA,WAAW,IAAA,SAAA,YACX,aAAa,MAAM,KAAA,CACrB;CAGF,IAAI,YAAY;EACd,eAAe,UAAA,YAAiC,SAAS,SAAS,CAAC;EACnE,IAAI,CAAC,QAAQ,qBACX,eAAe,UAAA,YAAiC,SAAS,SAAS,CAAC;CAEvE;CAEA,OAAO,CAAC,GAAG,iBAAiB,OAAO,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;AACxE"}
@@ -29,6 +29,13 @@ export declare function clampPercent(value: number): number;
29
29
  * @returns The same direction in `[0, 360)`, never negative zero.
30
30
  */
31
31
  export declare function normalizeAngle(deg: number): number;
32
+ /**
33
+ * Degrees wrapped into `[-180, 180)`, for a deviation either side of zero.
34
+ *
35
+ * @param deg - Any finite angle, negative and over-turned included; a non-finite angle yields NaN.
36
+ * @returns The same direction in `[-180, 180)`; a half turn is `-180`.
37
+ */
38
+ export declare function normalizeSignedAngle(deg: number): number;
32
39
  /**
33
40
  * @param deg - Angle in degrees.
34
41
  * @returns The angle in radians, as `(deg * Math.PI) / 180`.
@@ -1 +1 @@
1
- {"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../src/svghelpers/math.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAErE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGlD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE5C"}
1
+ {"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../src/svghelpers/math.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAErE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGlD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAExD;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE5C"}
@@ -38,6 +38,15 @@ function normalizeAngle(deg) {
38
38
  return (deg % 360 + 360) % 360;
39
39
  }
40
40
  /**
41
+ * Degrees wrapped into `[-180, 180)`, for a deviation either side of zero.
42
+ *
43
+ * @param deg - Any finite angle, negative and over-turned included; a non-finite angle yields NaN.
44
+ * @returns The same direction in `[-180, 180)`; a half turn is `-180`.
45
+ */
46
+ function normalizeSignedAngle(deg) {
47
+ return normalizeAngle(deg + 180) - 180;
48
+ }
49
+ /**
41
50
  * @param deg - Angle in degrees.
42
51
  * @returns The angle in radians, as `(deg * Math.PI) / 180`.
43
52
  */
@@ -51,6 +60,6 @@ function degToRad(deg) {
51
60
  function radToDeg(rad) {
52
61
  return rad * 180 / Math.PI;
53
62
  }
54
- export { clamp, clampPercent, degToRad, normalizeAngle, radToDeg };
63
+ export { clamp, clampPercent, degToRad, normalizeAngle, normalizeSignedAngle, radToDeg };
55
64
 
56
65
  //# sourceMappingURL=math.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"math.js","names":[],"sources":["../../src/svghelpers/math.ts"],"sourcesContent":["/**\n * Numeric helpers shared by the SVG instruments and the components that draw\n * with them: range clamping, angle wrapping and degree/radian conversion.\n *\n * Keep the operand order as written. `(deg * Math.PI) / 180` and\n * `deg * (Math.PI / 180)` differ in the last bit, and the instrument\n * snapshots pin the former.\n */\n\n/**\n * `value` limited to `[min, max]`.\n *\n * @param value - Any number. NaN passes through as NaN, as with `Math.min` / `Math.max`.\n * @param min - Lower bound, inclusive.\n * @param max - Upper bound, inclusive; it wins when `min > max`.\n * @returns The bounded value.\n */\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n\n/**\n * A percentage limited to `[0, 100]`.\n *\n * @param value - Any number. NaN counts as 0, so a missing reading draws empty; ±Infinity clamp to the bounds.\n * @returns The bounded percentage.\n */\nexport function clampPercent(value: number): number {\n if (Number.isNaN(value)) return 0;\n return clamp(value, 0, 100);\n}\n\n/**\n * Degrees wrapped into `[0, 360)`.\n *\n * @param deg - Any finite angle, negative and over-turned included; a non-finite angle yields NaN.\n * @returns The same direction in `[0, 360)`, never negative zero.\n */\nexport function normalizeAngle(deg: number): number {\n return ((deg % 360) + 360) % 360;\n}\n\n/**\n * @param deg - Angle in degrees.\n * @returns The angle in radians, as `(deg * Math.PI) / 180`.\n */\nexport function degToRad(deg: number): number {\n return (deg * Math.PI) / 180;\n}\n\n/**\n * @param rad - Angle in radians.\n * @returns The angle in degrees, as `(rad * 180) / Math.PI`.\n */\nexport function radToDeg(rad: number): number {\n return (rad * 180) / Math.PI;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAgB,MAAM,OAAe,KAAa,KAAqB;CACrE,OAAO,KAAK,IAAI,KAAK,IAAI,OAAO,GAAG,GAAG,GAAG;AAC3C;;;;;;;AAQA,SAAgB,aAAa,OAAuB;CAClD,IAAI,OAAO,MAAM,KAAK,GAAG,OAAO;CAChC,OAAO,MAAM,OAAO,GAAG,GAAG;AAC5B;;;;;;;AAQA,SAAgB,eAAe,KAAqB;CAClD,QAAS,MAAM,MAAO,OAAO;AAC/B;;;;;AAMA,SAAgB,SAAS,KAAqB;CAC5C,OAAQ,MAAM,KAAK,KAAM;AAC3B;;;;;AAMA,SAAgB,SAAS,KAAqB;CAC5C,OAAQ,MAAM,MAAO,KAAK;AAC5B"}
1
+ {"version":3,"file":"math.js","names":[],"sources":["../../src/svghelpers/math.ts"],"sourcesContent":["/**\n * Numeric helpers shared by the SVG instruments and the components that draw\n * with them: range clamping, angle wrapping and degree/radian conversion.\n *\n * Keep the operand order as written. `(deg * Math.PI) / 180` and\n * `deg * (Math.PI / 180)` differ in the last bit, and the instrument\n * snapshots pin the former.\n */\n\n/**\n * `value` limited to `[min, max]`.\n *\n * @param value - Any number. NaN passes through as NaN, as with `Math.min` / `Math.max`.\n * @param min - Lower bound, inclusive.\n * @param max - Upper bound, inclusive; it wins when `min > max`.\n * @returns The bounded value.\n */\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n\n/**\n * A percentage limited to `[0, 100]`.\n *\n * @param value - Any number. NaN counts as 0, so a missing reading draws empty; ±Infinity clamp to the bounds.\n * @returns The bounded percentage.\n */\nexport function clampPercent(value: number): number {\n if (Number.isNaN(value)) return 0;\n return clamp(value, 0, 100);\n}\n\n/**\n * Degrees wrapped into `[0, 360)`.\n *\n * @param deg - Any finite angle, negative and over-turned included; a non-finite angle yields NaN.\n * @returns The same direction in `[0, 360)`, never negative zero.\n */\nexport function normalizeAngle(deg: number): number {\n return ((deg % 360) + 360) % 360;\n}\n\n/**\n * Degrees wrapped into `[-180, 180)`, for a deviation either side of zero.\n *\n * @param deg - Any finite angle, negative and over-turned included; a non-finite angle yields NaN.\n * @returns The same direction in `[-180, 180)`; a half turn is `-180`.\n */\nexport function normalizeSignedAngle(deg: number): number {\n return normalizeAngle(deg + 180) - 180;\n}\n\n/**\n * @param deg - Angle in degrees.\n * @returns The angle in radians, as `(deg * Math.PI) / 180`.\n */\nexport function degToRad(deg: number): number {\n return (deg * Math.PI) / 180;\n}\n\n/**\n * @param rad - Angle in radians.\n * @returns The angle in degrees, as `(rad * 180) / Math.PI`.\n */\nexport function radToDeg(rad: number): number {\n return (rad * 180) / Math.PI;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAgB,MAAM,OAAe,KAAa,KAAqB;CACrE,OAAO,KAAK,IAAI,KAAK,IAAI,OAAO,GAAG,GAAG,GAAG;AAC3C;;;;;;;AAQA,SAAgB,aAAa,OAAuB;CAClD,IAAI,OAAO,MAAM,KAAK,GAAG,OAAO;CAChC,OAAO,MAAM,OAAO,GAAG,GAAG;AAC5B;;;;;;;AAQA,SAAgB,eAAe,KAAqB;CAClD,QAAS,MAAM,MAAO,OAAO;AAC/B;;;;;;;AAQA,SAAgB,qBAAqB,KAAqB;CACxD,OAAO,eAAe,MAAM,GAAG,IAAI;AACrC;;;;;AAMA,SAAgB,SAAS,KAAqB;CAC5C,OAAQ,MAAM,KAAK,KAAM;AAC3B;;;;;AAMA,SAAgB,SAAS,KAAqB;CAC5C,OAAQ,MAAM,MAAO,KAAK;AAC5B"}
@@ -0,0 +1,69 @@
1
+ # `<obc-attitude>`
2
+
3
+ Attitude instrument that shows pitch and roll as a moving horizon behind a fixed vessel symbol, the way an artificial horizon does.
4
+
5
+ Lifecycle: experimental. [Storybook](https://openbridge-next-storybook.web.app/?path=/docs/instruments-attitude--docs) · [Source](https://raw.githubusercontent.com/Ocean-Industries-Concept-Lab/openbridge-webcomponents/develop/packages/openbridge-webcomponents/src/navigation-instruments/attitude/attitude.ts)
6
+
7
+ `<obc-attitude>` – Attitude instrument that shows pitch and roll as a moving
8
+ horizon behind a fixed vessel symbol, the way an artificial horizon does.
9
+
10
+ The symbol in the centre stays level. The ground half of the face slides
11
+ down as the pitch rises and tilts against the roll, so the picture matches
12
+ what is seen looking forward. A ladder of short rungs on the horizon gives
13
+ the pitch. The roll scale turns with the horizon, and the pointer at the
14
+ top, which stays straight up like the symbol, reads the roll on it.
15
+
16
+ ## Features / Variants
17
+
18
+ - **Roll scale:** the band over the sky half of the face, labelled
19
+ 90/45/0/45/90. It turns with the horizon, so the fixed pointer sits on
20
+ the side the vehicle rolls to. `showLabels` turns the labels off.
21
+ - **Full turns:** `pitch` and `roll` take any angle. Past ±90° of pitch the
22
+ ladder runs on to the inverted horizon, with the ground above the sky,
23
+ and the roll scale follows the sky to the lower half.
24
+ - **Pitch ladder:** one rung per `pitchTickInterval` degrees. A smaller
25
+ interval magnifies the pitch; a larger one shows more of it.
26
+ - **Priority:** `priority` switches the symbol and the pointer between the
27
+ `regular` and `enhanced` palette.
28
+
29
+ ## Usage Guidelines
30
+
31
+ Use for a vehicle that is steered in three dimensions and whose operator
32
+ needs pitch and roll together at a glance. For readings against a scale
33
+ with advice zones use `obc-pitch`, `obc-roll` or `obc-pitch-roll`; for
34
+ pitch, roll and yaw deviation as a dot on a polar grid use
35
+ `obc-pitch-roll-yaw`.
36
+
37
+ The scales carry no numbers besides the roll labels. Put the values next to
38
+ the instrument with `obc-readout` when they have to be read exactly.
39
+
40
+ **TODO(designer)**: Figma 20108:142407 shows no pitch values on the ladder.
41
+
42
+ ## Properties
43
+
44
+ | Property | Attribute | Type | Default | Description |
45
+ | --- | --- | --- | --- | --- |
46
+ | pitch | pitch | `number` | `0` | Pitch in degrees, positive with the front up. The horizon drops below the symbol as it rises. Any angle is accepted and wraps over a full turn. |
47
+ | roll | roll | `number` | `0` | Roll in degrees, positive with the right side down. The horizon and the roll scale turn the other way, as they appear from on board. Any angle is accepted. |
48
+ | pitchTickInterval | pitchTickInterval | `number` | `10` | Degrees of pitch between two ladder rungs, from 0.1 to 90. Default `10`, which shows about ±29° on the face. |
49
+ | showLabels | | `boolean` | `true` | When `true` (default), labels the roll scale. |
50
+ | priority | priority | `Priority` | | Palette of the symbol and the pointer: `regular` or `enhanced`. |
51
+ | faceDiameter | face-diameter | `number \| undefined` | | Outer-ring diameter in CSS pixels. When set, the instrument renders at a fixed size, so instruments that share the value have rings of the same size. |
52
+
53
+ ## Events
54
+
55
+ None.
56
+
57
+ ## Slots
58
+
59
+ None.
60
+
61
+ ## Stories
62
+
63
+ - [Default](https://openbridge-next-storybook.web.app/?path=/story/instruments-attitude--default): Level, as the design draws it (Figma 20108:142406).
64
+ - [Enhanced](https://openbridge-next-storybook.web.app/?path=/story/instruments-attitude--enhanced)
65
+ - [Pitch And Roll](https://openbridge-next-storybook.web.app/?path=/story/instruments-attitude--pitch-and-roll): Front up and right side down: the horizon drops and tilts to the left, and the roll scale turns with it under the pointer.
66
+ - [Inverted](https://openbridge-next-storybook.web.app/?path=/story/instruments-attitude--inverted): Past half a turn of pitch the ladder shows the inverted horizon, ground on top. The roll scale follows the sky to the lower half, away from the pointer.
67
+ - [Fine Ladder](https://openbridge-next-storybook.web.app/?path=/story/instruments-attitude--fine-ladder): One rung is 5°, so the same pitch moves the horizon twice as far.
68
+ - [Without Labels](https://openbridge-next-storybook.web.app/?path=/story/instruments-attitude--without-labels)
69
+ - [Small](https://openbridge-next-storybook.web.app/?path=/story/instruments-attitude--small): The roll labels keep their text size, so a small face gives up room to them.