@oicl/openbridge-webcomponents-full-bundle 2.2.0-next.17 → 2.2.0-next.18

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 (36) hide show
  1. package/bundle/openbridge-webcomponents.bundle.js +269 -67
  2. package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
  3. package/custom-elements.json +257 -14
  4. package/dist/building-blocks/bar-horizontal/bar-horizontal.d.ts +4 -0
  5. package/dist/building-blocks/bar-horizontal/bar-horizontal.d.ts.map +1 -1
  6. package/dist/building-blocks/bar-horizontal/bar-horizontal.js +26 -23
  7. package/dist/building-blocks/bar-horizontal/bar-horizontal.js.map +1 -1
  8. package/dist/building-blocks/bar-vertical/bar-vertical.d.ts +4 -0
  9. package/dist/building-blocks/bar-vertical/bar-vertical.d.ts.map +1 -1
  10. package/dist/building-blocks/bar-vertical/bar-vertical.js +26 -23
  11. package/dist/building-blocks/bar-vertical/bar-vertical.js.map +1 -1
  12. package/dist/building-blocks/external-scale/external-scale.d.ts +28 -1
  13. package/dist/building-blocks/external-scale/external-scale.d.ts.map +1 -1
  14. package/dist/building-blocks/external-scale/external-scale.js +30 -4
  15. package/dist/building-blocks/external-scale/external-scale.js.map +1 -1
  16. package/dist/navigation-instruments/gauge-horizontal/gauge-horizontal.d.ts +28 -17
  17. package/dist/navigation-instruments/gauge-horizontal/gauge-horizontal.d.ts.map +1 -1
  18. package/dist/navigation-instruments/gauge-horizontal/gauge-horizontal.js +91 -11
  19. package/dist/navigation-instruments/gauge-horizontal/gauge-horizontal.js.map +1 -1
  20. package/dist/navigation-instruments/gauge-vertical/gauge-vertical.d.ts +28 -17
  21. package/dist/navigation-instruments/gauge-vertical/gauge-vertical.d.ts.map +1 -1
  22. package/dist/navigation-instruments/gauge-vertical/gauge-vertical.js +91 -11
  23. package/dist/navigation-instruments/gauge-vertical/gauge-vertical.js.map +1 -1
  24. package/package.json +1 -1
  25. package/src/building-blocks/bar-horizontal/bar-horizontal-fixed-aspect.spec.ts +102 -0
  26. package/src/building-blocks/bar-horizontal/bar-horizontal.ts +28 -23
  27. package/src/building-blocks/bar-vertical/bar-vertical-fixed-aspect.spec.ts +101 -0
  28. package/src/building-blocks/bar-vertical/bar-vertical.ts +28 -23
  29. package/src/building-blocks/external-scale/external-scale.ts +72 -3
  30. package/src/navigation-instruments/gauge-horizontal/gauge-horizontal.spec.ts +288 -0
  31. package/src/navigation-instruments/gauge-horizontal/gauge-horizontal.stories.ts +114 -4
  32. package/src/navigation-instruments/gauge-horizontal/gauge-horizontal.ts +129 -41
  33. package/src/navigation-instruments/gauge-trend/gauge-trend.stories.ts +8 -0
  34. package/src/navigation-instruments/gauge-vertical/gauge-vertical.spec.ts +284 -0
  35. package/src/navigation-instruments/gauge-vertical/gauge-vertical.stories.ts +117 -4
  36. package/src/navigation-instruments/gauge-vertical/gauge-vertical.ts +129 -41
