@oicl/openbridge-webcomponents-full-bundle 2.2.0-next.21 → 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 (55) hide show
  1. package/bundle/openbridge-webcomponents.bundle.js +113 -56
  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/svghelpers/advice-linear.d.ts +7 -0
  28. package/dist/svghelpers/advice-linear.d.ts.map +1 -1
  29. package/dist/svghelpers/advice-linear.js +14 -10
  30. package/dist/svghelpers/advice-linear.js.map +1 -1
  31. package/dist/svghelpers/advice-patterns.d.ts +2 -2
  32. package/dist/svghelpers/advice-patterns.d.ts.map +1 -1
  33. package/dist/svghelpers/advice-patterns.js +6 -4
  34. package/dist/svghelpers/advice-patterns.js.map +1 -1
  35. package/package.json +1 -1
  36. package/src/automation/automation-tank/automation-tank.ts +4 -0
  37. package/src/building-blocks/bar-horizontal/bar-horizontal-fixed-aspect.spec.ts +50 -0
  38. package/src/building-blocks/bar-horizontal/bar-horizontal.stories.ts +6 -0
  39. package/src/building-blocks/bar-horizontal/bar-horizontal.ts +22 -9
  40. package/src/building-blocks/bar-vertical/bar-vertical-dimensions.spec.ts +36 -0
  41. package/src/building-blocks/bar-vertical/bar-vertical-fixed-aspect.spec.ts +49 -0
  42. package/src/building-blocks/bar-vertical/bar-vertical.stories.ts +6 -0
  43. package/src/building-blocks/bar-vertical/bar-vertical.ts +22 -9
  44. package/src/building-blocks/external-scale/external-scale.spec.ts +151 -0
  45. package/src/building-blocks/external-scale/external-scale.stories.ts +6 -0
  46. package/src/building-blocks/external-scale/external-scale.ts +86 -40
  47. package/src/navigation-instruments/gauge-horizontal/gauge-horizontal.spec.ts +55 -0
  48. package/src/navigation-instruments/gauge-horizontal/gauge-horizontal.stories.ts +2 -0
  49. package/src/navigation-instruments/gauge-horizontal/gauge-horizontal.ts +24 -9
  50. package/src/navigation-instruments/gauge-trend/gauge-trend.stories.ts +25 -0
  51. package/src/navigation-instruments/gauge-vertical/gauge-vertical.spec.ts +55 -0
  52. package/src/navigation-instruments/gauge-vertical/gauge-vertical.stories.ts +2 -0
  53. package/src/navigation-instruments/gauge-vertical/gauge-vertical.ts +24 -9
  54. package/src/svghelpers/advice-linear.ts +25 -11
  55. package/src/svghelpers/advice-patterns.ts +13 -5
@@ -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
@@ -23,6 +23,13 @@ const svgOf = (el: Element) => el.querySelector('svg')!;
23
23
  const scaleOf = (el: Element) =>
24
24
  parseFloat(svgOf(el).style.getPropertyValue('--scale'));
25
25
 
26
+ /** The painted thickness of the first advice band, in CSS px. */
27
+ const pillPx = (el: Element) => {
28
+ const svg = svgOf(el);
29
+ const band = svg.querySelector('path.advice-band') as SVGPathElement;
30
+ return +(band.getBBox().height * svg.getScreenCTM()!.a).toFixed(2);
31
+ };
32
+
26
33
  /** Default bands and no setpoint: 48 bar + 24 ticks + 60 labels = 132 thick. */
27
34
  async function mount(fixedAspectRatio = false): Promise<ObcGaugeHorizontal> {
28
35
  const screen = render(
@@ -285,4 +292,52 @@ describe('obc-gauge-horizontal sizing', () => {
285
292
  await until(() => Math.abs(scaleOf(el) - 60 / 72) < 1e-3);
286
293
  await until(() => reports[reports.length - 1] === 60);
287
294
  });
295
+
296
+ it('keeps the advice pill at 8 px at every scale', async () => {
297
+ const screen = render(
298
+ html`<div style="display: block; width: 600px; height: 440px">
299
+ <obc-gauge-horizontal
300
+ .minValue=${0}
301
+ .maxValue=${100}
302
+ .value=${40}
303
+ .primaryTickmarkInterval=${20}
304
+ .advices=${[{min: 20, max: 40, category: 'optimal'}]}
305
+ .fixedAspectRatio=${true}
306
+ ></obc-gauge-horizontal>
307
+ </div>`
308
+ );
309
+ const el = screen.container.querySelector(
310
+ 'obc-gauge-horizontal'
311
+ ) as ObcGaugeHorizontal;
312
+ await el.updateComplete;
313
+ await until(() => Math.abs(scaleOf(el) - 600 / 384) < 1e-3);
314
+ expect(pillPx(el)).toBeCloseTo(8, 1);
315
+ });
316
+
317
+ it('reports the advice column when it is the widest band outside the bar', async () => {
318
+ const screen = render(
319
+ html`<div style="display: block; width: 192px; height: 260px">
320
+ <obc-gauge-horizontal
321
+ .minValue=${0}
322
+ .maxValue=${100}
323
+ .value=${40}
324
+ .primaryTickmarkInterval=${20}
325
+ .showLabels=${false}
326
+ .advices=${[{min: 20, max: 40, category: 'optimal'}]}
327
+ .fixedAspectRatio=${true}
328
+ ></obc-gauge-horizontal>
329
+ </div>`
330
+ );
331
+ const el = screen.container.querySelector(
332
+ 'obc-gauge-horizontal'
333
+ ) as ObcGaugeHorizontal;
334
+ const reports: number[] = [];
335
+ el.addEventListener('scale-dimensions-changed', (e) =>
336
+ reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
337
+ );
338
+ await el.updateComplete;
339
+ // At scale 0.5 the 16 px column is 32 units, past the 24 unit ticks:
340
+ // (48 + 32) × 0.5, not (48 + 24) × 0.5.
341
+ await until(() => reports[reports.length - 1] === 40);
342
+ });
288
343
  });
