@oicl/openbridge-webcomponents-full-bundle 2.2.0-next.20 → 2.2.0-next.22

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 (77) hide show
  1. package/bundle/openbridge-webcomponents.bundle.js +156 -61
  2. package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
  3. package/custom-elements.json +49 -21
  4. package/dist/automation/automation-tank/automation-tank.d.ts.map +1 -1
  5. package/dist/automation/automation-tank/automation-tank.js +2 -1
  6. package/dist/automation/automation-tank/automation-tank.js.map +1 -1
  7. package/dist/building-blocks/bar-horizontal/bar-horizontal.d.ts +4 -2
  8. package/dist/building-blocks/bar-horizontal/bar-horizontal.d.ts.map +1 -1
  9. package/dist/building-blocks/bar-horizontal/bar-horizontal.js +12 -6
  10. package/dist/building-blocks/bar-horizontal/bar-horizontal.js.map +1 -1
  11. package/dist/building-blocks/bar-vertical/bar-vertical.d.ts +4 -2
  12. package/dist/building-blocks/bar-vertical/bar-vertical.d.ts.map +1 -1
  13. package/dist/building-blocks/bar-vertical/bar-vertical.js +12 -6
  14. package/dist/building-blocks/bar-vertical/bar-vertical.js.map +1 -1
  15. package/dist/building-blocks/external-scale/external-scale.d.ts +21 -3
  16. package/dist/building-blocks/external-scale/external-scale.d.ts.map +1 -1
  17. package/dist/building-blocks/external-scale/external-scale.js +40 -17
  18. package/dist/building-blocks/external-scale/external-scale.js.map +1 -1
  19. package/dist/navigation-instruments/gauge-horizontal/gauge-horizontal.d.ts +4 -2
  20. package/dist/navigation-instruments/gauge-horizontal/gauge-horizontal.d.ts.map +1 -1
  21. package/dist/navigation-instruments/gauge-horizontal/gauge-horizontal.js +14 -6
  22. package/dist/navigation-instruments/gauge-horizontal/gauge-horizontal.js.map +1 -1
  23. package/dist/navigation-instruments/gauge-vertical/gauge-vertical.d.ts +4 -2
  24. package/dist/navigation-instruments/gauge-vertical/gauge-vertical.d.ts.map +1 -1
  25. package/dist/navigation-instruments/gauge-vertical/gauge-vertical.js +14 -6
  26. package/dist/navigation-instruments/gauge-vertical/gauge-vertical.js.map +1 -1
  27. package/dist/navigation-instruments/heave/heave.d.ts.map +1 -1
  28. package/dist/navigation-instruments/heave/heave.js +14 -5
  29. package/dist/navigation-instruments/heave/heave.js.map +1 -1
  30. package/dist/navigation-instruments/watch/vessel.d.ts +2 -0
  31. package/dist/navigation-instruments/watch/vessel.d.ts.map +1 -1
  32. package/dist/navigation-instruments/watch/vessel.js +6 -0
  33. package/dist/navigation-instruments/watch/vessel.js.map +1 -1
  34. package/dist/navigation-instruments/watch/vessels/fish-cage-side.d.ts +3 -0
  35. package/dist/navigation-instruments/watch/vessels/fish-cage-side.d.ts.map +1 -0
  36. package/dist/navigation-instruments/watch/vessels/fish-cage-side.js +13 -0
  37. package/dist/navigation-instruments/watch/vessels/fish-cage-side.js.map +1 -0
  38. package/dist/navigation-instruments/watch/vessels/fish-cage-top.d.ts +3 -0
  39. package/dist/navigation-instruments/watch/vessels/fish-cage-top.d.ts.map +1 -0
  40. package/dist/navigation-instruments/watch/vessels/fish-cage-top.js +20 -0
  41. package/dist/navigation-instruments/watch/vessels/fish-cage-top.js.map +1 -0
  42. package/dist/svghelpers/advice-linear.d.ts +7 -0
  43. package/dist/svghelpers/advice-linear.d.ts.map +1 -1
  44. package/dist/svghelpers/advice-linear.js +14 -10
  45. package/dist/svghelpers/advice-linear.js.map +1 -1
  46. package/dist/svghelpers/advice-patterns.d.ts +2 -2
  47. package/dist/svghelpers/advice-patterns.d.ts.map +1 -1
  48. package/dist/svghelpers/advice-patterns.js +6 -4
  49. package/dist/svghelpers/advice-patterns.js.map +1 -1
  50. package/package.json +1 -1
  51. package/src/automation/automation-tank/automation-tank.ts +4 -0
  52. package/src/building-blocks/bar-horizontal/bar-horizontal-fixed-aspect.spec.ts +50 -0
  53. package/src/building-blocks/bar-horizontal/bar-horizontal.stories.ts +6 -0
  54. package/src/building-blocks/bar-horizontal/bar-horizontal.ts +22 -9
  55. package/src/building-blocks/bar-vertical/bar-vertical-dimensions.spec.ts +36 -0
  56. package/src/building-blocks/bar-vertical/bar-vertical-fixed-aspect.spec.ts +49 -0
  57. package/src/building-blocks/bar-vertical/bar-vertical.stories.ts +6 -0
  58. package/src/building-blocks/bar-vertical/bar-vertical.ts +22 -9
  59. package/src/building-blocks/external-scale/external-scale.spec.ts +151 -0
  60. package/src/building-blocks/external-scale/external-scale.stories.ts +6 -0
  61. package/src/building-blocks/external-scale/external-scale.ts +86 -40
  62. package/src/navigation-instruments/gauge-horizontal/gauge-horizontal.spec.ts +55 -0
  63. package/src/navigation-instruments/gauge-horizontal/gauge-horizontal.stories.ts +2 -0
  64. package/src/navigation-instruments/gauge-horizontal/gauge-horizontal.ts +24 -9
  65. package/src/navigation-instruments/gauge-trend/gauge-trend.stories.ts +25 -0
  66. package/src/navigation-instruments/gauge-vertical/gauge-vertical.spec.ts +55 -0
  67. package/src/navigation-instruments/gauge-vertical/gauge-vertical.stories.ts +2 -0
  68. package/src/navigation-instruments/gauge-vertical/gauge-vertical.ts +24 -9
  69. package/src/navigation-instruments/heave/heave.stories.ts +12 -1
  70. package/src/navigation-instruments/heave/heave.ts +23 -7
  71. package/src/navigation-instruments/pitch/pitch.stories.ts +13 -0
  72. package/src/navigation-instruments/roll/roll.stories.ts +13 -1
  73. package/src/navigation-instruments/watch/vessel.ts +6 -0
  74. package/src/navigation-instruments/watch/vessels/fish-cage-side.ts +10 -0
  75. package/src/navigation-instruments/watch/vessels/fish-cage-top.ts +17 -0
  76. package/src/svghelpers/advice-linear.ts +25 -11
  77. package/src/svghelpers/advice-patterns.ts +13 -5