@@ -23,6 +23,7 @@ import {
23
23
  computeExternalScaleEffectiveBarThickness,
24
24
  readExternalScaleBorderRadiusPx,
25
25
  startExternalScaleBorderRadiusObserver,
26
+ readContentBox,
26
27
  ScaleType,
27
28
  FillMode,
28
29
  AdvicePosition,
@@ -155,6 +156,9 @@ export class ObcBarVertical extends AdviceMixin(
155
156
  @state()
156
157
  private _scale = 1;
157
158
 
159
+ /** The drawing's width in viewBox units, kept from the last render for the scale measurement. */
160
+ private _viewBoxThickness = 0;
161
+
158
162
  // ResizeController automatically subscribes/unsubscribes based on component lifecycle
159
163
  // @ts-expect-error - Controller is used for side effects, not accessed directly
160
164
  private _resizeController = new ResizeController(this, {
@@ -164,14 +168,12 @@ export class ObcBarVertical extends AdviceMixin(
164
168
  const entry = entries[0];
165
169
  if (!entry) return;
166
170
 
167
- // Use the centralized function that computes scale based on reference size
168
- // For vertical scales, compare container height to reference size
169
- const containerMainAxisSize = entry.contentRect.height;
170
-
171
171
  this._scale = computeFixedAspectRatioScale({
172
172
  orientation: ExternalScaleOrientation.vertical,
173
- containerMainAxisSize,
173
+ containerMainAxisSize: entry.contentRect.height,
174
+ containerCrossAxisSize: entry.contentRect.width,
174
175
  scaleReferenceSize: this.scaleReferenceSize,
176
+ viewBoxThickness: this._viewBoxThickness,
175
177
  });
176
178
 
177
179
  // Report scaled dimensions to parent chart
@@ -309,6 +311,7 @@ export class ObcBarVertical extends AdviceMixin(
309
311
  const layout = computeExternalScaleLayout(
310
312
  toExternalScaleLayoutConfig(config)
311
313
  );
314
+ this._viewBoxThickness = layout.thickness;
312
315
 
313
316
  const parts = renderExternalScale(config);
314
317
 
@@ -382,6 +385,9 @@ export class ObcBarVertical extends AdviceMixin(
382
385
  this.setpointPresenceChanged(changed);
383
386
 
384
387
  if (!this.fixedAspectRatio || layoutChanged) {
388
+ // A thinner or thicker drawing under the same box changes the painted
389
+ // scale without a resize event.
390
+ if (this.fixedAspectRatio) this._measureScale();
385
391
  this.reportDimensions();
386
392
  }
387
393
  }
@@ -498,6 +504,20 @@ export class ObcBarVertical extends AdviceMixin(
498
504
  this.style.width = '';
499
505
  }
500
506
 
507
+ /** Reads the host's content box into the scale; false while the host has no size yet. */
508
+ private _measureScale(): boolean {
509
+ const {width, height} = readContentBox(this);
510
+ if (height <= 0) return false;
511
+ this._scale = computeFixedAspectRatioScale({
512
+ orientation: ExternalScaleOrientation.vertical,
513
+ containerMainAxisSize: height,
514
+ containerCrossAxisSize: width,
515
+ scaleReferenceSize: this.scaleReferenceSize,
516
+ viewBoxThickness: this._viewBoxThickness,
517
+ });
518
+ return true;
519
+ }
520
+
501
521
  /**
502
522
  * Calculate scale based on current element size.
503
523
  * Called when fixedAspectRatio is enabled or scaleReferenceSize changes.
@@ -505,13 +525,7 @@ export class ObcBarVertical extends AdviceMixin(
505
525
  private _updateScaleFromCurrentSize(): void {
506
526
  // Use requestAnimationFrame to ensure layout is complete
507
527
  requestAnimationFrame(() => {
508
- const containerHeight = this.clientHeight;
509
- if (containerHeight > 0) {
510
- this._scale = computeFixedAspectRatioScale({
511
- orientation: ExternalScaleOrientation.vertical,
512
- containerMainAxisSize: containerHeight,
513
- scaleReferenceSize: this.scaleReferenceSize,
514
- });
528
+ if (this._measureScale()) {
515
529
  this.requestUpdate();
516
530
  // Report updated dimensions to parent (matches pattern in ResizeController and _refreshBorderRadiusFromCssVar)
517
531
  this.reportDimensions();
@@ -531,17 +545,8 @@ export class ObcBarVertical extends AdviceMixin(
531
545
 
532
546
  // In fixed-aspect-ratio mode, recompute scale when border radius changes
533
547
  // (border radius affects effective bar thickness and therefore viewBox)
534
- if (this.fixedAspectRatio) {
535
- const rect = this.getBoundingClientRect();
536
- if (rect.height > 0) {
537
- this._scale = computeFixedAspectRatioScale({
538
- orientation: ExternalScaleOrientation.vertical,
539
- containerMainAxisSize: rect.height,
540
- scaleReferenceSize: this.scaleReferenceSize,
541
- });
542
- // Report updated dimensions
543
- this.reportDimensions();
544
- }
548
+ if (this.fixedAspectRatio && this._measureScale()) {
549
+ this.reportDimensions();
545
550
  }
546
551
  }
547
552
 
@@ -793,6 +793,14 @@ export interface FixedAspectRatioScaleConfig {
793
793
  containerMainAxisSize: number;
794
794
  /** Reference size at which the scale renders at 1:1 (default: 384) */
795
795
  scaleReferenceSize: number;
796
+ /**
797
+ * Cross-axis size of the container (width for vertical, height for
798
+ * horizontal). With `viewBoxThickness` it caps the scale the way
799
+ * `xMidYMid meet` does once the container is narrower than the drawing.
800
+ */
801
+ containerCrossAxisSize?: number;
802
+ /** The drawing's cross-axis size in viewBox units (`computeExternalScaleLayout().thickness`). */
803
+ viewBoxThickness?: number;
796
804
  }
797
805
 
798
806
  /**
@@ -807,17 +815,28 @@ export interface FixedAspectRatioScaleConfig {
807
815
  * This scale factor is applied to SVG rendering while keeping text labels at constant size
808
816
  * by using the CSS variable `--scale` to counter-scale font sizes.
809
817
  *
818
+ * The SVG is painted with `xMidYMid meet`, which takes the smaller of the two
819
+ * axes' ratios. Pass the container's cross-axis size and the drawing's
820
+ * thickness so the factor follows the paint when the cross axis is the limit;
821
+ * without them the main axis alone decides, as it does whenever the cross axis
822
+ * has room.
823
+ *
810
824
  * Works for all orientations and sides:
811
825
  * - Vertical scales (left/right): compare container height vs reference
812
826
  * - Horizontal scales (top/bottom): compare container width vs reference
813
827
  *
814
- * @param config Configuration with orientation, container size, and reference size
828
+ * @param config Configuration with orientation, container sizes, reference size and drawing thickness
815
829
  * @returns Scale factor (> 0), defaults to 1 if container size is invalid
816
830
  */
817
831
  export function computeFixedAspectRatioScale(
818
832
  config: FixedAspectRatioScaleConfig
819
833
  ): number {
820
- const {containerMainAxisSize, scaleReferenceSize} = config;
834
+ const {
835
+ containerMainAxisSize,
836
+ scaleReferenceSize,
837
+ containerCrossAxisSize,
838
+ viewBoxThickness,
839
+ } = config;
821
840
 
822
841
  // Guard against zero or negative sizes
823
842
  if (containerMainAxisSize <= 0 || scaleReferenceSize <= 0) {
@@ -827,7 +846,57 @@ export function computeFixedAspectRatioScale(
827
846
  // Scale = container size / reference size
828
847
  // e.g., container=480px, reference=384px => scale=1.25 (zoom in)
829
848
  // e.g., container=288px, reference=384px => scale=0.75 (zoom out)
830
- return containerMainAxisSize / scaleReferenceSize;
849
+ const mainScale = containerMainAxisSize / scaleReferenceSize;
850
+
851
+ if (
852
+ containerCrossAxisSize === undefined ||
853
+ containerCrossAxisSize <= 0 ||
854
+ viewBoxThickness === undefined ||
855
+ viewBoxThickness <= 0
856
+ ) {
857
+ return mainScale;
858
+ }
859
+
860
+ // Integer client sizes round an unconstrained box down by under a pixel;
861
+ // that is not a constraint.
862
+ if (containerCrossAxisSize + 1 >= viewBoxThickness * mainScale) {
863
+ return mainScale;
864
+ }
865
+
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
+ );
879
+ }
880
+
881
+ /**
882
+ * The element's content box in CSS px: the box a `100%` × `100%` SVG child
883
+ * fills, and what a ResizeObserver's `contentRect` reports. `clientWidth` /
884
+ * `clientHeight` include the padding, and `getBoundingClientRect()` is scaled
885
+ * by any ancestor CSS `zoom`, so neither is the box the drawing is painted in.
886
+ *
887
+ * @param el The host element
888
+ * @returns Content width and height in CSS px, 0 × 0 while the element has no layout box
889
+ */
890
+ export function readContentBox(el: HTMLElement): {
891
+ width: number;
892
+ height: number;
893
+ } {
894
+ const style = getComputedStyle(el);
895
+ const px = (value: string): number => parseFloat(value) || 0;
896
+ return {
897
+ width: el.clientWidth - px(style.paddingLeft) - px(style.paddingRight),
898
+ height: el.clientHeight - px(style.paddingTop) - px(style.paddingBottom),
899
+ };
831
900
  }
832
901
 
833
902
  /**
@@ -0,0 +1,288 @@
1
+ import {describe, expect, it} from 'vitest';
2
+ import {render} from 'vitest-browser-lit';
3
+ import {html} from 'lit';
4
+ import '../../main.css';
5
+ import './gauge-horizontal.js';
6
+ import '../../bars-graphs/line-graph/line-graph.js';
7
+ import {ExternalScaleSide} from './gauge-horizontal.js';
8
+ import type {ObcGaugeHorizontal} from './gauge-horizontal.js';
9
+ import type {ObcLineGraph} from '../../bars-graphs/line-graph/line-graph.js';
10
+
11
+ const frame = () => new Promise((resolve) => requestAnimationFrame(resolve));
12
+
13
+ /** The scale factor settles a few frames after a size change. */
14
+ async function until(check: () => boolean, frames = 40): Promise<void> {
15
+ for (let i = 0; i < frames; i++) {
16
+ if (check()) return;
17
+ await frame();
18
+ }
19
+ throw new Error('the condition never held');
20
+ }
21
+
22
+ const svgOf = (el: Element) => el.querySelector('svg')!;
23
+ const scaleOf = (el: Element) =>
24
+ parseFloat(svgOf(el).style.getPropertyValue('--scale'));
25
+
26
+ /** Default bands and no setpoint: 48 bar + 24 ticks + 60 labels = 132 thick. */
27
+ async function mount(fixedAspectRatio = false): Promise<ObcGaugeHorizontal> {
28
+ const screen = render(
29
+ html`<div style="display: block; width: 600px; height: 260px">
30
+ <obc-gauge-horizontal
31
+ .minValue=${0}
32
+ .maxValue=${100}
33
+ .value=${40}
34
+ .primaryTickmarkInterval=${20}
35
+ .fixedAspectRatio=${fixedAspectRatio}
36
+ ></obc-gauge-horizontal>
37
+ </div>`
38
+ );
39
+ const el = screen.container.querySelector(
40
+ 'obc-gauge-horizontal'
41
+ ) as ObcGaugeHorizontal;
42
+ await el.updateComplete;
43
+ return el;
44
+ }
45
+
46
+ describe('obc-gauge-horizontal sizing', () => {
47
+ it('draws at its 384 px reference length by default', async () => {
48
+ const el = await mount();
49
+ const svg = svgOf(el);
50
+ expect(svg.getAttribute('width')).toBe('384px');
51
+ expect(svg.getAttribute('preserveAspectRatio')).toBe('none');
52
+ expect(Math.round(svg.getBoundingClientRect().width)).toBe(384);
53
+ expect(el.style.display).toBe('');
54
+ });
55
+
56
+ it('fills the box and keeps the label scale when fixedAspectRatio is turned on after connect', async () => {
57
+ const el = await mount();
58
+ el.fixedAspectRatio = true;
59
+ await until(() => scaleOf(el) !== 1);
60
+ const svg = svgOf(el);
61
+ expect(el.style.display).toBe('block');
62
+ expect(el.style.width).toBe('100%');
63
+ expect(svg.getAttribute('width')).toBe('100%');
64
+ expect(svg.getAttribute('height')).toBe('100%');
65
+ expect(svg.getAttribute('preserveAspectRatio')).toBe('xMidYMid meet');
66
+ expect(Math.round(svg.getBoundingClientRect().width)).toBe(600);
67
+ expect(scaleOf(el)).toBeCloseTo(600 / 384, 3);
68
+ });
69
+
70
+ it('follows scaleReferenceSize', async () => {
71
+ const el = await mount(true);
72
+ await until(() => Math.abs(scaleOf(el) - 600 / 384) < 1e-3);
73
+ el.scaleReferenceSize = 192;
74
+ await until(() => Math.abs(scaleOf(el) - 600 / 192) < 1e-3);
75
+ expect(scaleOf(el)).toBeCloseTo(3.125, 3);
76
+ });
77
+
78
+ it('reports the scaled thickness, and re-reports on side and showLabels', async () => {
79
+ const el = await mount();
80
+ const reports: number[] = [];
81
+ el.addEventListener('scale-dimensions-changed', (e) =>
82
+ reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
83
+ );
84
+ el.fixedAspectRatio = true;
85
+ // 132 × 600 / 384 = 206.25
86
+ await until(() => reports[reports.length - 1] === 206);
87
+ const before = reports.length;
88
+ el.side = ExternalScaleSide.top;
89
+ await el.updateComplete;
90
+ await frame();
91
+ expect(reports.length).toBeGreaterThan(before);
92
+ el.showLabels = false;
93
+ // (48 + 24) × 600 / 384 = 112.5
94
+ await until(() => reports[reports.length - 1] === 113);
95
+ });
96
+
97
+ it('returns to the pixel drawing when fixedAspectRatio is turned off', async () => {
98
+ const el = await mount(true);
99
+ await until(() => scaleOf(el) > 1);
100
+ el.fixedAspectRatio = false;
101
+ await el.updateComplete;
102
+ await frame();
103
+ expect(svgOf(el).getAttribute('width')).toBe('384px');
104
+ expect(el.style.display).toBe('');
105
+ expect(scaleOf(el)).toBe(1);
106
+ });
107
+
108
+ it('gives a fixed-aspect chart its rendered thickness', async () => {
109
+ const screen = render(
110
+ html`<obc-line-graph
111
+ style="display: block; width: 800px"
112
+ .width=${800}
113
+ .height=${400}
114
+ .fixedAspectRatioScaling=${true}
115
+ .data=${[
116
+ {label: 'a', value: 10},
117
+ {label: 'b', value: 40},
118
+ {label: 'c', value: 25},
119
+ ]}
120
+ >
121
+ <obc-gauge-horizontal
122
+ slot="bottom-scale"
123
+ .minValue=${0}
124
+ .maxValue=${100}
125
+ .value=${40}
126
+ .primaryTickmarkInterval=${20}
127
+ ></obc-gauge-horizontal>
128
+ </obc-line-graph>`
129
+ );
130
+ const chart = screen.container.querySelector(
131
+ 'obc-line-graph'
132
+ ) as ObcLineGraph;
133
+ const el = screen.container.querySelector(
134
+ 'obc-gauge-horizontal'
135
+ ) as ObcGaugeHorizontal;
136
+ await chart.updateComplete;
137
+ const reports: number[] = [];
138
+ chart
139
+ .shadowRoot!.querySelector('slot[name="bottom-scale"]')!
140
+ .addEventListener('scale-dimensions-changed', (e) =>
141
+ reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
142
+ );
143
+ // The slot is 800 px wide: 132 × 800 / 384 = 275
144
+ await until(() => Math.abs(scaleOf(el) - 800 / 384) < 1e-3, 90);
145
+ await until(() => reports[reports.length - 1] === 275, 90);
146
+ // The chart grows the slot once its debounced layout runs.
147
+ await until(
148
+ () => Math.round(svgOf(el).getBoundingClientRect().height) === 275,
149
+ 90
150
+ );
151
+ });
152
+
153
+ it('leaves a consumer inline style alone in pixel mode', async () => {
154
+ const screen = render(
155
+ html`<obc-gauge-horizontal
156
+ style="display: none; width: 300px"
157
+ .minValue=${0}
158
+ .maxValue=${100}
159
+ ></obc-gauge-horizontal>`
160
+ );
161
+ const el = screen.container.querySelector(
162
+ 'obc-gauge-horizontal'
163
+ ) as ObcGaugeHorizontal;
164
+ await el.updateComplete;
165
+ await frame();
166
+ expect(el.style.display).toBe('none');
167
+ expect(el.style.width).toBe('300px');
168
+ });
169
+
170
+ it('gives a consumer inline style back after a toggle cycle', async () => {
171
+ const screen = render(
172
+ html`<div style="display: block; width: 600px; height: 260px">
173
+ <obc-gauge-horizontal
174
+ style="display: inline-block; height: 120px; width: 300px !important"
175
+ .minValue=${0}
176
+ .maxValue=${100}
177
+ ></obc-gauge-horizontal>
178
+ </div>`
179
+ );
180
+ const el = screen.container.querySelector(
181
+ 'obc-gauge-horizontal'
182
+ ) as ObcGaugeHorizontal;
183
+ await el.updateComplete;
184
+ el.fixedAspectRatio = true;
185
+ await until(() => scaleOf(el) !== 1);
186
+ expect(el.style.width).toBe('100%');
187
+ el.fixedAspectRatio = false;
188
+ await el.updateComplete;
189
+ expect(el.style.display).toBe('inline-block');
190
+ expect(el.style.height).toBe('120px');
191
+ expect(el.style.width).toBe('300px');
192
+ expect(el.style.getPropertyPriority('width')).toBe('important');
193
+ });
194
+
195
+ it('follows the painted scale when the host is shorter than the drawing', async () => {
196
+ const screen = render(
197
+ html`<div style="display: flex; width: 600px; height: 100px">
198
+ <obc-gauge-horizontal
199
+ style="flex: 1"
200
+ .minValue=${0}
201
+ .maxValue=${100}
202
+ .value=${40}
203
+ .primaryTickmarkInterval=${20}
204
+ .fixedAspectRatio=${true}
205
+ ></obc-gauge-horizontal>
206
+ </div>`
207
+ );
208
+ const el = screen.container.querySelector(
209
+ 'obc-gauge-horizontal'
210
+ ) as ObcGaugeHorizontal;
211
+ await el.updateComplete;
212
+ const reports: number[] = [];
213
+ el.addEventListener('scale-dimensions-changed', (e) =>
214
+ reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
215
+ );
216
+ // meet: the 132-tall drawing fits 100 px before the 384-long one fits 600
217
+ await until(() => Math.abs(scaleOf(el) - 100 / 132) < 1e-3);
218
+ const svg = svgOf(el);
219
+ const text = svg.querySelector('text')!;
220
+ const painted = svg.getScreenCTM()!.a;
221
+ expect(painted).toBeCloseTo(100 / 132, 3);
222
+ expect(parseFloat(getComputedStyle(text).fontSize) * painted).toBeCloseTo(
223
+ 12,
224
+ 1
225
+ );
226
+ await until(() => reports[reports.length - 1] === 100);
227
+ });
228
+
229
+ it('re-measures the scale when the drawing thickness changes under the same box', async () => {
230
+ const screen = render(
231
+ html`<div style="display: flex; width: 600px; height: 100px">
232
+ <obc-gauge-horizontal
233
+ style="flex: 1"
234
+ .minValue=${0}
235
+ .maxValue=${100}
236
+ .value=${40}
237
+ .primaryTickmarkInterval=${20}
238
+ .fixedAspectRatio=${true}
239
+ ></obc-gauge-horizontal>
240
+ </div>`
241
+ );
242
+ const el = screen.container.querySelector(
243
+ 'obc-gauge-horizontal'
244
+ ) as ObcGaugeHorizontal;
245
+ await el.updateComplete;
246
+ const reports: number[] = [];
247
+ el.addEventListener('scale-dimensions-changed', (e) =>
248
+ reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
249
+ );
250
+ await until(() => Math.abs(scaleOf(el) - 100 / 132) < 1e-3);
251
+ // 48 + 24 = 72 tall without labels, still more than 100 px at the width's
252
+ // 1.5625, so the height keeps deciding
253
+ reports.length = 0;
254
+ el.showLabels = false;
255
+ await until(() => Math.abs(scaleOf(el) - 100 / 72) < 1e-3);
256
+ await until(() => reports[reports.length - 1] === 100);
257
+ });
258
+
259
+ it('measures the content box of a padded host', async () => {
260
+ const screen = render(
261
+ html`<div style="display: flex; width: 600px; height: 100px">
262
+ <obc-gauge-horizontal
263
+ style="flex: 1; padding: 20px"
264
+ .minValue=${0}
265
+ .maxValue=${100}
266
+ .value=${40}
267
+ .primaryTickmarkInterval=${20}
268
+ .fixedAspectRatio=${true}
269
+ ></obc-gauge-horizontal>
270
+ </div>`
271
+ );
272
+ const el = screen.container.querySelector(
273
+ 'obc-gauge-horizontal'
274
+ ) as ObcGaugeHorizontal;
275
+ await el.updateComplete;
276
+ const reports: number[] = [];
277
+ el.addEventListener('scale-dimensions-changed', (e) =>
278
+ reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
279
+ );
280
+ // 60 px of content height for the 132-tall drawing
281
+ await until(() => Math.abs(scaleOf(el) - 60 / 132) < 1e-3);
282
+ reports.length = 0;
283
+ // 72 tall without labels: 60 / 72 is still under the width's 560 / 384
284
+ el.showLabels = false;
285
+ await until(() => Math.abs(scaleOf(el) - 60 / 72) < 1e-3);
286
+ await until(() => reports[reports.length - 1] === 60);
287
+ });
288
+ });
@@ -15,6 +15,23 @@ const meta: Meta = {
15
15
  tags: ['autodocs', '6.0'],
16
16
  component: 'obc-gauge-horizontal',
17
17
  argTypes: {
18
+ // Fixed by design and not API; the manifest lists the fields, so the
19
+ // table would otherwise show dead controls.
20
+ width: {table: {disable: true}},
21
+ paddingLeft: {table: {disable: true}},
22
+ paddingRight: {table: {disable: true}},
23
+ barThickness: {table: {disable: true}},
24
+ tickThickness: {table: {disable: true}},
25
+ labelThickness: {table: {disable: true}},
26
+ scaleType: {table: {disable: true}},
27
+ frameStyle: {table: {disable: true}},
28
+ borderRadius: {table: {disable: true}},
29
+ hasBar: {table: {disable: true}},
30
+ hasScale: {table: {disable: true}},
31
+ scaleBackground: {table: {disable: true}},
32
+ advicePosition: {table: {disable: true}},
33
+ fixedAspectRatio: {control: {type: 'boolean'}},
34
+ scaleReferenceSize: {control: {type: 'range', min: 96, max: 768, step: 8}},
18
35
  minValue: {control: {type: 'range', min: -100, max: 100}},
19
36
  maxValue: {control: {type: 'range', min: 0, max: 1000}},
20
37
  reverse: {control: {type: 'boolean'}},
@@ -50,6 +67,8 @@ const meta: Meta = {
50
67
  advices: {control: {type: 'object'}},
51
68
  },
52
69
  args: {
70
+ fixedAspectRatio: false,
71
+ scaleReferenceSize: 384,
53
72
  minValue: 0,
54
73
  maxValue: 100,
55
74
  reverse: false,
@@ -74,8 +93,12 @@ const meta: Meta = {
74
93
  side: 'bottom',
75
94
  advices: [],
76
95
  },
77
- render: (args) => html`
78
- <obc-gauge-horizontal
96
+ // A fixed-aspect gauge fills its host, so the toggle only shows something
97
+ // inside a sized box; off, the gauge renders bare and the baselines hold.
98
+ render: (args) => {
99
+ const gauge = html`<obc-gauge-horizontal
100
+ .fixedAspectRatio=${args.fixedAspectRatio}
101
+ .scaleReferenceSize=${args.scaleReferenceSize ?? 384}
79
102
  .minValue=${args.minValue}
80
103
  .maxValue=${args.maxValue}
81
104
  .reverse=${args.reverse}
@@ -100,8 +123,11 @@ const meta: Meta = {
100
123
  .side=${args.side}
101
124
  .advices=${args.advices}
102
125
  >
103
- </obc-gauge-horizontal>
104
- `,
126
+ </obc-gauge-horizontal>`;
127
+ return args.fixedAspectRatio
128
+ ? html`<div style="width: 600px">${gauge}</div>`
129
+ : gauge;
130
+ },
105
131
  } satisfies Meta;
106
132
 
107
133
  export default meta;
@@ -544,3 +570,87 @@ export const Reversed: Story = {
544
570
  secondaryTickmarkInterval: 1,
545
571
  },
546
572
  };
573
+
574
+ /**
575
+ * `obc-gauge-horizontal` is a fixed-config gauge: it draws at the design's 384 px
576
+ * reference width with the bar, tick and label bands at their design
577
+ * thickness. That number is where the drawing is 1:1, not a layout limit.
578
+ *
579
+ * - **fixedAspectRatio=false (default)**: a 384 px wide SVG, whatever the box does.
580
+ * - **fixedAspectRatio=true**: the whole gauge scales to the width of its host
581
+ * like a vector image and the labels keep their font size; `scaleReferenceSize`
582
+ * is the host width at which it is 1:1. Size the host, the gauge fills it.
583
+ *
584
+ * For a scale whose length follows the layout while the bands keep their design
585
+ * thickness, use `obc-bar-horizontal` with `width` from a ResizeObserver, as the
586
+ * table's bar cells and the chart slots do.
587
+ *
588
+ * Drag the corner of each box to resize it.
589
+ */
590
+ export const FixedAspectRatioComparison: StoryObj = {
591
+ tags: ['skip-test'],
592
+ render: () => html`
593
+ <style>
594
+ .far-wrapper {
595
+ display: grid;
596
+ grid-template-rows: 1fr 1fr;
597
+ gap: 32px;
598
+ padding: 16px;
599
+ width: 600px;
600
+ height: 520px;
601
+ }
602
+ .far-box {
603
+ display: flex;
604
+ flex-direction: column;
605
+ padding: 16px;
606
+ border: 2px dashed var(--instrument-frame-tertiary-color);
607
+ resize: both;
608
+ overflow: auto;
609
+ min-width: 200px;
610
+ min-height: 100px;
611
+ }
612
+ .far-box-fixed {
613
+ border-color: var(--instrument-enhanced-primary-color);
614
+ }
615
+ .far-label {
616
+ flex-shrink: 0;
617
+ margin-bottom: 8px;
618
+ font-family: var(--font-family-main);
619
+ font-size: 14px;
620
+ color: var(--instrument-frame-tertiary-color);
621
+ }
622
+ .far-box-fixed .far-label {
623
+ color: var(--instrument-enhanced-primary-color);
624
+ }
625
+ </style>
626
+ <div class="far-wrapper">
627
+ <div class="far-box">
628
+ <div class="far-label">
629
+ fixedAspectRatio=false (default): 384 px wide, whatever the box does
630
+ </div>
631
+ <obc-gauge-horizontal
632
+ .minValue=${-20}
633
+ .maxValue=${120}
634
+ .value=${60}
635
+ .setpoint=${80}
636
+ .primaryTickmarkInterval=${20}
637
+ .priority=${Priority.regular}
638
+ ></obc-gauge-horizontal>
639
+ </div>
640
+ <div class="far-box far-box-fixed">
641
+ <div class="far-label">
642
+ fixedAspectRatio=true: fills the box width, labels keep their size
643
+ </div>
644
+ <obc-gauge-horizontal
645
+ .fixedAspectRatio=${true}
646
+ .minValue=${-20}
647
+ .maxValue=${120}
648
+ .value=${60}
649
+ .setpoint=${80}
650
+ .primaryTickmarkInterval=${20}
651
+ .priority=${Priority.enhanced}
652
+ ></obc-gauge-horizontal>
653
+ </div>
654
+ </div>
655
+ `,
656
+ };