@@ -634,6 +634,7 @@ export const FixedAspectRatioComparison: StoryObj = {
634
634
  .value=${60}
635
635
  .setpoint=${80}
636
636
  .primaryTickmarkInterval=${20}
637
+ .advices=${[{min: 60, max: 80, type: AdviceType.caution, hinted: true}]}
637
638
  .priority=${Priority.regular}
638
639
  ></obc-gauge-horizontal>
639
640
  </div>
@@ -648,6 +649,7 @@ export const FixedAspectRatioComparison: StoryObj = {
648
649
  .value=${60}
649
650
  .setpoint=${80}
650
651
  .primaryTickmarkInterval=${20}
652
+ .advices=${[{min: 60, max: 80, type: AdviceType.caution, hinted: true}]}
651
653
  .priority=${Priority.enhanced}
652
654
  ></obc-gauge-horizontal>
653
655
  </div>
@@ -10,7 +10,10 @@ import {
10
10
  BorderRadiusPosition,
11
11
  Priority,
12
12
  } from '../types.js';
13
- import type {ExternalScaleConfig} from '../../building-blocks/external-scale/external-scale.js';
13
+ import type {
14
+ ExternalScaleConfig,
15
+ ExternalScaleLayoutConfig,
16
+ } from '../../building-blocks/external-scale/external-scale.js';
14
17
  import {
15
18
  computeExternalScaleViewBox,
16
19
  computeFixedAspectRatioScale,
@@ -172,8 +175,17 @@ export class ObcGaugeHorizontal extends AdviceMixin(
172
175
  @state()
173
176
  private _scale = 1;
174
177
 
175
- /** The drawing's height in viewBox units, kept from the last render for the scale measurement. */
176
- private _viewBoxThickness = 0;
178
+ /** The last render's layout inputs, for the scale measurement. */
179
+ private _layoutConfig?: ExternalScaleLayoutConfig;
180
+
181
+ /** The drawing's height in viewBox units at a scale: the advice column is pixels, so it depends on it. */
182
+ private _thicknessAt = (scale: number): number =>
183
+ this._layoutConfig
184
+ ? computeExternalScaleLayout({
185
+ ...this._layoutConfig,
186
+ fixedAspectRatioScale: scale,
187
+ }).thickness
188
+ : 0;
177
189
 
178
190
  // ResizeController automatically subscribes/unsubscribes based on component lifecycle
179
191
  // @ts-expect-error - Controller is used for side effects, not accessed directly
@@ -189,7 +201,7 @@ export class ObcGaugeHorizontal extends AdviceMixin(
189
201
  containerMainAxisSize: entry.contentRect.width,
190
202
  containerCrossAxisSize: entry.contentRect.height,
191
203
  scaleReferenceSize: this.scaleReferenceSize,
192
- viewBoxThickness: this._viewBoxThickness,
204
+ viewBoxThickness: this._thicknessAt,
193
205
  });
194
206
  // Guard against zero-sized containers, but allow fractional scales < 1
195
207
  this._scale = scale > 0 ? scale : 1;
@@ -301,16 +313,16 @@ export class ObcGaugeHorizontal extends AdviceMixin(
301
313
  adviceEmphasis: this.adviceEmphasis,
302
314
  adviceMaskPrefix: this._adviceMaskPrefix,
303
315
  fixedAspectRatio: this.fixedAspectRatio,
316
+ fixedAspectRatioScale: this.fixedAspectRatio ? this._scale : 1,
304
317
  // Gauges are always in instrument mode - they use fixed borderRadius (8px)
305
318
  // and don't respond to .obc-component-size-* CSS classes for border radius
306
319
  instrumentMode: true,
307
320
  highlightCurrentValue: this.highlightCurrentValue,
308
321
  };
309
322
 
310
- const layout = computeExternalScaleLayout(
311
- toExternalScaleLayoutConfig(config)
312
- );
313
- this._viewBoxThickness = layout.thickness;
323
+ const layoutConfig = toExternalScaleLayoutConfig(config);
324
+ const layout = computeExternalScaleLayout(layoutConfig);
325
+ this._layoutConfig = layoutConfig;
314
326
 
315
327
  const parts = renderExternalScale(config);
316
328
 
@@ -411,11 +423,14 @@ export class ObcGaugeHorizontal extends AdviceMixin(
411
423
  labelThickness: this.labelThickness,
412
424
  length: this.fixedAspectRatio ? this.scaleReferenceSize : this.width,
413
425
  scaleType: this.scaleType,
426
+ advicePosition: this.advicePosition,
427
+ hasAdvice: !!this.advices && this.advices.length > 0,
414
428
  hasAdviceIcon: !!this.advices?.some((a) => a.showIcon),
415
429
  hasSetpoint:
416
430
  this.setpoint !== undefined ||
417
431
  this.newSetpoint !== undefined ||
418
432
  this.departingNewSetpoint !== undefined,
433
+ fixedAspectRatioScale: this.fixedAspectRatio ? this._scale : 1,
419
434
  });
420
435
 
421
436
  // The chart lays out in visual pixels, so a scaled drawing reports its
@@ -492,7 +507,7 @@ export class ObcGaugeHorizontal extends AdviceMixin(
492
507
  containerMainAxisSize: width,
493
508
  containerCrossAxisSize: height,
494
509
  scaleReferenceSize: this.scaleReferenceSize,
495
- viewBoxThickness: this._viewBoxThickness,
510
+ viewBoxThickness: this._thicknessAt,
496
511
  });
497
512
  return true;
498
513
  }