@@ -74,3 +74,39 @@ describe('scale-dimensions-changed', () => {
74
74
  expect(leaked).toBe(0);
75
75
  });
76
76
  });
77
+
78
+ /** The bar fills its cell exactly; the advice column beside it is 16 px at every cell size. */
79
+ describe('automation-tank bar mode advice column', () => {
80
+ it('keeps the pill at 8 px and no gutter at two cell sizes', async () => {
81
+ for (const [w, h] of [
82
+ [140, 320],
83
+ [280, 640],
84
+ ]) {
85
+ const screen = render(
86
+ html`<obc-automation-tank
87
+ style="display: block; width: ${w}px; height: ${h}px"
88
+ .chartMode=${'bar'}
89
+ .value=${40}
90
+ .max=${100}
91
+ .hasAdvice=${true}
92
+ .advices=${[{min: 20, max: 40, category: 'optimal'}]}
93
+ ></obc-automation-tank>`
94
+ );
95
+ const tank = screen.container.querySelector(
96
+ 'obc-automation-tank'
97
+ ) as ObcAutomationTank;
98
+ await tank.updateComplete;
99
+ const bar = await tankBar(tank);
100
+ await bar.updateComplete;
101
+ for (let i = 0; i < 20; i++) await frame();
102
+ const svg = bar.querySelector('svg')!;
103
+ const scale = svg.getScreenCTM()!.a;
104
+ const band = svg.querySelector('path.advice-band') as SVGPathElement;
105
+ expect(+(band.getBBox().width * scale).toFixed(1)).toBeCloseTo(8, 1);
106
+ // the viewBox is sized to the cell: the painted width is the cell's
107
+ expect(
108
+ Math.abs(svg.viewBox.baseVal.width * scale - bar.clientWidth)
109
+ ).toBeLessThan(1.5);
110
+ }
111
+ });
112
+ });
@@ -20,6 +20,13 @@ const svgOf = (el: Element) => el.querySelector('svg')!;
20
20
  const scaleOf = (el: Element) =>
21
21
  parseFloat(svgOf(el).style.getPropertyValue('--scale'));
22
22
 
23
+ /** The painted thickness of the first advice band, in CSS px. */
24
+ const pillPx = (el: Element) => {
25
+ const svg = svgOf(el);
26
+ const band = svg.querySelector('path.advice-band') as SVGPathElement;
27
+ return +(band.getBBox().width * svg.getScreenCTM()!.a).toFixed(2);
28
+ };
29
+
23
30
  /** Bar, ticks and labels with no setpoint: 48 + 24 + 60 = 132 thick. */
