@oicl/openbridge-webcomponents 0.0.15-dev-20240916083108 → 0.0.15-dev-20240923184809

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. package/.storybook/main.ts +8 -0
  2. package/.storybook/preview.ts +2 -0
  3. package/__snapshots__/building-blocks-watch--advice.png +0 -0
  4. package/__snapshots__/building-blocks-watch-flat--primary.png +0 -0
  5. package/__snapshots__/navigation-instruments-azimuth-thruster--in-command-at-setpoint-disable-auto-setpoint.png +0 -0
  6. package/__snapshots__/navigation-instruments-azimuth-thruster--in-command-at-setpoint.png +0 -0
  7. package/__snapshots__/navigation-instruments-azimuth-thruster--in-command.png +0 -0
  8. package/__snapshots__/navigation-instruments-azimuth-thruster--pod.png +0 -0
  9. package/__snapshots__/navigation-instruments-azimuth-thruster--single-direction-with-propeller.png +0 -0
  10. package/__snapshots__/navigation-instruments-azimuth-thruster--single-direction.png +0 -0
  11. package/__snapshots__/navigation-instruments-azimuth-thruster-labeled--large.png +0 -0
  12. package/__snapshots__/navigation-instruments-azimuth-thruster-labeled--medium.png +0 -0
  13. package/__snapshots__/navigation-instruments-azimuth-thruster-labeled--no-command.png +0 -0
  14. package/__snapshots__/navigation-instruments-compass--primary.png +0 -0
  15. package/__snapshots__/navigation-instruments-compass-flat--primary.png +0 -0
  16. package/__snapshots__/navigation-instruments-compass-flat--with-fov-indicator.png +0 -0
  17. package/__snapshots__/navigation-instruments-main-engine--active.png +0 -0
  18. package/__snapshots__/navigation-instruments-main-engine--in-command.png +0 -0
  19. package/__snapshots__/navigation-instruments-main-engine--off.png +0 -0
  20. package/__snapshots__/navigation-instruments-thruster--tunnel.png +0 -0
  21. package/custom-elements.json +2184 -660
  22. package/dist/navigation-instruments/azimuth-thruster/azimuth-thruster.d.ts.map +1 -1
  23. package/dist/navigation-instruments/azimuth-thruster/azimuth-thruster.js +2 -1
  24. package/dist/navigation-instruments/azimuth-thruster/azimuth-thruster.js.map +1 -1
  25. package/dist/navigation-instruments/compass/arrow.d.ts +7 -0
  26. package/dist/navigation-instruments/compass/arrow.d.ts.map +1 -0
  27. package/dist/navigation-instruments/compass/arrow.js +59 -0
  28. package/dist/navigation-instruments/compass/arrow.js.map +1 -0
  29. package/dist/navigation-instruments/compass/compass.d.ts +23 -0
  30. package/dist/navigation-instruments/compass/compass.d.ts.map +1 -0
  31. package/dist/navigation-instruments/compass/compass.js +139 -0
  32. package/dist/navigation-instruments/compass/compass.js.map +1 -0
  33. package/dist/navigation-instruments/compass/radial-tickmark.d.ts +4 -0
  34. package/dist/navigation-instruments/compass/radial-tickmark.d.ts.map +1 -0
  35. package/dist/navigation-instruments/compass/radial-tickmark.js +69 -0
  36. package/dist/navigation-instruments/compass/radial-tickmark.js.map +1 -0
  37. package/dist/navigation-instruments/compass-flat/compass-flat.css.js +29 -0
  38. package/dist/navigation-instruments/compass-flat/compass-flat.css.js.map +1 -0
  39. package/dist/navigation-instruments/compass-flat/compass-flat.d.ts +45 -0
  40. package/dist/navigation-instruments/compass-flat/compass-flat.d.ts.map +1 -0
  41. package/dist/navigation-instruments/compass-flat/compass-flat.js +223 -0
  42. package/dist/navigation-instruments/compass-flat/compass-flat.js.map +1 -0
  43. package/dist/navigation-instruments/main-engine/main-engine.css.js +22 -0
  44. package/dist/navigation-instruments/main-engine/main-engine.css.js.map +1 -0
  45. package/dist/navigation-instruments/main-engine/main-engine.d.ts +29 -0
  46. package/dist/navigation-instruments/main-engine/main-engine.d.ts.map +1 -0
  47. package/dist/navigation-instruments/main-engine/main-engine.js +196 -0
  48. package/dist/navigation-instruments/main-engine/main-engine.js.map +1 -0
  49. package/dist/navigation-instruments/thruster/advice.d.ts.map +1 -1
  50. package/dist/navigation-instruments/thruster/advice.js +9 -5
  51. package/dist/navigation-instruments/thruster/advice.js.map +1 -1
  52. package/dist/navigation-instruments/thruster/thruster.d.ts +54 -1
  53. package/dist/navigation-instruments/thruster/thruster.d.ts.map +1 -1
  54. package/dist/navigation-instruments/thruster/thruster.js +163 -99
  55. package/dist/navigation-instruments/thruster/thruster.js.map +1 -1
  56. package/dist/navigation-instruments/watch/advice.js +1 -1
  57. package/dist/navigation-instruments/watch/advice.js.map +1 -1
  58. package/dist/navigation-instruments/watch/label.d.ts +3 -0
  59. package/dist/navigation-instruments/watch/label.d.ts.map +1 -0
  60. package/dist/navigation-instruments/watch/label.js +68 -0
  61. package/dist/navigation-instruments/watch/label.js.map +1 -0
  62. package/dist/navigation-instruments/watch/watch.css.js +15 -14
  63. package/dist/navigation-instruments/watch/watch.css.js.map +1 -1
  64. package/dist/navigation-instruments/watch/watch.d.ts +3 -0
  65. package/dist/navigation-instruments/watch/watch.d.ts.map +1 -1
  66. package/dist/navigation-instruments/watch/watch.js +34 -1
  67. package/dist/navigation-instruments/watch/watch.js.map +1 -1
  68. package/dist/navigation-instruments/watch-flat/tickmark-flat.d.ts +20 -0
  69. package/dist/navigation-instruments/watch-flat/tickmark-flat.d.ts.map +1 -0
  70. package/dist/navigation-instruments/watch-flat/tickmark-flat.js +53 -0
  71. package/dist/navigation-instruments/watch-flat/tickmark-flat.js.map +1 -0
  72. package/dist/navigation-instruments/watch-flat/watch-flat.css.js +32 -0
  73. package/dist/navigation-instruments/watch-flat/watch-flat.css.js.map +1 -0
  74. package/dist/navigation-instruments/watch-flat/watch-flat.d.ts +29 -0
  75. package/dist/navigation-instruments/watch-flat/watch-flat.d.ts.map +1 -0
  76. package/dist/navigation-instruments/watch-flat/watch-flat.js +184 -0
  77. package/dist/navigation-instruments/watch-flat/watch-flat.js.map +1 -0
  78. package/dist/svghelpers/rectangular.d.ts +1 -0
  79. package/dist/svghelpers/rectangular.d.ts.map +1 -1
  80. package/dist/svghelpers/rectangular.js +3 -2
  81. package/dist/svghelpers/rectangular.js.map +1 -1
  82. package/package.json +16 -11
  83. package/src/navigation-instruments/azimuth-thruster/azimuth-thruster.ts +1 -0
  84. package/src/navigation-instruments/compass/arrow.ts +61 -0
  85. package/src/navigation-instruments/compass/compass.stories.ts +37 -0
  86. package/src/navigation-instruments/compass/compass.ts +132 -0
  87. package/src/navigation-instruments/compass/radial-tickmark.ts +77 -0
  88. package/src/navigation-instruments/compass-flat/compass-flat.css +23 -0
  89. package/src/navigation-instruments/compass-flat/compass-flat.stories.ts +35 -0
  90. package/src/navigation-instruments/compass-flat/compass-flat.ts +221 -0
  91. package/src/navigation-instruments/main-engine/main-engine.css +17 -0
  92. package/src/navigation-instruments/main-engine/main-engine.stories.ts +54 -0
  93. package/src/navigation-instruments/main-engine/main-engine.ts +160 -0
  94. package/src/navigation-instruments/thruster/advice.ts +9 -5
  95. package/src/navigation-instruments/thruster/thruster.stories.ts +1 -0
  96. package/src/navigation-instruments/thruster/thruster.ts +205 -113
  97. package/src/navigation-instruments/watch/advice.ts +1 -1
  98. package/src/navigation-instruments/watch/label.ts +69 -0
  99. package/src/navigation-instruments/watch/watch.css +7 -7
  100. package/src/navigation-instruments/watch/watch.ts +30 -1
  101. package/src/navigation-instruments/watch-flat/tickmark-flat.ts +62 -0
  102. package/src/navigation-instruments/watch-flat/watch-flat.css +19 -0
  103. package/src/navigation-instruments/watch-flat/watch-flat.stories.ts +17 -0
  104. package/src/navigation-instruments/watch-flat/watch-flat.ts +148 -0
  105. package/src/palettes/variables.css +1343 -1343
  106. package/src/svghelpers/rectangular.ts +6 -3
