@oicl/openbridge-webcomponents-full-bundle 2.2.0-next.23 → 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 (35) hide show
  1. package/bundle/openbridge-webcomponents.bundle.js +538 -202
  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/advice-linear.d.ts.map +1 -1
  14. package/dist/svghelpers/advice-linear.js +10 -4
  15. package/dist/svghelpers/advice-linear.js.map +1 -1
  16. package/dist/svghelpers/math.d.ts +7 -0
  17. package/dist/svghelpers/math.d.ts.map +1 -1
  18. package/dist/svghelpers/math.js +10 -1
  19. package/dist/svghelpers/math.js.map +1 -1
  20. package/llms/components/obc-attitude.md +69 -0
  21. package/llms/docs/building-blocks-advice.md +1 -0
  22. package/llms/llms-full.txt +73 -0
  23. package/llms/llms.txt +1 -0
  24. package/package.json +1 -1
  25. package/src/building-blocks/advice/advice.stories.ts +34 -0
  26. package/src/building-blocks/external-scale/external-scale.spec.ts +15 -0
  27. package/src/navigation-instruments/attitude/attitude.css +54 -0
  28. package/src/navigation-instruments/attitude/attitude.spec.ts +208 -0
  29. package/src/navigation-instruments/attitude/attitude.stories.ts +87 -0
  30. package/src/navigation-instruments/attitude/attitude.ts +351 -0
  31. package/src/navigation-instruments/watch/tickmark.spec.ts +22 -0
  32. package/src/navigation-instruments/watch/tickmark.ts +49 -5
  33. package/src/svghelpers/advice-linear.ts +16 -4
  34. package/src/svghelpers/math.spec.ts +25 -0
  35. 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,o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AC;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"}