24
31
  async function mount(boxStyle: string): Promise<ObcBarVertical> {
25
32
  const screen = render(
@@ -98,4 +105,46 @@ describe('obc-bar-vertical fixed aspect ratio', () => {
98
105
  await until(() => Math.abs(scaleOf(el) - 80 / 264) < 1e-3);
99
106
  await until(() => reports[reports.length - 1] === 80);
100
107
  });
108
+
109
+ it('keeps the advice pill at 8 px and its column at 16 px at every scale', async () => {
110
+ const mountWithAdvice = async (boxStyle: string) => {
111
+ const screen = render(
112
+ html`<div style=${boxStyle}>
113
+ <obc-bar-vertical
114
+ .minValue=${0}
115
+ .maxValue=${100}
116
+ .value=${40}
117
+ .hasBar=${true}
118
+ .hasScale=${false}
119
+ .showLabels=${false}
120
+ .barThickness=${48}
121
+ .advices=${[{min: 20, max: 40, category: 'optimal'}]}
122
+ .fixedAspectRatio=${true}
123
+ ></obc-bar-vertical>
124
+ </div>`
125
+ );
126
+ const el = screen.container.querySelector(
127
+ 'obc-bar-vertical'
128
+ ) as ObcBarVertical;
129
+ await el.updateComplete;
130
+ const reports: number[] = [];
131
+ el.addEventListener('scale-dimensions-changed', (e) =>
132
+ reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
133
+ );
134
+ return {el, reports};
135
+ };
136
+ // 400 px of width has room: the height decides, 48 × 1.5625 + 16 = 91
137
+ const wide = await mountWithAdvice(
138
+ 'display: block; width: 400px; height: 600px'
139
+ );
140
+ await until(() => wide.reports[wide.reports.length - 1] === 91);
141
+ expect(pillPx(wide.el)).toBeCloseTo(8, 1);
142
+ // 60 px of width: (60 - 16) / 48 is the scale the bar can still have
143
+ const narrow = await mountWithAdvice(
144
+ 'display: block; width: 60px; height: 600px'
145
+ );
146
+ await until(() => Math.abs(scaleOf(narrow.el) - (60 - 16) / 48) < 1e-3);
147
+ await until(() => narrow.reports[narrow.reports.length - 1] === 60);
148
+ expect(pillPx(narrow.el)).toBeCloseTo(8, 1);
149
+ });
101
150
  });