@@ -1,4 +1,4 @@
1
- import {LitElement, svg, html, css} from 'lit';
1
+ import {LitElement, svg, html, css, nothing} from 'lit';
2
2
  import {customElement, property} from 'lit/decorators.js';
3
3
  import {InstrumentState} from '../types';
4
4
  import {LinearAdvice, LinearAdviceRaw, renderAdvice} from './advice';
@@ -46,6 +46,7 @@ export class ObcThruster extends LitElement {
46
46
  singleDirectionHalfSize: this.singleDirectionHalfSize,
47
47
  topPropeller: this.topPropeller,
48
48
  bottomPropeller: this.bottomPropeller,
49
+ narrow: !this.tunnel,
49
50
  })}
50
51
  </div>`;
51
52
  }
@@ -63,11 +64,11 @@ export class ObcThruster extends LitElement {
63
64
  `;
64
65
  }
65
66
 
66
- function thrusterTop(
67
+ export function thrusterTop(
67
68
  height: number,
68
69
  value: number,
69
70
  colors: {box: string; container: string},
70
- hideTicks: boolean
71
+ options: {hideTicks: boolean; hideContainer: boolean}
71
72
  ) {
72
73
  const container = svg`
73
74
  <path transform="translate(0 -2)" d="M -44 0 v -${height - 8} a 8 8 0 0 1 8 -8 h 72 a 8 8 0 0 1 8 8 V 0 Z" fill=${colors.container} stroke="var(--instrument-frame-tertiary-color)" vector-effect="non-scaling-stroke"/>
@@ -78,7 +79,7 @@ function thrusterTop(
78
79
 
79
80
  const nTicks = 2;
80
81
  const delta = height / nTicks;
81
- if (!hideTicks) {
82
+ if (!options.hideTicks) {
82
83
  for (let i = 1; i < nTicks; i++) {
83
84
  tickmarks.push(
84
85
  svg`<line x1="-24" x2="-44" y1=${-i * delta - 2} y2=${
@@ -96,54 +97,86 @@ function thrusterTop(
96
97
  const barHeight = (height * value) / 100;
97
98
  const barY = -2 - barHeight;
98
99
  const bar = svg`<rect width="40" height=${barHeight} x="-20" y=${barY} fill=${colors.box} stroke=${colors.box} vector-effect="non-scaling-stroke"/>`;
99
-
100
- return [container, track, tickmarks, bar];
100
+ if (options.hideContainer) {
101
+ return [track, tickmarks, bar];
102
+ } else {
103
+ return [container, track, tickmarks, bar];
104
+ }
101
105
  }
102
106
 
103
- function thrusterTopSingleSided(
107
+ export function thrusterTopSingleSided(
104
108
  height: number,
105
109
  value: number,
106
110
  colors: {box: string; container: string},
107
- hideTicks: boolean,
108
- advice: LinearAdviceRaw[],
109
- flipAdicePattern: boolean = false
111
+ options: {
112
+ hideTicks: boolean;
113
+ flipAdicePattern: boolean;
114
+ hideContainer: boolean;
115
+ narrow: boolean;
116
+ },
117
+ advice: LinearAdviceRaw[]
110
118
  ) {
111
- const container = svg`
119
+ const container = options.narrow
120
+ ? svg`
112
121
  <path transform="translate(0 -2)" d="M -32 0 v -${height - 8} a 8 8 0 0 1 8 -8 h 48 a 8 8 0 0 1 8 8 V 0 Z" fill=${colors.container} stroke="var(--instrument-frame-tertiary-color)" vector-effect="non-scaling-stroke"/>
122
+ `
123
+ : svg`
124
+ <path transform="translate(0 -2)" d="M -40 0 v -${height - 8} a 8 8 0 0 1 8 -8 h 56 a 8 8 0 0 1 8 8 V 0 Z" fill=${colors.container} stroke="var(--instrument-frame-tertiary-color)" vector-effect="non-scaling-stroke"/>
113
125
  `;
114
- const track = svg`
126
+ const track = options.narrow
127
+ ? svg`
115
128
  <path transform="translate(0 -2)" d="M -32 0 v -${height - 8} a 8 8 0 0 1 8 -8 h 32 V 0 Z" fill="var(--instrument-frame-secondary-color)" stroke="var(--instrument-frame-tertiary-color)" vector-effect="non-scaling-stroke"/>
129
+ `
130
+ : svg`
131
+ <path transform="translate(0 -2)" d="M -40 0 v -${height - 8} a 8 8 0 0 1 8 -8 h 40 V 0 Z" fill="var(--instrument-frame-secondary-color)" stroke="var(--instrument-frame-tertiary-color)" vector-effect="non-scaling-stroke"/>
116
132
  `;
117
133
 
118
- const tickmarks = hideTicks
134
+ const tickmarks = options.hideTicks
119
135
  ? []
120
136
  : [singleSidedTickmark(height, 50, TickmarkStyle.hinted)];
121
137
 
122
138
  const barHeight = (height * value) / 100;
139
+ const barWidth = options.narrow ? 40 : 48;
140
+ const barX = options.narrow ? -32 : -40;
123
141
  const barY = -2 - barHeight;
124
- const maskId = flipAdicePattern ? 'thrusterBarMask1' : 'thrusterBarMask2';
125
- const bar = svg`
142
+ const maskId = options.flipAdicePattern
143
+ ? 'thrusterBarMask1'
144
+ : 'thrusterBarMask2';
145
+ // The mask is used to clip the bar to the container shape
146
+ const mask = options.hideContainer
147
+ ? nothing
148
+ : svg`
126
149
  <defs>
127
150
  <mask id=${maskId}>
128
- <path transform="translate(0 -2)" d="M -32 0 v -${height - 8} a 8 8 0 0 1 8 -8 h 48 a 8 8 0 0 1 8 8 V 0 Z" fill="white" stroke="white" vector-effect="non-scaling-stroke"/>
129
- </defs>
130
- <rect mask="url(#${maskId})" width="40" height=${barHeight} x="-32" y=${barY} fill=${colors.box} stroke=${colors.box} vector-effect="non-scaling-stroke"/>`;
151
+ <path transform="translate(0 -2)" d="M ${barX} 0 v -${height - 8} a 8 8 0 0 1 8 -8 h ${barWidth} V 0 Z" fill="white" stroke="white" vector-effect="non-scaling-stroke"/>
152
+ </defs>`;
153
+ const maskAttr = options.hideContainer ? '' : `mask="url(#${maskId})"`;
154
+ const bar = svg`
155
+ ${mask}
156
+ <rect ${maskAttr} width=${barWidth} height=${barHeight} x=${barX} y=${barY} fill=${colors.box} stroke=${colors.box} vector-effect="non-scaling-stroke"/>`;
131
157
  const advicesSvg = advice.map((a) =>
132
- renderAdvice(height, a, flipAdicePattern)
158
+ renderAdvice(height, a, options.flipAdicePattern)
133
159
  );
134
-
135
- return [container, track, tickmarks, bar, advicesSvg];
160
+ const all = [tickmarks, bar, advicesSvg];
161
+ if (!options.hideContainer) {
162
+ all.splice(0, 0, [container, track]);
163
+ }
164
+ if (!options.narrow) {
165
+ return svg`<g transform="translate(4 0)">${all}</g>`;
166
+ } else {
167
+ return all;
168
+ }
136
169
  }
137
170
 
138
- function thrusterBottom(
171
+ export function thrusterBottom(
139
172
  height: number,
140
173
  value: number,
141
174
  colors: {box: string; container: string},
142
- hideTicks: boolean
175
+ options: {hideTicks: boolean; hideContainer: boolean}
143
176
  ) {
144
177
  const container = svg`
145
178
  <g transform="rotate(180)">
146
- ${thrusterTop(height, value, colors, hideTicks)}
179
+ ${thrusterTop(height, value, colors, options)}
147
180
  </g>
148
181
  `;
149
182
  return container;
@@ -153,18 +186,23 @@ function thrusterBottomSingleSided(
153
186
  height: number,
154
187
  value: number,
155
188
  colors: {box: string; container: string},
156
- hideTicks: boolean,
157
- advices: LinearAdviceRaw[]
189
+ options: {
190
+ hideTicks: boolean;
191
+ flipAdicePattern: boolean;
192
+ hideContainer: boolean;
193
+ narrow: boolean;
194
+ },
195
+ advice: LinearAdviceRaw[]
158
196
  ) {
159
197
  const container = svg`
160
198
  <g transform="rotate(180) scale(-1,1)">
161
- ${thrusterTopSingleSided(height, value, colors, hideTicks, advices, true)}
199
+ ${thrusterTopSingleSided(height, value, colors, {hideTicks: options.hideTicks, flipAdicePattern: options.flipAdicePattern, hideContainer: options.hideContainer, narrow: options.narrow}, advice)}
162
200
  </g>
163
201
  `;
164
202
  return container;
165
203
  }
166
204
 
167
- function setpointSvg(
205
+ export function setpointSvg(
168
206
  height: number,
169
207
  value: number,
170
208
  setpointAtZero: boolean,
@@ -172,12 +210,13 @@ function setpointSvg(
172
210
  options: {
173
211
  inCommand: boolean;
174
212
  singleSided: boolean;
213
+ narrow: boolean;
175
214
  }
176
215
  ) {
177
216
  const y = -(setpointAtZero
178
217
  ? 0
179
218
  : Math.sign(value) * ((height * Math.abs(value)) / 100 + 2));
180
- const extra = options.singleSided ? -12 : 0;
219
+ const extra = (options.singleSided ? -12 : 0) + (options.narrow ? 0 : 4);
181
220
  let path;
182
221
  if (options.inCommand) {
183
222
  path =
@@ -211,6 +250,27 @@ function setpointSvg(
211
250
  `;
212
251
  }
213
252
 
253
+ export function atSetpoint(
254
+ thrust: number,
255
+ setpoint: number | undefined,
256
+ options: {
257
+ autoAtSetpoint: boolean;
258
+ autoSetpointDeadband: number;
259
+ touching: boolean;
260
+ atSetpoint: boolean;
261
+ }
262
+ ): boolean {
263
+ if (options.touching) {
264
+ return false;
265
+ }
266
+
267
+ if (options.autoAtSetpoint && setpoint !== undefined) {
268
+ return Math.abs(thrust - setpoint) < options.autoSetpointDeadband;
269
+ }
270
+
271
+ return options.atSetpoint;
272
+ }
273
+
214
274
  export function thruster(
215
275
  thrust: number,
216
276
  setpoint: number | undefined,
@@ -228,92 +288,38 @@ export function thruster(
228
288
  advices: LinearAdvice[];
229
289
  topPropeller: PropellerType;
230
290
  bottomPropeller: PropellerType;
291
+ narrow: boolean;
231
292
  }
232
293
  ) {
233
- if (!options.singleSided && options.advices.length > 0) {
234
- throw new Error('Double sided thruster does not support advice');
294
+ if (options.tunnel) {
295
+ thrust = -thrust;
296
+ setpoint = setpoint === undefined ? undefined : -setpoint;
235
297
  }
236
298
 
237
- if (options.autoAtSetpoint && setpoint !== undefined) {
238
- options.atSetpoint =
239
- Math.abs(thrust - setpoint) < options.autoSetpointDeadband;
299
+ if (!options.singleSided && options.advices.length > 0) {
300
+ throw new Error('Double sided thruster does not support advice');
240
301
  }
241
302
 
242
- if (options.touching) {
243
- options.atSetpoint = false;
244
- }
303
+ options.atSetpoint = atSetpoint(thrust, setpoint, options);
245
304
 
246
- let boxColor = 'var(--instrument-enhanced-secondary-color)';
247
- let setPointColor = 'var(--instrument-enhanced-primary-color)';
248
- let arrowColor = 'var(--instrument-regular-secondary-color)';
249
- let containerBackgroundColor = 'var(--instrument-frame-primary-color)';
250
- let zeroLineColor = 'var(--instrument-enhanced-secondary-color)';
251
- let hideTicks = false;
252
- if (options.atSetpoint) {
253
- setPointColor = boxColor;
254
- }
255
- if (state === InstrumentState.active) {
256
- boxColor = 'var(--instrument-regular-secondary-color)';
257
- zeroLineColor = 'var(--instrument-regular-secondary-color)';
258
- setPointColor = 'var(--instrument-regular-primary-color)';
259
- arrowColor = 'var(--instrument-regular-secondary-color)';
260
- if (options.atSetpoint) {
261
- setPointColor = boxColor;
262
- }
263
- } else if (state === InstrumentState.loading) {
264
- boxColor = 'transparent';
265
- setPointColor = 'var(--instrument-frame-tertiary-color)';
266
- zeroLineColor = 'var(--instrument-frame-tertiary-color)';
267
- arrowColor = 'var(--instrument-regular-secondary-color)';
268
- thrust = 0;
269
- hideTicks = true;
270
- if (setpoint !== undefined) {
271
- setpoint = 0;
272
- }
273
- } else if (state === InstrumentState.off) {
274
- boxColor = 'transparent';
275
- setPointColor = 'var(--instrument-frame-tertiary-color)';
276
- arrowColor = 'var(--instrument-frame-tertiary-color)';
277
- zeroLineColor = 'var(--instrument-frame-tertiary-color)';
278
- thrust = 0;
279
- hideTicks = true;
280
- containerBackgroundColor = 'transparent';
281
- if (setpoint !== undefined) {
282
- setpoint = 0;
283
- }
284
- }
305
+ const tc = thrusterColors(options, state);
285
306
 
286
- const centerLine = options.singleSided
287
- ? svg`<rect x="-32" y="-2" width="64" height="4" stroke-width="1" fill=${zeroLineColor} stroke=${zeroLineColor} vector-effect="non-scaling-stroke"/>`
288
- : svg`
289
- <rect x="-44" y="-2" width="88" height="4" stroke-width="1" fill=${zeroLineColor} stroke=${zeroLineColor} vector-effect="non-scaling-stroke"/>
307
+ let centerLine = svg`
308
+ <rect x="-44" y="-2" width="88" height="4" stroke-width="1" fill=${tc.zeroLineColor} stroke=${tc.zeroLineColor} vector-effect="non-scaling-stroke"/>
290
309
  `;
310
+ if (options.singleSided) {
311
+ const width = options.narrow ? 64 : 72;
312
+ const x = options.narrow ? -32 : -36;
313
+ centerLine = svg`<rect x=${x} y="-2" width=${width} height="4" stroke-width="1" fill=${tc.zeroLineColor} stroke=${tc.zeroLineColor} vector-effect="non-scaling-stroke"/>`;
314
+ }
291
315
 
292
316
  const setpointAtZero =
293
317
  Math.abs(setpoint || 0) < options.setpointAtZeroDeadband;
294
318
 
295
- const advices: LinearAdviceRaw[] = options.advices.map((a) => {
296
- const triggered = thrust >= a.min && thrust <= a.max;
297
- let state: AdviceState;
298
- if (triggered) {
299
- state = AdviceState.triggered;
300
- } else if (a.hinted) {
301
- state = AdviceState.hinted;
302
- } else {
303
- state = AdviceState.regular;
304
- }
305
- return {
306
- min: a.min,
307
- max: a.max,
308
- type: a.type,
309
- state,
310
- };
311
- });
312
-
313
- const topAdvices = advices.filter((a) => a.min >= 0);
314
- const bottomAdvices = advices
315
- .filter((a) => a.max <= 0)
316
- .map((a) => ({...a, min: -a.max, max: -a.min}));
319
+ const {topAdvices, bottomAdvices} = convertThrustAdvices(
320
+ options.advices,
321
+ thrust
322
+ );
317
323
 
318
324
  const thrusterSvg = [];
319
325
  const baseheight = options.topPropeller === PropellerType.none ? 134 : 106;
@@ -323,8 +329,13 @@ export function thruster(
323
329
  thrusterTopSingleSided(
324
330
  height,
325
331
  Math.max(thrust, 0),
326
- {box: boxColor, container: containerBackgroundColor},
327
- hideTicks,
332
+ {box: tc.boxColor, container: tc.containerBackgroundColor},
333
+ {
334
+ hideTicks: tc.hideTicks,
335
+ flipAdicePattern: false,
336
+ hideContainer: false,
337
+ narrow: options.narrow,
338
+ },
328
339
  topAdvices
329
340
  )
330
341
  );
@@ -333,8 +344,13 @@ export function thruster(
333
344
  thrusterBottomSingleSided(
334
345
  height,
335
346
  Math.max(-thrust, 0),
336
- {box: boxColor, container: containerBackgroundColor},
337
- hideTicks,
347
+ {box: tc.boxColor, container: tc.containerBackgroundColor},
348
+ {
349
+ hideTicks: tc.hideTicks,
350
+ flipAdicePattern: true,
351
+ hideContainer: false,
352
+ narrow: options.narrow,
353
+ },
338
354
  bottomAdvices
339
355
  )
340
356
  );
@@ -345,8 +361,8 @@ export function thruster(
345
361
  thrusterTop(
346
362
  height,
347
363
  Math.max(thrust, 0),
348
- {box: boxColor, container: containerBackgroundColor},
349
- hideTicks
364
+ {box: tc.boxColor, container: tc.containerBackgroundColor},
365
+ {hideTicks: tc.hideTicks, hideContainer: false}
350
366
  )
351
367
  );
352
368
  if (!options.singleDirection) {
@@ -354,8 +370,8 @@ export function thruster(
354
370
  thrusterBottom(
355
371
  height,
356
372
  Math.max(-thrust, 0),
357
- {box: boxColor, container: containerBackgroundColor},
358
- hideTicks
373
+ {box: tc.boxColor, container: tc.containerBackgroundColor},
374
+ {hideTicks: tc.hideTicks, hideContainer: false}
359
375
  )
360
376
  );
361
377
  }
@@ -368,12 +384,13 @@ export function thruster(
368
384
  setpoint,
369
385
  setpointAtZero,
370
386
  {
371
- fill: setPointColor,
387
+ fill: tc.setPointColor,
372
388
  stroke: 'var(--border-silhouette-color)',
373
389
  },
374
390
  {
375
391
  inCommand: state === InstrumentState.inCommand,
376
392
  singleSided: options.singleSided,
393
+ narrow: options.narrow,
377
394
  }
378
395
  )
379
396
  );
@@ -382,7 +399,7 @@ export function thruster(
382
399
  if (options.tunnel) {
383
400
  return svg`
384
401
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="-160 -64 320 128" x="-160" y="-64">
385
- <g transform="rotate(90)">
402
+ <g transform="rotate(-90)">
386
403
  ${thrusterSvg}
387
404
  </g>
388
405
  </svg>`;
@@ -393,7 +410,7 @@ export function thruster(
393
410
  viewBox = '-80 -300 160 320';
394
411
  y = -320;
395
412
  }
396
- const top = topPropeller(height, arrowColor, options.topPropeller);
413
+ const top = topPropeller(height, tc.arrowColor, options.topPropeller);
397
414
  const bottom = bottomPropeller(
398
415
  options.singleDirectionHalfSize ? 0.5 : height,
399
416
  options.bottomPropeller
@@ -413,3 +430,78 @@ declare global {
413
430
  'obc-thruster': ObcThruster;
414
431
  }
415
432
  }
433
+
434
+ export function convertThrustAdvices(
435
+ advices: LinearAdvice[],
436
+ thrust: number
437
+ ): {topAdvices: LinearAdviceRaw[]; bottomAdvices: LinearAdviceRaw[]} {
438
+ const rawAdvices: LinearAdviceRaw[] = advices.map((a) => {
439
+ const triggered = thrust >= a.min && thrust <= a.max;
440
+ let state: AdviceState;
441
+ if (triggered) {
442
+ state = AdviceState.triggered;
443
+ } else if (a.hinted) {
444
+ state = AdviceState.hinted;
445
+ } else {
446
+ state = AdviceState.regular;
447
+ }
448
+ return {
449
+ min: a.min,
450
+ max: a.max,
451
+ type: a.type,
452
+ state,
453
+ hinted: a.hinted,
454
+ };
455
+ });
456
+
457
+ const topAdvices = rawAdvices.filter((a) => a.min >= 0);
458
+ const bottomAdvices = rawAdvices
459
+ .filter((a) => a.max <= 0)
460
+ .map((a) => ({...a, min: -a.max, max: -a.min}));
461
+ return {topAdvices, bottomAdvices};
462
+ }
463
+
464
+ export function thrusterColors(
465
+ options: {atSetpoint: boolean; touching: boolean},
466
+ state: InstrumentState
467
+ ) {
468
+ let boxColor = 'var(--instrument-enhanced-secondary-color)';
469
+ let setPointColor = 'var(--instrument-enhanced-primary-color)';
470
+ let arrowColor = 'var(--instrument-regular-secondary-color)';
471
+ let containerBackgroundColor = 'var(--instrument-frame-primary-color)';
472
+ let zeroLineColor = 'var(--instrument-enhanced-secondary-color)';
473
+ let hideTicks = false;
474
+ if (options.atSetpoint) {
475
+ setPointColor = boxColor;
476
+ }
477
+ if (state === InstrumentState.active) {
478
+ boxColor = 'var(--instrument-regular-secondary-color)';
479
+ zeroLineColor = 'var(--instrument-regular-secondary-color)';
480
+ setPointColor = 'var(--instrument-regular-primary-color)';
481
+ arrowColor = 'var(--instrument-regular-secondary-color)';
482
+ if (options.atSetpoint) {
483
+ setPointColor = boxColor;
484
+ }
485
+ } else if (state === InstrumentState.loading) {
486
+ boxColor = 'transparent';
487
+ setPointColor = 'var(--instrument-frame-tertiary-color)';
488
+ zeroLineColor = 'var(--instrument-frame-tertiary-color)';
489
+ arrowColor = 'var(--instrument-regular-secondary-color)';
490
+ hideTicks = true;
491
+ } else if (state === InstrumentState.off) {
492
+ boxColor = 'transparent';
493
+ setPointColor = 'var(--instrument-frame-tertiary-color)';
494
+ arrowColor = 'var(--instrument-frame-tertiary-color)';
495
+ zeroLineColor = 'var(--instrument-frame-tertiary-color)';
496
+ hideTicks = true;
497
+ containerBackgroundColor = 'transparent';
498
+ }
499
+ return {
500
+ zeroLineColor,
501
+ boxColor,
502
+ containerBackgroundColor,
503
+ hideTicks,
504
+ setPointColor,
505
+ arrowColor,
506
+ };
507
+ }
@@ -112,7 +112,7 @@ export function renderAdvice(advice: AngleAdviceRaw): SVGTemplateResult {
112
112
  tickmarkStyle = TickmarkStyle.regular;
113
113
  }
114
114
  return svg`
115
- ${adviceMask(advice.minAngle, advice.maxAngle, mainColor, mainColor)}
115
+ ${adviceMask(advice.minAngle, advice.maxAngle, advice.state === AdviceState.triggered ? mainColor : 'none', mainColor)}
116
116
  ${tickmark(advice.minAngle, TickmarkType.primary, tickmarkStyle, 1)}
117
117
  ${tickmark(advice.maxAngle, TickmarkType.primary, tickmarkStyle, 1)}
118
118
  `;
@@ -0,0 +1,69 @@
1
+ import {svg, SVGTemplateResult} from 'lit-html';
2
+
3
+ export function renderLabels(scale: number): SVGTemplateResult {
4
+ const labelWidth = 32;
5
+ const gap = 8;
6
+ const radius: number = 368 / 2;
7
+ const labels = [
8
+ {
9
+ label: 'E',
10
+ x: radius + gap / scale + labelWidth / 2,
11
+ y: 0,
12
+ class: 'label',
13
+ },
14
+ {
15
+ label: 'S',
16
+ x: 0,
17
+ y: radius + gap / scale + labelWidth / 2,
18
+ class: 'label',
19
+ },
20
+ {
21
+ label: 'W',
22
+ x: -(radius + gap / scale + labelWidth / 2),
23
+ y: 0,
24
+ class: 'label',
25
+ },
26
+ ];
27
+
28
+ let arrow = svg`<defs>
29
+ <mask id="circleMask">
30
+ <rect x="-${radius}" y="-${radius}" width="${radius * 2}" height="${radius * 2}" fill="black"/>
31
+ <circle cx="0" cy="0" r="${radius}" fill="white"/>
32
+ </mask>
33
+ </defs>
34
+ <g mask="url(#circleMask)" transform="translate(0, ${-(radius + 45 / scale)}) scale(${1 / scale}, ${1 / scale})">
35
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M-32.04 42.7192 0 0 32.039 42.7192C21.627 40.9314 10.922 40 0 40-10.922 40-21.627 40.9314-32.04 42.7192Z"
36
+ fill="var(--instrument-tick-mark-secondary-color)"/>
37
+ <path d="M5.003 29H2.091L-3.013 20.264H-3.077C-3.066 20.52-3.056 20.7813-3.045 21.048-3.034 21.3147-3.024 21.5867-3.013 21.864-2.992 22.1307-2.976 22.4027-2.965 22.68-2.954 22.9573-2.944 23.2347-2.933 23.512V29H-4.997V17.576H-2.101L2.987 26.232H3.035C3.024 25.9867 3.014 25.736 3.003 25.48 2.992 25.2133 2.982 24.952 2.971 24.696 2.971 24.4293 2.966 24.1627 2.955 23.896 2.944 23.6293 2.934 23.3627 2.923 23.096V17.576H5.003V29Z" fill="var(--element-active-inverted-color)"/>
38
+ </g>`;
39
+
40
+ if (scale < 0.58) {
41
+ arrow = svg`
42
+ <g mask="url(#circleMask)" transform="translate(0, ${-radius})">
43
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M-17.8457 24.984 0 0 17.8458 24.984C11.9868 24.3338 6.0324 24 0 24-6.0323 24-11.9867 24.3338-17.8457 24.984Z" fill="var(--instrument-frame-tertiary-color)"/>
44
+ </g>`;
45
+
46
+ labels.push({
47
+ label: 'N',
48
+ x: 0,
49
+ y: -(radius + gap / scale + labelWidth / 2),
50
+ class: 'label',
51
+ });
52
+ }
53
+
54
+ return svg`
55
+ ${arrow}
56
+
57
+ ${labels.map(
58
+ (l) => svg`
59
+ <text
60
+ x="${l.x}"
61
+ y="${l.y}"
62
+ class="${l.class}"
63
+ >
64
+ ${l.label}
65
+ </text>
66
+ `
67
+ )}
68
+ `;
69
+ }
@@ -1,11 +1,11 @@
1
1
  * {
2
- box-sizing: border-box;
2
+ box-sizing: border-box;
3
3
  }
4
4
 
5
5
  .label {
6
- @mixin font-body;
7
- font-size: calc(16px / var(--scale));
8
- fill: var(--element-neutral-color);
9
- alignment-baseline: middle;
10
- text-anchor: middle;
11
- }
6
+ @mixin font-body;
7
+ font-size: calc(16px / var(--scale));
8
+ fill: var(--element-neutral-color);
9
+ alignment-baseline: middle;
10
+ text-anchor: middle;
11
+ }
@@ -14,6 +14,7 @@ import compentStyle from './watch.css?inline';
14
14
  import {ResizeController} from '@lit-labs/observers/resize-controller.js';
15
15
  import {AngleAdviceRaw, renderAdvice} from './advice';
16
16
  import {Tickmark, TickmarkStyle, tickmark} from './tickmark';
17
+ import {renderLabels} from './label';
17
18
 
18
19
  @customElement('obc-watch')
19
20
  export class ObcWatch extends LitElement {
@@ -27,6 +28,8 @@ export class ObcWatch extends LitElement {
27
28
  @property({type: Boolean}) roundInsideCut = false;
28
29
  @property({type: Array, attribute: false}) tickmarks: Tickmark[] = [];
29
30
  @property({type: Array, attribute: false}) advices: AngleAdviceRaw[] = [];
31
+ @property({type: Boolean}) crosshairEnabled: boolean = false;
32
+ @property({type: Boolean}) labelFrameEnabled: boolean = false;
30
33
 
31
34
  // @ts-expect-error TS6133: The controller unsures that the render
32
35
  // function is called on resize of the element
@@ -91,6 +94,29 @@ export class ObcWatch extends LitElement {
91
94
  }
92
95
  }
93
96
 
97
+ private renderCrosshair(radius: number): SVGTemplateResult {
98
+ return svg`
99
+ <line
100
+ x1="-${radius}"
101
+ y1="0"
102
+ x2="${radius}"
103
+ y2="0"
104
+ stroke="var(--instrument-frame-tertiary-color)"
105
+ stroke-width="1"
106
+ vector-effect="non-scaling-stroke"
107
+ />
108
+ <line
109
+ x1="0"
110
+ y1="-${radius}"
111
+ x2="0"
112
+ y2="${radius}"
113
+ stroke="var(--instrument-frame-tertiary-color)"
114
+ stroke-width="1"
115
+ vector-effect="non-scaling-stroke"
116
+ />
117
+ `;
118
+ }
119
+
94
120
  override render() {
95
121
  const width = (176 + this.padding) * 2;
96
122
  const viewBox = `-${width / 2} -${width / 2} ${width} ${width}`;
@@ -102,6 +128,8 @@ export class ObcWatch extends LitElement {
102
128
  const advices = this.advices
103
129
  ? this.advices.map((a) => renderAdvice(a))
104
130
  : nothing;
131
+ const labels = this.labelFrameEnabled ? renderLabels(scale) : nothing;
132
+
105
133
  return html`
106
134
  <svg
107
135
  width="100%"
@@ -109,7 +137,8 @@ export class ObcWatch extends LitElement {
109
137
  viewBox=${viewBox}
110
138
  style="--scale: ${scale}"
111
139
  >
112
- ${this.watchCircle()} ${tickmarks} ${advices} ${angleSetpoint}
140
+ ${this.watchCircle()} ${tickmarks} ${advices} ${angleSetpoint} ${labels}
141
+ ${this.crosshairEnabled ? this.renderCrosshair(320 / 2) : nothing}
113
142
  </svg>
114
143
  `;
115
144
  }