1
+ {"version":3,"file":"tickmark.d.ts","sourceRoot":"","sources":["../../../src/navigation-instruments/watch/tickmark.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAM,MAAM,KAAK,CAAC;AAG3C,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,oBAAY,YAAY;IACtB,aAAa,kBAAkB;IAC/B,QAAQ,aAAa;IACrB,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,QAAQ,aAAa;IACrB,QAAQ,aAAa;CACtB;AAED,oBAAY,aAAa;IACvB,OAAO,YAAY;IACnB,QAAQ,aAAa;CACtB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAC1B,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,QAAQ,SAAI,GACX,QAAQ,EAAE,CAoBZ;AAED,wBAAgB,aAAa,CAC3B,KAAK,EAAE,aAAa,EACpB,YAAY,CAAC,EAAE,YAAY,GAC1B,MAAM,CASR;AAED,wBAAgB,QAAQ,CACtB,KAAK,EAAE,MAAM,EACb,EACE,IAAI,EACJ,KAAK,EACL,KAAK,EACL,IAAI,EACJ,MAAM,EACN,UAAU,EACV,QAAQ,EACR,SAAS,EACT,KAAK,EACL,YAAgB,EAChB,eAAuB,GACxB,EAAE;IACD,IAAI,EAAE,YAAY,CAAC;IACnB,KAAK,EAAE,aAAa,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC;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,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AM,kBAAkB,eAAe,KAAK;GAC5C,IACE,mBAAmB,WAAW,WAC9B,mBAAmB,WAAW,SAE9B;GAEF,eACE,iBACA,MACA,cAAc,cAAc,CAAC,QAAQ,yBACjC,gBAAgB,SAAS,IACzB,KAAA,CACN;EACF;CACF;CAEA,uBAAuB,QAAQ,iBAAA,WAAuC,IAAI;CAC1E,uBAAuB,QAAQ,mBAAA,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"}
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,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;EACjC,cAA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E,CAAC,EAAE,MAAM,CAAC;CACb;AAED,yFAAyF;AACzF,wBAAgB,sBAAsB,CACpC,CAAC,EAAE,uBAAuB,GACzB,iBAAiB,CAWnB"}
1
+ {"version":3,"file":"advice-linear.d.ts","sourceRoot":"","sources":["../../src/svghelpers/advice-linear.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAC,OAAO,EAAO,KAAK,iBAAiB,EAAC,MAAM,KAAK,CAAC;AACzD,OAAO,EAeL,KAAK,WAAW,EAChB,KAAK,cAAc,EAEpB,MAAM,aAAa,CAAC;AAIrB,oFAAoF;AACpF,MAAM,WAAW,uBAAuB;IACtC,2DAA2D;IAC3D,QAAQ,EAAE,OAAO,CAAC;IAClB,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,kGAAkG;IAClG,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,WAAW,GAAG,cAAc,CAAC;IACrC,2DAA2D;IAC3D,MAAM,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AA+ED,2EAA2E;AAC3E,wBAAgB,sBAAsB,CACpC,CAAC,EAAE,uBAAuB,GACzB,iBAAiB,GAAG,OAAO,OAAO,CAoCpC;AAED,sEAAsE;AACtE,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,OAAO,CAAC;IAClB,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,WAAW,GAAG,cAAc,CAAC;IACrC,0FAA0F;IAC1F,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,CAAC,EAAE,wBAAwB,GAC1B,iBAAiB,CAmBnB;AAED,qFAAqF;AACrF,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,WAAW,GAAG,cAAc,CAAC;IACrC,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,CAAC,EAAE,uBAAuB,GACzB,iBAAiB,CAwCnB;AAED,iGAAiG;AACjG,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,OAAO,CAAC;IAClB,iGAAiG;IACjG,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,WAAW,GAAG,cAAc,CAAC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wEAAwE;IACxE,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,yFAAyF;AACzF,wBAAgB,sBAAsB,CACpC,CAAC,EAAE,uBAAuB,GACzB,iBAAiB,CAWnB"}
@@ -19,6 +19,11 @@ var point = (vertical, main, perp) => vertical ? `${perp} ${main}` : `${main} ${
19
19
  * coordinate is the advice's start cap when `mainStart <= mainEnd`, as on a
20
20
  * horizontal scale, and its end cap otherwise, as on a vertical scale whose
21
21
  * values grow upward.
22
+ *
23
+ * TODO(designer): the sets draw no go-to range shorter than the pill and its
24
+ * two tip insets, 16 px. The code keeps the pill's round ends down to 8 px
25
+ * so a short range on a small tank stays marked, and drops the band below
26
+ * that. The ring drops a range of 16 or less.
22
27
  */
23
28
  function bandPath(o, advice) {
24
29
  const t = o.thickness ?? 8;
@@ -29,13 +34,14 @@ function bandPath(o, advice) {
29
34
  const capLo = ascending ? caps.start : caps.end;
30
35
  const capHi = ascending ? caps.end : caps.start;
31
36
  const u = o.unitsPerPx ?? 1;
32
- const inset = 4 * u;
33
- const edgeLo = capLo === AdviceCap.pill ? lo + inset : lo;
34
- const edgeHi = capHi === AdviceCap.pill ? hi - inset : hi;
35
37
  const radius = (cap) => cap === AdviceCap.pill ? t / 2 : cap === AdviceCap.square ? 2 * u : 0;
36
38
  const rLo = radius(capLo);
37
39
  const rHi = radius(capHi);
38
- if (edgeHi - edgeLo < rLo + rHi) return null;
40
+ if (hi - lo < rLo + rHi) return null;
41
+ const pills = Number(capLo === AdviceCap.pill) + Number(capHi === AdviceCap.pill);
42
+ const inset = pills ? Math.min(4 * u, (hi - lo - rLo - rHi) / pills) : 0;
43
+ const edgeLo = capLo === AdviceCap.pill ? lo + inset : lo;
44
+ const edgeHi = capHi === AdviceCap.pill ? hi - inset : hi;
39
45
  const p0 = o.perpStart;
40
46
  const p1 = o.perpStart + t;
41
47
  const v = o.vertical;
@@ -1 +1 @@
1
- {"version":3,"file":"advice-linear.js","names":[],"sources":["../../src/svghelpers/advice-linear.ts"],"sourcesContent":["/**\n * The linear advice renderer, shared by the external scale, the thruster\n * column and the linear instrument scales: a band along a main axis at a\n * fixed perpendicular offset, a point marker on the band centreline, and the\n * area between the limit lines across a bar. What a band looks like comes\n * from `advice.ts`; the caller maps its values to main-axis coordinates and\n * says where the band sits.\n *\n * @module\n */\n\nimport {nothing, svg, type SVGTemplateResult} from 'lit';\nimport {\n ADVICE_ALERT_CORNER_RADIUS,\n ADVICE_AREA_DASH,\n ADVICE_BAND_THICKNESS,\n ADVICE_CAP_INSET,\n ADVICE_POINT_DOT_DIAMETER,\n ADVICE_POINT_TICK,\n AdviceCap,\n ADVICE_STRIPE,\n AdviceCategory,\n AdviceState,\n adviceCaps,\n adviceStyle,\n asResolvedAdvice,\n isGoToCategory,\n type AdviceInput,\n type ResolvedAdvice,\n ADVICE_ICON_SIZE_LINEAR,\n} from './advice.js';\nimport {dotPattern, hairlinePattern, stripePattern} from './advice-patterns.js';\nimport {renderAdviceIcon} from './advice-icons.js';\n\n/** Where a band sits: its range along the main axis and its near edge across it. */\nexport interface LinearAdviceBandOptions {\n /** The main axis is y (a vertical scale) rather than x. */\n vertical: boolean;\n /** Main-axis coordinate of the advice's `min`. */\n mainStart: number;\n /** Main-axis coordinate of the advice's `max`. */\n mainEnd: number;\n /** The band's edge with the lower perpendicular coordinate; it extends `thickness` from there. */\n perpStart: number;\n thickness?: number;\n advice: AdviceInput | ResolvedAdvice;\n /** Unique in the document; only a hatched band uses it. */\n maskId: string;\n /** The band is drawn under a reflection, so the hatch is mirrored back. */\n mirrorPattern?: boolean;\n /**\n * ViewBox units per CSS pixel when the band is pixel-fixed inside a scaled\n * drawing: the hatch tile is enlarged by it so the stripes keep their pitch.\n */\n unitsPerPx?: number;\n}\n\nconst point = (vertical: boolean, main: number, perp: number) =>\n vertical ? `${perp} ${main}` : `${main} ${perp}`;\n\n/**\n * The band outline, one cap per end. The cap at the lower main-axis\n * coordinate is the advice's start cap when `mainStart <= mainEnd`, as on a\n * horizontal scale, and its end cap otherwise, as on a vertical scale whose\n * values grow upward.\n */\nfunction bandPath(o: LinearAdviceBandOptions, advice: ResolvedAdvice) {\n const t = o.thickness ?? ADVICE_BAND_THICKNESS;\n const caps = adviceCaps(advice);\n const ascending = o.mainStart <= o.mainEnd;\n const lo = Math.min(o.mainStart, o.mainEnd);\n const hi = Math.max(o.mainStart, o.mainEnd);\n const capLo = ascending ? caps.start : caps.end;\n const capHi = ascending ? caps.end : caps.start;\n // The caps are pixel geometry like the band: a scaled drawing holds them\n // in the band's own units.\n const u = o.unitsPerPx ?? 1;\n const inset = ADVICE_CAP_INSET * u;\n const edgeLo = capLo === AdviceCap.pill ? lo + inset : lo;\n const edgeHi = capHi === AdviceCap.pill ? hi - inset : hi;\n const radius = (cap: AdviceCap) =>\n cap === AdviceCap.pill\n ? t / 2\n : cap === AdviceCap.square\n ? ADVICE_ALERT_CORNER_RADIUS * u\n : 0;\n const rLo = radius(capLo);\n const rHi = radius(capHi);\n if (edgeHi - edgeLo < rLo + rHi) return null;\n const p0 = o.perpStart;\n const p1 = o.perpStart + t;\n const v = o.vertical;\n const sw = v ? 0 : 1;\n const P = (main: number, perp: number) => point(v, main, perp);\n const cap = (\n main: number,\n r: number,\n c: AdviceCap,\n from: number,\n to: number,\n dir: 1 | -1\n ) => {\n // `dir` is +1 at the high end, -1 at the low end; the cap bulges that way.\n if (c === AdviceCap.pill) {\n return `A ${r} ${r} 0 0 ${sw} ${P(main - dir * r, to)}`;\n }\n if (c === AdviceCap.square) {\n const inward = from < to ? 1 : -1;\n return `A ${r} ${r} 0 0 ${sw} ${P(main, from + inward * r)} L ${P(main, to - inward * r)} A ${r} ${r} 0 0 ${sw} ${P(main - dir * r, to)}`;\n }\n return `L ${P(main, from)} L ${P(main, to)}`;\n };\n return [\n `M ${P(edgeLo + rLo, p0)}`,\n `L ${P(edgeHi - rHi, p0)}`,\n cap(edgeHi, rHi, capHi, p0, p1, 1),\n `L ${P(edgeLo + rLo, p1)}`,\n cap(edgeLo, rLo, capLo, p1, p0, -1),\n 'Z',\n ].join(' ');\n}\n\n/** One advice band. `nothing` when the range is too short for its caps. */\nexport function renderLinearAdviceBand(\n o: LinearAdviceBandOptions\n): SVGTemplateResult | typeof nothing {\n const advice = asResolvedAdvice(o.advice);\n const style = adviceStyle(advice.category, advice.state);\n const d = bandPath(o, advice);\n if (d === null) return nothing;\n if (style.pattern === 'none') {\n return svg`<path class=\"advice-band\" d=${d} fill=${style.fill} stroke=${style.stroke} stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`;\n }\n const t = o.thickness ?? ADVICE_BAND_THICKNESS;\n const lo = Math.min(o.mainStart, o.mainEnd);\n const hi = Math.max(o.mainStart, o.mainEnd);\n const patternId = `${o.maskId}-pattern`;\n const mirrored = o.mirrorPattern ?? false;\n const unitsPerPx = o.unitsPerPx ?? 1;\n const pattern =\n style.pattern === 'hairline'\n ? hairlinePattern(patternId, style.patternColor, mirrored, unitsPerPx)\n : stripePattern(\n patternId,\n style.patternColor,\n ADVICE_STRIPE.width,\n mirrored,\n unitsPerPx\n );\n const cover = o.vertical\n ? svg`<rect x=${o.perpStart} y=${lo} width=${t} height=${hi - lo} fill=${style.fill}/><rect x=${o.perpStart} y=${lo} width=${t} height=${hi - lo} fill=\"url(#${patternId})\"/>`\n : svg`<rect x=${lo} y=${o.perpStart} width=${hi - lo} height=${t} fill=${style.fill}/><rect x=${lo} y=${o.perpStart} width=${hi - lo} height=${t} fill=\"url(#${patternId})\"/>`;\n return svg`\n <defs>\n ${pattern}\n <mask id=${o.maskId} maskUnits=\"userSpaceOnUse\" x=\"-4096\" y=\"-4096\" width=\"8192\" height=\"8192\">\n <path d=${d} fill=\"white\"/>\n </mask>\n </defs>\n <g mask=\"url(#${o.maskId})\">${cover}</g>\n <path class=\"advice-band\" d=${d} fill=\"none\" stroke=${style.stroke} stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`;\n}\n\n/** Where a point marker sits: on the band centreline at its value. */\nexport interface LinearAdvicePointOptions {\n vertical: boolean;\n /** Main-axis coordinate of the advice's `value`. */\n main: number;\n /** Perpendicular coordinate of the band centreline. */\n perpCenter: number;\n advice: AdviceInput | ResolvedAdvice;\n /** ViewBox units per CSS pixel when the marker is pixel-fixed inside a scaled drawing. */\n unitsPerPx?: number;\n}\n\n/**\n * A point advice: a dot for a go-to category, a thick tick across the band\n * for a no-go one. The caution point takes the tick-mark primary colour while\n * triggered, never the caution yellow.\n */\nexport function renderLinearAdvicePoint(\n o: LinearAdvicePointOptions\n): SVGTemplateResult {\n const advice = asResolvedAdvice(o.advice);\n const style = adviceStyle(advice.category, advice.state);\n const cx = o.vertical ? o.perpCenter : o.main;\n const cy = o.vertical ? o.main : o.perpCenter;\n const u = o.unitsPerPx ?? 1;\n if (isGoToCategory(advice.category)) {\n return svg`<circle cx=${cx} cy=${cy} r=${(ADVICE_POINT_DOT_DIAMETER / 2) * u} fill=${style.fill} stroke=${style.stroke} stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`;\n }\n const grey =\n advice.category === AdviceCategory.caution\n ? advice.state === AdviceState.triggered\n ? 'var(--instrument-tick-mark-primary-color)'\n : style.stroke\n : undefined;\n const {length, thickness, radius} = ADVICE_POINT_TICK;\n const w = (o.vertical ? length : thickness) * u;\n const h = (o.vertical ? thickness : length) * u;\n return svg`<rect x=${cx - w / 2} y=${cy - h / 2} width=${w} height=${h} rx=${radius * u} fill=${grey ?? style.fill} stroke=${grey ?? style.stroke} stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`;\n}\n\n/** Where an area sits: the advice's range along the main axis, the bar across it. */\nexport interface LinearAdviceAreaOptions {\n vertical: boolean;\n mainStart: number;\n mainEnd: number;\n perpStart: number;\n perpEnd: number;\n advice: AdviceInput | ResolvedAdvice;\n /** Unique in the document; the pattern tile's id. */\n patternId: string;\n}\n\n/**\n * The area layer across a bar: the category's tint or pattern between the\n * limits and the limit lines in the category's dash; for a point one line.\n */\nexport function renderLinearAdviceArea(\n o: LinearAdviceAreaOptions\n): SVGTemplateResult {\n const advice = asResolvedAdvice(o.advice);\n const style = adviceStyle(advice.category, advice.state);\n const v = o.vertical;\n const dash =\n style.areaOutline === 'dotted'\n ? ADVICE_AREA_DASH.dotted\n : style.areaOutline === 'dashed'\n ? ADVICE_AREA_DASH.dashed\n : undefined;\n const line = (main: number) => {\n const d = `M ${point(v, main, o.perpStart)} L ${point(v, main, o.perpEnd)}`;\n return svg`\n ${\n dash\n ? svg`<path d=${d} fill=\"none\" stroke=\"var(--instrument-frame-primary-color)\" stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`\n : nothing\n }\n <path d=${d} fill=\"none\" stroke=${style.stroke} stroke-width=\"1\" stroke-dasharray=${dash ?? nothing} vector-effect=\"non-scaling-stroke\"/>`;\n };\n if (advice.point) return line(o.mainStart);\n const lo = Math.min(o.mainStart, o.mainEnd);\n const hi = Math.max(o.mainStart, o.mainEnd);\n const pLo = Math.min(o.perpStart, o.perpEnd);\n const pHi = Math.max(o.perpStart, o.perpEnd);\n const rect = (fill: string) =>\n v\n ? svg`<rect x=${pLo} y=${lo} width=${pHi - pLo} height=${hi - lo} fill=${fill}/>`\n : svg`<rect x=${lo} y=${pLo} width=${hi - lo} height=${pHi - pLo} fill=${fill}/>`;\n const pattern =\n style.areaPattern === 'dots'\n ? dotPattern(o.patternId, style.stroke)\n : style.areaPattern === 'hairline'\n ? hairlinePattern(o.patternId, style.stroke)\n : nothing;\n return svg`\n ${pattern}\n ${style.areaFill === 'none' ? nothing : rect(style.areaFill)}\n ${pattern === nothing ? nothing : rect(`url(#${o.patternId})`)}\n ${line(o.mainStart)} ${line(o.mainEnd)}`;\n}\n\n/** Where an icon sits: the advice's midpoint along the main axis, the label column across it. */\nexport interface LinearAdviceIconOptions {\n vertical: boolean;\n /** Main-axis coordinates of the advice's `min` and `max`; a point gives the same value twice. */\n mainStart: number;\n mainEnd: number;\n /** Perpendicular coordinate of the icon box's centre. */\n perpCenter: number;\n advice: AdviceInput | ResolvedAdvice;\n size?: number;\n /** Unique in the document; the glyph's own ids are prefixed with it. */\n id?: string;\n}\n\n/** The category's icon beside the band, centred on the range, in the responsive size. */\nexport function renderLinearAdviceIcon(\n o: LinearAdviceIconOptions\n): SVGTemplateResult {\n const advice = asResolvedAdvice(o.advice);\n const main = (o.mainStart + o.mainEnd) / 2;\n return renderAdviceIcon({\n category: advice.category,\n state: advice.state,\n x: o.vertical ? o.perpCenter : main,\n y: o.vertical ? main : o.perpCenter,\n size: o.size ?? ADVICE_ICON_SIZE_LINEAR,\n id: o.id,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyDA,IAAM,SAAS,UAAmB,MAAc,SAC9C,WAAW,GAAG,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG;;;;;;;AAQ5C,SAAS,SAAS,GAA4B,QAAwB;CACpE,MAAM,IAAI,EAAE,aAAA;CACZ,MA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WAAW,OAAO,EAAE;EACzB,MAAM,EAAE,QAAA;EACR,IAAI,EAAE;CACR,CAAC;AACH"}
1
+ {"version":3,"file":"advice-linear.js","names":[],"sources":["../../src/svghelpers/advice-linear.ts"],"sourcesContent":["/**\n * The linear advice renderer, shared by the external scale, the thruster\n * column and the linear instrument scales: a band along a main axis at a\n * fixed perpendicular offset, a point marker on the band centreline, and the\n * area between the limit lines across a bar. What a band looks like comes\n * from `advice.ts`; the caller maps its values to main-axis coordinates and\n * says where the band sits.\n *\n * @module\n */\n\nimport {nothing, svg, type SVGTemplateResult} from 'lit';\nimport {\n ADVICE_ALERT_CORNER_RADIUS,\n ADVICE_AREA_DASH,\n ADVICE_BAND_THICKNESS,\n ADVICE_CAP_INSET,\n ADVICE_POINT_DOT_DIAMETER,\n ADVICE_POINT_TICK,\n AdviceCap,\n ADVICE_STRIPE,\n AdviceCategory,\n AdviceState,\n adviceCaps,\n adviceStyle,\n asResolvedAdvice,\n isGoToCategory,\n type AdviceInput,\n type ResolvedAdvice,\n ADVICE_ICON_SIZE_LINEAR,\n} from './advice.js';\nimport {dotPattern, hairlinePattern, stripePattern} from './advice-patterns.js';\nimport {renderAdviceIcon} from './advice-icons.js';\n\n/** Where a band sits: its range along the main axis and its near edge across it. */\nexport interface LinearAdviceBandOptions {\n /** The main axis is y (a vertical scale) rather than x. */\n vertical: boolean;\n /** Main-axis coordinate of the advice's `min`. */\n mainStart: number;\n /** Main-axis coordinate of the advice's `max`. */\n mainEnd: number;\n /** The band's edge with the lower perpendicular coordinate; it extends `thickness` from there. */\n perpStart: number;\n thickness?: number;\n advice: AdviceInput | ResolvedAdvice;\n /** Unique in the document; only a hatched band uses it. */\n maskId: string;\n /** The band is drawn under a reflection, so the hatch is mirrored back. */\n mirrorPattern?: boolean;\n /**\n * ViewBox units per CSS pixel when the band is pixel-fixed inside a scaled\n * drawing: the hatch tile is enlarged by it so the stripes keep their pitch.\n */\n unitsPerPx?: number;\n}\n\nconst point = (vertical: boolean, main: number, perp: number) =>\n vertical ? `${perp} ${main}` : `${main} ${perp}`;\n\n/**\n * The band outline, one cap per end. The cap at the lower main-axis\n * coordinate is the advice's start cap when `mainStart <= mainEnd`, as on a\n * horizontal scale, and its end cap otherwise, as on a vertical scale whose\n * values grow upward.\n *\n * TODO(designer): the sets draw no go-to range shorter than the pill and its\n * two tip insets, 16 px. The code keeps the pill's round ends down to 8 px\n * so a short range on a small tank stays marked, and drops the band below\n * that. The ring drops a range of 16 or less.\n */\nfunction bandPath(o: LinearAdviceBandOptions, advice: ResolvedAdvice) {\n const t = o.thickness ?? ADVICE_BAND_THICKNESS;\n const caps = adviceCaps(advice);\n const ascending = o.mainStart <= o.mainEnd;\n const lo = Math.min(o.mainStart, o.mainEnd);\n const hi = Math.max(o.mainStart, o.mainEnd);\n const capLo = ascending ? caps.start : caps.end;\n const capHi = ascending ? caps.end : caps.start;\n // The caps are pixel geometry like the band: a scaled drawing holds them\n // in the band's own units.\n const u = o.unitsPerPx ?? 1;\n const radius = (cap: AdviceCap) =>\n cap === AdviceCap.pill\n ? t / 2\n : cap === AdviceCap.square\n ? ADVICE_ALERT_CORNER_RADIUS * u\n : 0;\n const rLo = radius(capLo);\n const rHi = radius(capHi);\n if (hi - lo < rLo + rHi) return null;\n // The pill tips give way before the pill: a range too short for both\n // insets shares what is left beyond the caps between its pill ends, so a\n // pixel-fixed pill in a small drawing still marks a short range.\n const pills =\n Number(capLo === AdviceCap.pill) + Number(capHi === AdviceCap.pill);\n const inset = pills\n ? Math.min(ADVICE_CAP_INSET * u, (hi - lo - rLo - rHi) / pills)\n : 0;\n const edgeLo = capLo === AdviceCap.pill ? lo + inset : lo;\n const edgeHi = capHi === AdviceCap.pill ? hi - inset : hi;\n const p0 = o.perpStart;\n const p1 = o.perpStart + t;\n const v = o.vertical;\n const sw = v ? 0 : 1;\n const P = (main: number, perp: number) => point(v, main, perp);\n const cap = (\n main: number,\n r: number,\n c: AdviceCap,\n from: number,\n to: number,\n dir: 1 | -1\n ) => {\n // `dir` is +1 at the high end, -1 at the low end; the cap bulges that way.\n if (c === AdviceCap.pill) {\n return `A ${r} ${r} 0 0 ${sw} ${P(main - dir * r, to)}`;\n }\n if (c === AdviceCap.square) {\n const inward = from < to ? 1 : -1;\n return `A ${r} ${r} 0 0 ${sw} ${P(main, from + inward * r)} L ${P(main, to - inward * r)} A ${r} ${r} 0 0 ${sw} ${P(main - dir * r, to)}`;\n }\n return `L ${P(main, from)} L ${P(main, to)}`;\n };\n return [\n `M ${P(edgeLo + rLo, p0)}`,\n `L ${P(edgeHi - rHi, p0)}`,\n cap(edgeHi, rHi, capHi, p0, p1, 1),\n `L ${P(edgeLo + rLo, p1)}`,\n cap(edgeLo, rLo, capLo, p1, p0, -1),\n 'Z',\n ].join(' ');\n}\n\n/** One advice band. `nothing` when the range is too short for its caps. */\nexport function renderLinearAdviceBand(\n o: LinearAdviceBandOptions\n): SVGTemplateResult | typeof nothing {\n const advice = asResolvedAdvice(o.advice);\n const style = adviceStyle(advice.category, advice.state);\n const d = bandPath(o, advice);\n if (d === null) return nothing;\n if (style.pattern === 'none') {\n return svg`<path class=\"advice-band\" d=${d} fill=${style.fill} stroke=${style.stroke} stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`;\n }\n const t = o.thickness ?? ADVICE_BAND_THICKNESS;\n const lo = Math.min(o.mainStart, o.mainEnd);\n const hi = Math.max(o.mainStart, o.mainEnd);\n const patternId = `${o.maskId}-pattern`;\n const mirrored = o.mirrorPattern ?? false;\n const unitsPerPx = o.unitsPerPx ?? 1;\n const pattern =\n style.pattern === 'hairline'\n ? hairlinePattern(patternId, style.patternColor, mirrored, unitsPerPx)\n : stripePattern(\n patternId,\n style.patternColor,\n ADVICE_STRIPE.width,\n mirrored,\n unitsPerPx\n );\n const cover = o.vertical\n ? svg`<rect x=${o.perpStart} y=${lo} width=${t} height=${hi - lo} fill=${style.fill}/><rect x=${o.perpStart} y=${lo} width=${t} height=${hi - lo} fill=\"url(#${patternId})\"/>`\n : svg`<rect x=${lo} y=${o.perpStart} width=${hi - lo} height=${t} fill=${style.fill}/><rect x=${lo} y=${o.perpStart} width=${hi - lo} height=${t} fill=\"url(#${patternId})\"/>`;\n return svg`\n <defs>\n ${pattern}\n <mask id=${o.maskId} maskUnits=\"userSpaceOnUse\" x=\"-4096\" y=\"-4096\" width=\"8192\" height=\"8192\">\n <path d=${d} fill=\"white\"/>\n </mask>\n </defs>\n <g mask=\"url(#${o.maskId})\">${cover}</g>\n <path class=\"advice-band\" d=${d} fill=\"none\" stroke=${style.stroke} stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`;\n}\n\n/** Where a point marker sits: on the band centreline at its value. */\nexport interface LinearAdvicePointOptions {\n vertical: boolean;\n /** Main-axis coordinate of the advice's `value`. */\n main: number;\n /** Perpendicular coordinate of the band centreline. */\n perpCenter: number;\n advice: AdviceInput | ResolvedAdvice;\n /** ViewBox units per CSS pixel when the marker is pixel-fixed inside a scaled drawing. */\n unitsPerPx?: number;\n}\n\n/**\n * A point advice: a dot for a go-to category, a thick tick across the band\n * for a no-go one. The caution point takes the tick-mark primary colour while\n * triggered, never the caution yellow.\n */\nexport function renderLinearAdvicePoint(\n o: LinearAdvicePointOptions\n): SVGTemplateResult {\n const advice = asResolvedAdvice(o.advice);\n const style = adviceStyle(advice.category, advice.state);\n const cx = o.vertical ? o.perpCenter : o.main;\n const cy = o.vertical ? o.main : o.perpCenter;\n const u = o.unitsPerPx ?? 1;\n if (isGoToCategory(advice.category)) {\n return svg`<circle cx=${cx} cy=${cy} r=${(ADVICE_POINT_DOT_DIAMETER / 2) * u} fill=${style.fill} stroke=${style.stroke} stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`;\n }\n const grey =\n advice.category === AdviceCategory.caution\n ? advice.state === AdviceState.triggered\n ? 'var(--instrument-tick-mark-primary-color)'\n : style.stroke\n : undefined;\n const {length, thickness, radius} = ADVICE_POINT_TICK;\n const w = (o.vertical ? length : thickness) * u;\n const h = (o.vertical ? thickness : length) * u;\n return svg`<rect x=${cx - w / 2} y=${cy - h / 2} width=${w} height=${h} rx=${radius * u} fill=${grey ?? style.fill} stroke=${grey ?? style.stroke} stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`;\n}\n\n/** Where an area sits: the advice's range along the main axis, the bar across it. */\nexport interface LinearAdviceAreaOptions {\n vertical: boolean;\n mainStart: number;\n mainEnd: number;\n perpStart: number;\n perpEnd: number;\n advice: AdviceInput | ResolvedAdvice;\n /** Unique in the document; the pattern tile's id. */\n patternId: string;\n}\n\n/**\n * The area layer across a bar: the category's tint or pattern between the\n * limits and the limit lines in the category's dash; for a point one line.\n */\nexport function renderLinearAdviceArea(\n o: LinearAdviceAreaOptions\n): SVGTemplateResult {\n const advice = asResolvedAdvice(o.advice);\n const style = adviceStyle(advice.category, advice.state);\n const v = o.vertical;\n const dash =\n style.areaOutline === 'dotted'\n ? ADVICE_AREA_DASH.dotted\n : style.areaOutline === 'dashed'\n ? ADVICE_AREA_DASH.dashed\n : undefined;\n const line = (main: number) => {\n const d = `M ${point(v, main, o.perpStart)} L ${point(v, main, o.perpEnd)}`;\n return svg`\n ${\n dash\n ? svg`<path d=${d} fill=\"none\" stroke=\"var(--instrument-frame-primary-color)\" stroke-width=\"1\" vector-effect=\"non-scaling-stroke\"/>`\n : nothing\n }\n <path d=${d} fill=\"none\" stroke=${style.stroke} stroke-width=\"1\" stroke-dasharray=${dash ?? nothing} vector-effect=\"non-scaling-stroke\"/>`;\n };\n if (advice.point) return line(o.mainStart);\n const lo = Math.min(o.mainStart, o.mainEnd);\n const hi = Math.max(o.mainStart, o.mainEnd);\n const pLo = Math.min(o.perpStart, o.perpEnd);\n const pHi = Math.max(o.perpStart, o.perpEnd);\n const rect = (fill: string) =>\n v\n ? svg`<rect x=${pLo} y=${lo} width=${pHi - pLo} height=${hi - lo} fill=${fill}/>`\n : svg`<rect x=${lo} y=${pLo} width=${hi - lo} height=${pHi - pLo} fill=${fill}/>`;\n const pattern =\n style.areaPattern === 'dots'\n ? dotPattern(o.patternId, style.stroke)\n : style.areaPattern === 'hairline'\n ? hairlinePattern(o.patternId, style.stroke)\n : nothing;\n return svg`\n ${pattern}\n ${style.areaFill === 'none' ? nothing : rect(style.areaFill)}\n ${pattern === nothing ? nothing : rect(`url(#${o.patternId})`)}\n ${line(o.mainStart)} ${line(o.mainEnd)}`;\n}\n\n/** Where an icon sits: the advice's midpoint along the main axis, the label column across it. */\nexport interface LinearAdviceIconOptions {\n vertical: boolean;\n /** Main-axis coordinates of the advice's `min` and `max`; a point gives the same value twice. */\n mainStart: number;\n mainEnd: number;\n /** Perpendicular coordinate of the icon box's centre. */\n perpCenter: number;\n advice: AdviceInput | ResolvedAdvice;\n size?: number;\n /** Unique in the document; the glyph's own ids are prefixed with it. */\n id?: string;\n}\n\n/** The category's icon beside the band, centred on the range, in the responsive size. */\nexport function renderLinearAdviceIcon(\n o: LinearAdviceIconOptions\n): SVGTemplateResult {\n const advice = asResolvedAdvice(o.advice);\n const main = (o.mainStart + o.mainEnd) / 2;\n return renderAdviceIcon({\n category: advice.category,\n state: advice.state,\n x: o.vertical ? o.perpCenter : main,\n y: o.vertical ? main : o.perpCenter,\n size: o.size ?? ADVICE_ICON_SIZE_LINEAR,\n id: o.id,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyDA,IAAM,SAAS,UAAmB,MAAc,SAC9C,WAAW,GAAG,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG;;;;;;;;;;;;AAa5C,SAAS,SAAS,GAA4B,QAAwB;CACpE,MAAM,IAAI,EAAE,aAAA;CACZ,MAAM,OAAO,WAAW,MAAM;CAC9B,MAAM,YAAY,EAAE,aAAa,EAAE;CACnC,MAAM,KAAK,KAAK,IAAI,EAAE,WAAW,EAAE,OAAO;CAC1C,MAAM,KAAK,KAAK,IAAI,EAAE,WAAW,EAAE,OAAO;CAC1C,MAAM,QAAQ,YAAY,KAAK,QAAQ,KAAK;CAC5C,MAAM,QAAQ,YAA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Percent(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