@@ -1259,6 +1259,9 @@ export const FixedAspectRatioComparison: StoryObj = {
1259
1259
  barNormal.fillMode = FillMode.fill;
1260
1260
  barNormal.priority = Priority.regular;
1261
1261
  barNormal.primaryTickmarkInterval = 20;
1262
+ barNormal.advices = [
1263
+ {min: 60, max: 80, type: AdviceType.caution, hinted: true},
1264
+ ];
1262
1265
  barNormal.fixedAspectRatio = false;
1263
1266
  barNormal.style.cssText = 'flex: 1; width: 100%;';
1264
1267
 
@@ -1288,6 +1291,9 @@ export const FixedAspectRatioComparison: StoryObj = {
1288
1291
  barFixed.fillMode = FillMode.fill;
1289
1292
  barFixed.priority = Priority.enhanced;
1290
1293
  barFixed.primaryTickmarkInterval = 20;
1294
+ barFixed.advices = [
1295
+ {min: 60, max: 80, type: AdviceType.caution, hinted: true},
1296
+ ];
1291
1297
  barFixed.fixedAspectRatio = true;
1292
1298
  barFixed.style.cssText = 'flex: 1; width: 100%;';
1293
1299
 
@@ -12,7 +12,10 @@ import {
12
12
  } from '../../navigation-instruments/types.js';
13
13
  import {AdviceMixin} from '../../svghelpers/advice-mixin.js';
14
14
  import {nextAdviceMaskId} from '../../svghelpers/advice.js';
15
- import type {ExternalScaleConfig} from '../external-scale/external-scale.js';
15
+ import type {
16
+ ExternalScaleConfig,
17
+ ExternalScaleLayoutConfig,
18
+ } from '../external-scale/external-scale.js';
16
19
  import {
17
20
  computeExternalScaleViewBox,
18
21
  computeFixedAspectRatioScale,
@@ -156,8 +159,17 @@ export class ObcBarVertical extends AdviceMixin(
156
159
  @state()
157
160
  private _scale = 1;
158
161
 
159
- /** The drawing's width in viewBox units, kept from the last render for the scale measurement. */
160
- private _viewBoxThickness = 0;
162
+ /** The last render's layout inputs, for the scale measurement. */
163
+ private _layoutConfig?: ExternalScaleLayoutConfig;
164
+
165
+ /** The drawing's width in viewBox units at a scale: the advice column is pixels, so it depends on it. */
166
+ private _thicknessAt = (scale: number): number =>
167
+ this._layoutConfig
168
+ ? computeExternalScaleLayout({
169
+ ...this._layoutConfig,
170
+ fixedAspectRatioScale: scale,
171
+ }).thickness
172
+ : 0;
161
173
 
162
174
  // ResizeController automatically subscribes/unsubscribes based on component lifecycle
163
175
  // @ts-expect-error - Controller is used for side effects, not accessed directly
@@ -173,7 +185,7 @@ export class ObcBarVertical extends AdviceMixin(
173
185
  containerMainAxisSize: entry.contentRect.height,
174
186
  containerCrossAxisSize: entry.contentRect.width,
175
187
  scaleReferenceSize: this.scaleReferenceSize,
176
- viewBoxThickness: this._viewBoxThickness,
188
+ viewBoxThickness: this._thicknessAt,
177
189
  });
178
190
 
179
191
  // Report scaled dimensions to parent chart
@@ -304,14 +316,14 @@ export class ObcBarVertical extends AdviceMixin(
304
316
  adviceEmphasis: this.adviceEmphasis,
305
317
  adviceMaskPrefix: this._adviceMaskPrefix,
306
318
  fixedAspectRatio: this.fixedAspectRatio,
319
+ fixedAspectRatioScale: this.fixedAspectRatio ? this._scale : 1,
307
320
  instrumentMode: this.instrumentMode,
308
321
  highlightCurrentValue: this.highlightCurrentValue,
309
322
  };
310
323
 
311
- const layout = computeExternalScaleLayout(
312
- toExternalScaleLayoutConfig(config)
313
- );
314
- this._viewBoxThickness = layout.thickness;
324
+ const layoutConfig = toExternalScaleLayoutConfig(config);
325
+ const layout = computeExternalScaleLayout(layoutConfig);
326
+ this._layoutConfig = layoutConfig;
315
327
 
316
328
  const parts = renderExternalScale(config);
317
329
 
@@ -430,6 +442,7 @@ export class ObcBarVertical extends AdviceMixin(
430
442
  this.setpoint !== undefined ||
431
443
  this.newSetpoint !== undefined ||
432
444
  this.departingNewSetpoint !== undefined,
445
+ fixedAspectRatioScale: this.fixedAspectRatio ? this._scale : 1,
433
446
  });
434
447
 
435
448
  // When fixedAspectRatio=true, the SVG scales proportionally via preserveAspectRatio="meet".
@@ -513,7 +526,7 @@ export class ObcBarVertical extends AdviceMixin(
513
526
  containerMainAxisSize: height,
514
527
  containerCrossAxisSize: width,
515
528
  scaleReferenceSize: this.scaleReferenceSize,
516
- viewBoxThickness: this._viewBoxThickness,
529
+ viewBoxThickness: this._thicknessAt,
517
530
  });
518
531
  return true;
519
532
  }
@@ -10,6 +10,7 @@ import {
10
10
  AdvicePosition,
11
11
  EXTERNAL_SCALE_MAX_TICKS,
12
12
  computeExternalScaleLayout,
13
+ computeFixedAspectRatioScale,
13
14
  type ExternalScaleConfig,
14
15
  type ExternalScaleLayoutConfig,
15
16
  } from './external-scale.js';
@@ -330,3 +331,153 @@ describe('advice overlays', () => {
330
331
  expect(out).toContain('id="bar-7-0"');
331
332
  });
332
333
  });