@@ -291,6 +291,7 @@ export const CompactRangeLabels: Story = {
291
291
  rangeLabels: 'xy',
292
292
  hasBar: true,
293
293
  hasScale: true,
294
+ hasAdvice: true,
294
295
  },
295
296
  };
296
297
 
@@ -486,6 +487,11 @@ export const ScaleReferenceSizeComparison: StoryObj = {
486
487
  .hasBar=${true}
487
488
  .hasScale=${true}
488
489
  .secondaryTickmarkInterval=${5}
490
+ .hasAdvice=${true}
491
+ .advice=${[
492
+ {min: 25, max: 45, type: AdviceType.caution, hinted: true},
493
+ {min: 55, max: 75, type: AdviceType.advice, hinted: false},
494
+ ]}
489
495
  ></obc-gauge-trend>
490
496
  </div>
491
497
  <div class="scale-comparison-sublabel">Scale factor: 1.0</div>
@@ -514,6 +520,11 @@ export const ScaleReferenceSizeComparison: StoryObj = {
514
520
  .hasBar=${true}
515
521
  .hasScale=${true}
516
522
  .secondaryTickmarkInterval=${5}
523
+ .hasAdvice=${true}
524
+ .advice=${[
525
+ {min: 25, max: 45, type: AdviceType.caution, hinted: true},
526
+ {min: 55, max: 75, type: AdviceType.advice, hinted: false},
527
+ ]}
517
528
  ></obc-gauge-trend>
518
529
  </div>
519
530
  <div class="scale-comparison-sublabel">Scale factor: 1.6</div>
@@ -542,6 +553,11 @@ export const ScaleReferenceSizeComparison: StoryObj = {
542
553
  .hasBar=${true}
543
554
  .hasScale=${true}
544
555
  .secondaryTickmarkInterval=${5}
556
+ .hasAdvice=${true}
557
+ .advice=${[
558
+ {min: 25, max: 45, type: AdviceType.caution, hinted: true},
559
+ {min: 55, max: 75, type: AdviceType.advice, hinted: false},
560
+ ]}
545
561
  ></obc-gauge-trend>
546
562
  </div>
547
563
  <div class="scale-comparison-sublabel">Scale factor: 1.0</div>
@@ -997,6 +1013,10 @@ export const FixedAspectRatioScalingComparison: StoryObj = {
997
1013
  .primaryTickmarkInterval=${10}
998
1014
  .secondaryTickmarkInterval=${5}
999
1015
  .tertiaryTickmarkInterval=${1}
1016
+ .advices=${[
1017
+ {min: 25, max: 45, type: AdviceType.caution, hinted: true},
1018
+ {min: 55, max: 75, type: AdviceType.advice, hinted: false},
1019
+ ]}
1000
1020
  .scaleBackground=${true}
1001
1021
  .fixedAspectRatio=${false}
1002
1022
  .priority=${Priority.regular}
@@ -1027,6 +1047,11 @@ export const FixedAspectRatioScalingComparison: StoryObj = {
1027
1047
  .primaryTickmarkInterval=${10}
1028
1048
  .secondaryTickmarkInterval=${5}
1029
1049
  .tertiaryTickmarkInterval=${1}
1050
+ .hasAdvice=${true}
1051
+ .advice=${[
1052
+ {min: 25, max: 45, type: AdviceType.caution, hinted: true},
1053
+ {min: 55, max: 75, type: AdviceType.advice, hinted: false},
1054
+ ]}
1030
1055
  ></obc-gauge-trend>
1031
1056
  </div>
1032
1057
  </div>