334
+
335
+ describe('advice geometry under fixedAspectRatio', () => {
336
+ const layout = (overrides: Partial<ExternalScaleLayoutConfig>) =>
337
+ computeExternalScaleLayout({
338
+ orientation: ExternalScaleOrientation.vertical,
339
+ side: ExternalScaleSide.right,
340
+ length: 200,
341
+ hasBar: true,
342
+ hasScale: false,
343
+ labels: false,
344
+ barThickness: 24,
345
+ tickThickness: 24,
346
+ labelThickness: 60,
347
+ scaleType: ScaleType.regular,
348
+ hasAdvice: true,
349
+ ...overrides,
350
+ });
351
+
352
+ it('reserves the advice column in pixels, so the viewBox share grows as the drawing shrinks', () => {
353
+ expect(layout({fixedAspectRatioScale: 0.5}).viewBoxThickness).toBe(24 + 32);
354
+ expect(layout({fixedAspectRatioScale: 2}).viewBoxThickness).toBe(24 + 8);
355
+ expect(
356
+ layout({advicePosition: AdvicePosition.outer, fixedAspectRatioScale: 0.5})
357
+ .viewBoxThickness
358
+ ).toBe(24 + 48);
359
+ expect(
360
+ layout({hasAdviceIcon: true, fixedAspectRatioScale: 0.5}).viewBoxThickness
361
+ ).toBe(24 + 32 + 16);
362
+ });
363
+
364
+ /** Bounding box of the advice bands a scale paints, in viewBox units. */
365
+ const bandBox = (overrides: Partial<ExternalScaleConfig>) => {
366
+ const host = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
367
+ document.body.appendChild(host);
368
+ try {
369
+ render(
370
+ svg`${
371
+ renderExternalScale(
372
+ bottomScale({
373
+ advices: [{min: 20, max: 40, category: 'optimal'}],
374
+ hasBar: true,
375
+ barThickness: 24,
376
+ hasScale: false,
377
+ labels: false,
378
+ ...overrides,
379
+ })
380
+ ).adviceOverlays
381
+ }`,
382
+ host
383
+ );
384
+ const boxes = [...host.querySelectorAll('path.advice-band')].map((p) =>
385
+ (p as SVGPathElement).getBBox()
386
+ );
387
+ return {
388
+ x: Math.min(...boxes.map((b) => b.x)),
389
+ y: Math.min(...boxes.map((b) => b.y)),
390
+ width: Math.max(...boxes.map((b) => b.width)),
391
+ height: Math.max(...boxes.map((b) => b.height)),
392
+ };
393
+ } finally {
394
+ host.remove();
395
+ }
396
+ };
397
+ const perp = ({y, height}: ReturnType<typeof bandBox>) => ({y, height});
398
+
399
+ it('paints the pill 8 px thick and 4 px off the bar at every scale', () => {
400
+ // The bar ends at 24 on a bottom scale; 8 and 4 are CSS px, so in
401
+ // viewBox units they are divided by the painted scale.
402
+ expect(perp(bandBox({fixedAspectRatioScale: 1}))).toEqual({
403
+ y: 24 + 4,
404
+ height: 8,
405
+ });
406
+ expect(perp(bandBox({fixedAspectRatioScale: 0.5}))).toEqual({
407
+ y: 24 + 8,
408
+ height: 16,
409
+ });
410
+ expect(perp(bandBox({fixedAspectRatioScale: 2}))).toEqual({
411
+ y: 24 + 2,
412
+ height: 4,
413
+ });
414
+ });
415
+
416
+ it('mirrors the outer pill across the bar: 14 px off its edge on a top scale as on a bottom one', () => {
417
+ const outer = {advicePosition: AdvicePosition.outer};
418
+ expect(perp(bandBox({...outer, fixedAspectRatioScale: 1}))).toEqual({
419
+ y: 24 + 14,
420
+ height: 8,
421
+ });
422
+ const top = {...outer, side: ExternalScaleSide.top};
423
+ expect(perp(bandBox({...top, fixedAspectRatioScale: 1}))).toEqual({
424
+ y: -24 - 14 - 8,
425
+ height: 8,
426
+ });
427
+ expect(perp(bandBox({...top, fixedAspectRatioScale: 0.5}))).toEqual({
428
+ y: -24 - 28 - 16,
429
+ height: 16,
430
+ });
431
+ });
432
+
433
+ it('keeps the pill tip inset and the alert corners in pixels', () => {
434
+ // The pill's tips sit 4 px inside the range at every scale.
435
+ const span = (scale: number) => bandBox({fixedAspectRatioScale: scale});
436
+ expect(span(1).width).toBeCloseTo(span(2).width - 4, 3);
437
+ // A no-go band 2.7 units long has room for 2 px corners at scale 3 only
438
+ // when the radius is pixels too: 2 corners of 2 units would not fit.
439
+ const short = {
440
+ advices: [{min: 20, max: 20.5, category: 'caution'}],
441
+ fixedAspectRatioScale: 3,
442
+ };
443
+ expect(bandBox(short).height).toBeCloseTo(8 / 3, 3);
444
+ });
445
+
446
+ it('caps the scale by the cross axis with the pixel column held out of the ratio', () => {
447
+ // 48 scaled units plus a 16 px column: the drawing fits a 60 px host at
448
+ // (60 - 16) / 48, not at 60 / 64.
449
+ const thickness = (scale: number) => 48 + 16 / scale;
450
+ const scale = (containerCrossAxisSize: number) =>
451
+ computeFixedAspectRatioScale({
452
+ orientation: ExternalScaleOrientation.vertical,
453
+ containerMainAxisSize: 600,
454
+ scaleReferenceSize: 384,
455
+ containerCrossAxisSize,
456
+ viewBoxThickness: thickness,
457
+ });
458
+ expect(scale(400)).toBeCloseTo(600 / 384, 4);
459
+ expect(scale(60)).toBeCloseTo((60 - 16) / 48, 3);
460
+ });
461
+
462
+ it('settles the cap in a host barely wider than the pixel column', () => {
463
+ // A 48 unit bar beside a 24 px outer column: in a 30 px host only
464
+ // (30 - 24) / 48 paints at itself. A 20 px host has no such scale and
465
+ // keeps the estimate from the main axis.
466
+ const thickness = (scale: number) =>
467
+ layout({
468
+ barThickness: 48,
469
+ advicePosition: AdvicePosition.outer,
470
+ fixedAspectRatioScale: scale,
471
+ }).viewBoxThickness;
472
+ const scale = (containerCrossAxisSize: number) =>
473
+ computeFixedAspectRatioScale({
474
+ orientation: ExternalScaleOrientation.vertical,
475
+ containerMainAxisSize: 600,
476
+ scaleReferenceSize: 384,
477
+ containerCrossAxisSize,
478
+ viewBoxThickness: thickness,
479
+ });
480
+ expect(scale(30)).toBeCloseTo((30 - 24) / 48, 6);
481
+ expect(scale(20)).toBeCloseTo(20 / (48 + 24 / (600 / 384)), 6);
482
+ });
483
+ });
@@ -783,6 +783,9 @@ export const FixedAspectRatioComparison: StoryObj = {
783
783
  barNormal.fillMode = FillMode.fill;
784
784
  barNormal.priority = Priority.regular;
785
785
  barNormal.primaryTickmarkInterval = 20;
786
+ barNormal.advices = [
787
+ {min: 60, max: 80, type: AdviceType.caution, hinted: true},
788
+ ];
786
789
  barNormal.fixedAspectRatio = false;
787
790
  barNormal.style.cssText = 'flex: 1; width: 100%;';
788
791
 
@@ -815,6 +818,9 @@ export const FixedAspectRatioComparison: StoryObj = {
815
818
  barFixed.fillMode = FillMode.fill;
816
819
  barFixed.priority = Priority.enhanced;
817
820
  barFixed.primaryTickmarkInterval = 20;
821
+ barFixed.advices = [
822
+ {min: 60, max: 80, type: AdviceType.caution, hinted: true},
823
+ ];
818
824
  barFixed.fixedAspectRatio = true;
819
825
  barFixed.style.cssText = 'flex: 1; width: 100%;';
820
826
 
@@ -137,6 +137,7 @@ import {
137
137
  resolveAdvices,
138
138
  type AdviceInput,
139
139
  type ResolvedAdvice,
140
+ ADVICE_BAND_THICKNESS,
140
141
  ADVICE_ICON_SIZE_LINEAR,
141
142
  } from '../../svghelpers/advice.js';
142
143
  import {
@@ -596,6 +597,14 @@ export interface ExternalScaleConfig {
596
597
  */
597
598
  scaleReferenceSize?: number;
598
599
 
600
+ /**
601
+ * The painted scale under `fixedAspectRatio`, which the wrapper measures
602
+ * from its host. The advice pill, its offset and its column are CSS pixels
603
+ * divided by it, so they keep one on-screen size while the bands scale;
604
+ * unset or 1 in pixel mode.
605
+ */
606
+ fixedAspectRatioScale?: number;
607
+
599
608
  /**
600
609
  * When true, the component is used inside an instrument (e.g., gauge-trend).
601
610
  * In this mode, only label font size responds to .obc-component-size-* CSS classes.
@@ -708,6 +717,13 @@ export type ExternalScaleLayoutConfig = Pick<
708
717
  * extra band so the marker is not clipped by the viewBox.
709
718
  */
710
719
  hasSetpoint?: boolean;
720
+ /**
721
+ * The painted scale under `fixedAspectRatio` (1, the default, in pixel
722
+ * mode). The advice pill, its offset and the column reserved for it are CSS
723
+ * pixels divided by it, so they keep one on-screen size at every host size
724
+ * while the bar, tick and label bands scale with the drawing.
725
+ */
726
+ fixedAspectRatioScale?: number;
711
727
  };
712
728
 
713
729
  export interface ExternalScaleViewBox {
@@ -739,9 +755,16 @@ export function toExternalScaleLayoutConfig(
739
755
  config.setpoint !== undefined ||
740
756
  config.newSetpoint !== undefined ||
741
757
  config.departingNewSetpoint !== undefined,
758
+ fixedAspectRatioScale: config.fixedAspectRatioScale,
742
759
  };
743
760
  }
744
761
 
762
+ /** ViewBox units per CSS pixel of the advice geometry: 1 outside fixedAspectRatio. */
763
+ function advicePx(config: {fixedAspectRatioScale?: number}): number {
764
+ const scale = config.fixedAspectRatioScale;
765
+ return scale !== undefined && scale > 0 ? 1 / scale : 1;
766
+ }
767
+
745
768
  /**
746
769
  * Compute the outer SVG viewBox for a scale given layout.
747
770
  * Wrappers can use this to avoid duplicating orientation-specific math.
@@ -799,8 +822,12 @@ export interface FixedAspectRatioScaleConfig {
799
822
  * `xMidYMid meet` does once the container is narrower than the drawing.
800
823
  */
801
824
  containerCrossAxisSize?: number;
802
- /** The drawing's cross-axis size in viewBox units (`computeExternalScaleLayout().thickness`). */
803
- viewBoxThickness?: number;
825
+ /**
826
+ * The drawing's cross-axis size in viewBox units
827
+ * (`computeExternalScaleLayout().thickness`), or a function of the scale
828
+ * when part of it is pixel-fixed, as the advice column is.
829
+ */
830
+ viewBoxThickness?: number | ((scale: number) => number);
804
831
  }
805
832
 
806
833
  /**
@@ -848,34 +875,51 @@ export function computeFixedAspectRatioScale(
848
875
  // e.g., container=288px, reference=384px => scale=0.75 (zoom out)
849
876
  const mainScale = containerMainAxisSize / scaleReferenceSize;
850
877
 
878
+ const thicknessAt =
879
+ typeof viewBoxThickness === 'function'
880
+ ? viewBoxThickness
881
+ : () => viewBoxThickness ?? 0;
851
882
  if (
852
883
  containerCrossAxisSize === undefined ||
853
884
  containerCrossAxisSize <= 0 ||
854
- viewBoxThickness === undefined ||
855
- viewBoxThickness <= 0
885
+ thicknessAt(mainScale) <= 0
856
886
  ) {
857
887
  return mainScale;
858
888
  }
859
889
 
860
890
  // Integer client sizes round an unconstrained box down by under a pixel;
861
891
  // that is not a constraint.
862
- if (containerCrossAxisSize + 1 >= viewBoxThickness * mainScale) {
892
+ if (containerCrossAxisSize + 1 >= thicknessAt(mainScale) * mainScale) {
863
893
  return mainScale;
864
894
  }
865
895
 
866
- return config.orientation === ExternalScaleOrientation.vertical
867
- ? computeMeetScale(
868
- viewBoxThickness,
869
- scaleReferenceSize,
870
- containerCrossAxisSize,
871
- containerMainAxisSize
872
- )
873
- : computeMeetScale(
874
- scaleReferenceSize,
875
- viewBoxThickness,
876
- containerMainAxisSize,
877
- containerCrossAxisSize
878
- );
896
+ const meet = (thickness: number) =>
897
+ config.orientation === ExternalScaleOrientation.vertical
898
+ ? computeMeetScale(
899
+ thickness,
900
+ scaleReferenceSize,
901
+ containerCrossAxisSize,
902
+ containerMainAxisSize
903
+ )
904
+ : computeMeetScale(
905
+ scaleReferenceSize,
906
+ thickness,
907
+ containerMainAxisSize,
908
+ containerCrossAxisSize
909
+ );
910
+
911
+ // A pixel-fixed part grows in viewBox units as the scale falls, so the cap
912
+ // is the scale that paints at itself: bisected, since the paint rises with
913
+ // the laid-out scale. A host narrower than the pixel part alone has none.
914
+ const painted = (scale: number) => meet(thicknessAt(scale));
915
+ let lo = 0;
916
+ let hi = mainScale;
917
+ for (let i = 0; i < 48; i++) {
918
+ const mid = (lo + hi) / 2;
919
+ if (painted(mid) >= mid) lo = mid;
920
+ else hi = mid;
921
+ }
922
+ return lo > 0 ? lo : painted(mainScale);
879
923
  }
880
924
 
881
925
  /**
@@ -965,7 +1009,7 @@ export function computeExternalScaleLayout(
965
1009
  function computeAdviceBandThickness(
966
1010
  config: Pick<
967
1011
  ExternalScaleLayoutConfig,
968
- 'hasAdvice' | 'advicePosition' | 'hasBar'
1012
+ 'hasAdvice' | 'advicePosition' | 'hasBar' | 'fixedAspectRatioScale'
969
1013
  >
970
1014
  ): number {
971
1015
  if (!config.hasAdvice) return 0;
@@ -973,8 +1017,9 @@ function computeAdviceBandThickness(
973
1017
  ? (config.advicePosition ?? AdvicePosition.inner)
974
1018
  : AdvicePosition.inner;
975
1019
  if (position === AdvicePosition.center) return 0;
976
- if (position === AdvicePosition.outer) return 24;
977
- return 16;
1020
+ const px = advicePx(config);
1021
+ if (position === AdvicePosition.outer) return 24 * px;
1022
+ return 16 * px;
978
1023
  }
979
1024
 
980
1025
  /**
@@ -996,6 +1041,7 @@ export function computeOutsideBarThickness(
996
1041
  | 'hasAdviceIcon'
997
1042
  | 'advicePosition'
998
1043
  | 'hasSetpoint'
1044
+ | 'fixedAspectRatioScale'
999
1045
  >
1000
1046
  ): number {
1001
1047
  const scaleSpace = config.hasScale
@@ -1030,6 +1076,7 @@ function adviceIconStart(
1030
1076
  | 'tickThickness'
1031
1077
  | 'scaleType'
1032
1078
  | 'advicePosition'
1079
+ | 'fixedAspectRatioScale'
1033
1080
  >
1034
1081
  ): number {
1035
1082
  const scaleSpace = config.hasScale
@@ -2785,33 +2832,28 @@ function singleSidedTickmark(
2785
2832
 
2786
2833
  /**
2787
2834
  * The perpendicular coordinate of the advice band's near edge for the
2788
- * configured position: `inner` sits on the tick band 4 off the bar edge,
2789
- * `outer` on the far side of the tick band, `center` in the middle of the
2790
- * bar. Without a bar the band is always `inner`.
2835
+ * configured position: `inner` sits on the tick band 4 px off the bar edge,
2836
+ * `outer` 14 px off it, `center` in the middle of the bar; the same on
2837
+ * either side of the bar. Without a bar the band is always `inner`.
2791
2838
  */
2792
2839
  function advicePerpStart(config: ExternalScaleConfig): number {
2793
2840
  const tickBase = tickBasePerp(config);
2794
2841
  const position = config.hasBar ? config.advicePosition : 'inner';
2795
- const offset = 4;
2842
+ // The pill's own geometry is in CSS px; the bar it sits beside is not.
2843
+ const px = advicePx(config);
2844
+ const offset = 4 * px;
2796
2845
  const outward = isOutwardPositive(config);
2797
2846
  if (position === 'center') {
2798
- const centerOffset = config.barThickness / 2 - 4;
2799
- return (
2800
- (outward ? centerOffset : -config.barThickness + centerOffset) -
2801
- 4 +
2802
- offset
2803
- );
2847
+ const centerOffset = config.barThickness / 2 - 4 * px;
2848
+ return outward ? centerOffset : -config.barThickness + centerOffset;
2804
2849
  }
2805
2850
  if (position === 'inner') {
2806
- return (outward ? tickBase : tickBase - 16) + offset;
2851
+ return (outward ? tickBase : tickBase - 16 * px) + offset;
2807
2852
  }
2808
- return (
2809
- (outward
2810
- ? config.barThickness + 10
2811
- : -config.barThickness -
2812
- computeExternalScaleEffectiveTickThickness(config) +
2813
- 14) + offset
2814
- );
2853
+ const outerGap = 14 * px;
2854
+ return outward
2855
+ ? config.barThickness + outerGap
2856
+ : -config.barThickness - outerGap - ADVICE_BAND_THICKNESS * px;
2815
2857
  }
2816
2858
 
2817
2859
  function renderAdvice(
@@ -2858,20 +2900,24 @@ function renderAdvice(
2858
2900
  if (!advice.point && advice.max < config.maxValue) dash(advice.max);
2859
2901
  }
2860
2902
 
2903
+ const px = advicePx(config);
2861
2904
  const marker = advice.point
2862
2905
  ? renderLinearAdvicePoint({
2863
2906
  vertical,
2864
2907
  main: mainStart,
2865
- perpCenter: perpStart + 4,
2908
+ perpCenter: perpStart + 4 * px,
2866
2909
  advice,
2910
+ unitsPerPx: px,
2867
2911
  })
2868
2912
  : renderLinearAdviceBand({
2869
2913
  vertical,
2870
2914
  mainStart,
2871
2915
  mainEnd,
2872
2916
  perpStart,
2917
+ thickness: ADVICE_BAND_THICKNESS * px,
2873
2918
  advice,
2874
2919
  maskId,
2920
+ unitsPerPx: px,
2875
2921
  });
2876
2922
 
2877
2923
  const icon = advice.showIcon