@oicl/openbridge-webcomponents-full-bundle 2.2.0-next.16 → 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.
- package/bundle/openbridge-webcomponents.bundle.js +442 -87
- package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
- package/custom-elements.json +1970 -28
- package/dist/automation/analog-threeway-valve/analog-threeway-valve.d.ts +4 -4
- package/dist/automation/analog-threeway-valve/analog-threeway-valve.js.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.d.ts +20 -0
- package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.d.ts.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.js +1 -0
- package/dist/automation/automation-button/abstract-automation-button-storybook-helpers.js.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button.d.ts +11 -2
- package/dist/automation/automation-button/abstract-automation-button.d.ts.map +1 -1
- package/dist/automation/automation-button/abstract-automation-button.js +40 -20
- package/dist/automation/automation-button/abstract-automation-button.js.map +1 -1
- package/dist/automation/automation-button/badge-layout.d.ts +34 -0
- package/dist/automation/automation-button/badge-layout.d.ts.map +1 -0
- package/dist/automation/automation-button/badge-layout.js +64 -0
- package/dist/automation/automation-button/badge-layout.js.map +1 -0
- package/dist/automation/digital-threeway-valve/digital-threeway-valve.d.ts +4 -4
- package/dist/automation/digital-threeway-valve/digital-threeway-valve.js.map +1 -1
- package/dist/automation/electricity-battery/electricity-battery.d.ts +4 -4
- package/dist/automation/electricity-battery/electricity-battery.js.map +1 -1
- package/dist/building-blocks/bar-horizontal/bar-horizontal.d.ts +4 -0
- package/dist/building-blocks/bar-horizontal/bar-horizontal.d.ts.map +1 -1
- package/dist/building-blocks/bar-horizontal/bar-horizontal.js +26 -23
- package/dist/building-blocks/bar-horizontal/bar-horizontal.js.map +1 -1
- package/dist/building-blocks/bar-vertical/bar-vertical.d.ts +4 -0
- package/dist/building-blocks/bar-vertical/bar-vertical.d.ts.map +1 -1
- package/dist/building-blocks/bar-vertical/bar-vertical.js +26 -23
- package/dist/building-blocks/bar-vertical/bar-vertical.js.map +1 -1
- package/dist/building-blocks/external-scale/external-scale.d.ts +28 -1
- package/dist/building-blocks/external-scale/external-scale.d.ts.map +1 -1
- package/dist/building-blocks/external-scale/external-scale.js +30 -4
- package/dist/building-blocks/external-scale/external-scale.js.map +1 -1
- package/dist/internal/global-setting.d.ts +55 -0
- package/dist/internal/global-setting.d.ts.map +1 -0
- package/dist/internal/global-setting.js +86 -0
- package/dist/internal/global-setting.js.map +1 -0
- package/dist/navigation-instruments/gauge-horizontal/gauge-horizontal.d.ts +28 -17
- package/dist/navigation-instruments/gauge-horizontal/gauge-horizontal.d.ts.map +1 -1
- package/dist/navigation-instruments/gauge-horizontal/gauge-horizontal.js +91 -11
- package/dist/navigation-instruments/gauge-horizontal/gauge-horizontal.js.map +1 -1
- package/dist/navigation-instruments/gauge-vertical/gauge-vertical.d.ts +28 -17
- package/dist/navigation-instruments/gauge-vertical/gauge-vertical.d.ts.map +1 -1
- package/dist/navigation-instruments/gauge-vertical/gauge-vertical.js +91 -11
- package/dist/navigation-instruments/gauge-vertical/gauge-vertical.js.map +1 -1
- package/package.json +1 -1
- package/src/automation/analog-threeway-valve/analog-threeway-valve.ts +4 -4
- package/src/automation/automation-button/abstract-automation-button-storybook-helpers.ts +3 -0
- package/src/automation/automation-button/abstract-automation-button.ts +57 -23
- package/src/automation/automation-button/badge-layout.spec.ts +138 -0
- package/src/automation/automation-button/badge-layout.ts +120 -0
- package/src/automation/digital-threeway-valve/digital-threeway-valve.ts +4 -4
- package/src/automation/electricity-battery/electricity-battery.ts +4 -4
- package/src/automation/pump/pump.stories.ts +59 -0
- package/src/building-blocks/bar-horizontal/bar-horizontal-fixed-aspect.spec.ts +102 -0
- package/src/building-blocks/bar-horizontal/bar-horizontal.ts +28 -23
- package/src/building-blocks/bar-vertical/bar-vertical-fixed-aspect.spec.ts +101 -0
- package/src/building-blocks/bar-vertical/bar-vertical.ts +28 -23
- package/src/building-blocks/external-scale/external-scale.ts +72 -3
- package/src/internal/global-setting.spec.ts +119 -0
- package/src/internal/global-setting.ts +105 -0
- package/src/navigation-instruments/gauge-horizontal/gauge-horizontal.spec.ts +288 -0
- package/src/navigation-instruments/gauge-horizontal/gauge-horizontal.stories.ts +114 -4
- package/src/navigation-instruments/gauge-horizontal/gauge-horizontal.ts +129 -41
- package/src/navigation-instruments/gauge-trend/gauge-trend.stories.ts +8 -0
- package/src/navigation-instruments/gauge-vertical/gauge-vertical.spec.ts +284 -0
- package/src/navigation-instruments/gauge-vertical/gauge-vertical.stories.ts +117 -4
- package/src/navigation-instruments/gauge-vertical/gauge-vertical.ts +129 -41
|
@@ -16,6 +16,23 @@ const meta: Meta = {
|
|
|
16
16
|
tags: ['autodocs', '6.0'],
|
|
17
17
|
component: 'obc-gauge-vertical',
|
|
18
18
|
argTypes: {
|
|
19
|
+
// Fixed by design and not API; the manifest lists the fields, so the
|
|
20
|
+
// table would otherwise show dead controls.
|
|
21
|
+
height: {table: {disable: true}},
|
|
22
|
+
paddingTop: {table: {disable: true}},
|
|
23
|
+
paddingBottom: {table: {disable: true}},
|
|
24
|
+
barThickness: {table: {disable: true}},
|
|
25
|
+
tickThickness: {table: {disable: true}},
|
|
26
|
+
labelThickness: {table: {disable: true}},
|
|
27
|
+
scaleType: {table: {disable: true}},
|
|
28
|
+
frameStyle: {table: {disable: true}},
|
|
29
|
+
borderRadius: {table: {disable: true}},
|
|
30
|
+
hasBar: {table: {disable: true}},
|
|
31
|
+
hasScale: {table: {disable: true}},
|
|
32
|
+
scaleBackground: {table: {disable: true}},
|
|
33
|
+
advicePosition: {table: {disable: true}},
|
|
34
|
+
fixedAspectRatio: {control: {type: 'boolean'}},
|
|
35
|
+
scaleReferenceSize: {control: {type: 'range', min: 96, max: 768, step: 8}},
|
|
19
36
|
minValue: {control: {type: 'range', min: -100, max: 100}},
|
|
20
37
|
maxValue: {control: {type: 'range', min: 0, max: 1000}},
|
|
21
38
|
reverse: {control: {type: 'boolean'}},
|
|
@@ -51,6 +68,8 @@ const meta: Meta = {
|
|
|
51
68
|
advices: {control: {type: 'object'}},
|
|
52
69
|
},
|
|
53
70
|
args: {
|
|
71
|
+
fixedAspectRatio: false,
|
|
72
|
+
scaleReferenceSize: 384,
|
|
54
73
|
minValue: 0,
|
|
55
74
|
maxValue: 100,
|
|
56
75
|
reverse: false,
|
|
@@ -75,8 +94,12 @@ const meta: Meta = {
|
|
|
75
94
|
side: 'right',
|
|
76
95
|
advices: [],
|
|
77
96
|
},
|
|
78
|
-
|
|
79
|
-
|
|
97
|
+
// A fixed-aspect gauge fills its host, so the toggle only shows something
|
|
98
|
+
// inside a sized box; off, the gauge renders bare and the baselines hold.
|
|
99
|
+
render: (args) => {
|
|
100
|
+
const gauge = html`<obc-gauge-vertical
|
|
101
|
+
.fixedAspectRatio=${args.fixedAspectRatio}
|
|
102
|
+
.scaleReferenceSize=${args.scaleReferenceSize ?? 384}
|
|
80
103
|
.minValue=${args.minValue}
|
|
81
104
|
.maxValue=${args.maxValue}
|
|
82
105
|
.reverse=${args.reverse}
|
|
@@ -101,8 +124,11 @@ const meta: Meta = {
|
|
|
101
124
|
.side=${args.side}
|
|
102
125
|
.advices=${args.advices}
|
|
103
126
|
>
|
|
104
|
-
</obc-gauge-vertical
|
|
105
|
-
|
|
127
|
+
</obc-gauge-vertical>`;
|
|
128
|
+
return args.fixedAspectRatio
|
|
129
|
+
? html`<div style="height: 480px">${gauge}</div>`
|
|
130
|
+
: gauge;
|
|
131
|
+
},
|
|
106
132
|
} satisfies Meta;
|
|
107
133
|
|
|
108
134
|
export default meta;
|
|
@@ -596,3 +622,90 @@ export const Reversed: Story = {
|
|
|
596
622
|
advices: [{min: 65, max: 75, type: AdviceType.caution, hinted: false}],
|
|
597
623
|
},
|
|
598
624
|
};
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* `obc-gauge-vertical` is a fixed-config gauge: it draws at the design's 384 px
|
|
628
|
+
* reference height with the bar, tick and label bands at their design
|
|
629
|
+
* thickness. That number is where the drawing is 1:1, not a layout limit.
|
|
630
|
+
*
|
|
631
|
+
* - **fixedAspectRatio=false (default)**: a 384 px tall SVG, whatever the box does.
|
|
632
|
+
* - **fixedAspectRatio=true**: the whole gauge scales to the height of its host
|
|
633
|
+
* like a vector image and the labels keep their font size; `scaleReferenceSize`
|
|
634
|
+
* is the host height at which it is 1:1. Size the host, the gauge fills it.
|
|
635
|
+
*
|
|
636
|
+
* For a scale whose length follows the layout while the bands keep their design
|
|
637
|
+
* thickness, use `obc-bar-vertical` with `height` from a ResizeObserver, as the
|
|
638
|
+
* automation tank and the chart slots do.
|
|
639
|
+
*
|
|
640
|
+
* Drag the corner of each box to resize it.
|
|
641
|
+
*/
|
|
642
|
+
export const FixedAspectRatioComparison: StoryObj = {
|
|
643
|
+
tags: ['skip-test'],
|
|
644
|
+
render: () => html`
|
|
645
|
+
<style>
|
|
646
|
+
.far-wrapper {
|
|
647
|
+
display: grid;
|
|
648
|
+
grid-template-columns: 1fr 1fr;
|
|
649
|
+
gap: 32px;
|
|
650
|
+
padding: 16px;
|
|
651
|
+
height: 600px;
|
|
652
|
+
}
|
|
653
|
+
.far-box {
|
|
654
|
+
display: flex;
|
|
655
|
+
flex-direction: column;
|
|
656
|
+
padding: 16px;
|
|
657
|
+
border: 2px dashed var(--instrument-frame-tertiary-color);
|
|
658
|
+
resize: both;
|
|
659
|
+
overflow: auto;
|
|
660
|
+
min-width: 100px;
|
|
661
|
+
min-height: 200px;
|
|
662
|
+
}
|
|
663
|
+
.far-box-fixed {
|
|
664
|
+
border-color: var(--instrument-enhanced-primary-color);
|
|
665
|
+
}
|
|
666
|
+
.far-label {
|
|
667
|
+
flex-shrink: 0;
|
|
668
|
+
margin-bottom: 8px;
|
|
669
|
+
font-family: var(--font-family-main);
|
|
670
|
+
font-size: 14px;
|
|
671
|
+
color: var(--instrument-frame-tertiary-color);
|
|
672
|
+
}
|
|
673
|
+
.far-box-fixed .far-label {
|
|
674
|
+
color: var(--instrument-enhanced-primary-color);
|
|
675
|
+
}
|
|
676
|
+
.far-box obc-gauge-vertical {
|
|
677
|
+
flex: 1;
|
|
678
|
+
min-height: 0; /* lets the fixed-aspect gauge shrink with the box */
|
|
679
|
+
}
|
|
680
|
+
</style>
|
|
681
|
+
<div class="far-wrapper">
|
|
682
|
+
<div class="far-box">
|
|
683
|
+
<div class="far-label">
|
|
684
|
+
fixedAspectRatio=false (default): 384 px tall, whatever the box does
|
|
685
|
+
</div>
|
|
686
|
+
<obc-gauge-vertical
|
|
687
|
+
.minValue=${-20}
|
|
688
|
+
.maxValue=${120}
|
|
689
|
+
.value=${60}
|
|
690
|
+
.setpoint=${80}
|
|
691
|
+
.primaryTickmarkInterval=${20}
|
|
692
|
+
.priority=${Priority.regular}
|
|
693
|
+
></obc-gauge-vertical>
|
|
694
|
+
</div>
|
|
695
|
+
<div class="far-box far-box-fixed">
|
|
696
|
+
<div class="far-label">
|
|
697
|
+
fixedAspectRatio=true: fills the box height, labels keep their size
|
|
698
|
+
</div>
|
|
699
|
+
<obc-gauge-vertical
|
|
700
|
+
.fixedAspectRatio=${true}
|
|
701
|
+
.minValue=${-20}
|
|
702
|
+
.maxValue=${120}
|
|
703
|
+
.value=${60}
|
|
704
|
+
.setpoint=${80}
|
|
705
|
+
.primaryTickmarkInterval=${20}
|
|
706
|
+
.priority=${Priority.enhanced}
|
|
707
|
+
></obc-gauge-vertical>
|
|
708
|
+
</div>
|
|
709
|
+
</div>
|
|
710
|
+
`,
|
|
711
|
+
};
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
toExternalScaleLayoutConfig,
|
|
20
20
|
computeScaleDimensionsForReport,
|
|
21
21
|
computeExternalScaleEffectiveBarThickness,
|
|
22
|
+
readContentBox,
|
|
22
23
|
ScaleType,
|
|
23
24
|
FillMode,
|
|
24
25
|
AdvicePosition,
|
|
@@ -54,7 +55,7 @@ export {
|
|
|
54
55
|
* ---
|
|
55
56
|
*
|
|
56
57
|
* ### Features
|
|
57
|
-
* - **Fixed Layout:** Height (384px), padding (32px), bar/tick/label thicknesses, and border radius are fixed for consistent gauge appearance.
|
|
58
|
+
* - **Fixed Layout:** Height (384px), padding (32px), bar/tick/label thicknesses, and border radius are fixed for consistent gauge appearance. 384 px is the length the design is drawn at, not a layout limit: see `fixedAspectRatio`.
|
|
58
59
|
* - **Scale Configuration:**
|
|
59
60
|
* - Configurable `minValue` and `maxValue` for the value range.
|
|
60
61
|
* - Optional main, primary, secondary, and tertiary tickmarks at specified intervals.
|
|
@@ -68,7 +69,7 @@ export {
|
|
|
68
69
|
* - Optional `setpoint` value displays a marker.
|
|
69
70
|
* - Automatic at-setpoint detection with configurable deadband.
|
|
70
71
|
* - **Advice Overlays:** Render advice ranges with different types and hinted states.
|
|
71
|
-
* - **Fixed Aspect Ratio:**
|
|
72
|
+
* - **Fixed Aspect Ratio:** `fixedAspectRatio` scales the whole gauge to its container like a vector image while the label font size stays put; `scaleReferenceSize` is the container height at which it draws 1:1.
|
|
72
73
|
* - **Dimension Reporting:** Dispatches `scale-dimensions-changed` events for parent chart integration.
|
|
73
74
|
*
|
|
74
75
|
* ---
|
|
@@ -85,7 +86,6 @@ export {
|
|
|
85
86
|
* - `hasBar`: true
|
|
86
87
|
* - `hasScale`: true
|
|
87
88
|
* - `scaleBackground`: true
|
|
88
|
-
* - `fixedAspectRatio`: true (always scales proportionally)
|
|
89
89
|
*
|
|
90
90
|
* ---
|
|
91
91
|
*
|
|
@@ -127,6 +127,9 @@ export {
|
|
|
127
127
|
* @property maxValue - Maximum scale value
|
|
128
128
|
* @property reverse - Plot `minValue` at the top so values grow downward.
|
|
129
129
|
* @property side - Which side of the chart area this scale lives on (left or right)
|
|
130
|
+
* @property fixedAspectRatio - Scale the whole gauge to its container like a vector image, keeping the label font size: the SVG fills the host, so size the host. Off, the gauge draws at its 384 px reference height.
|
|
131
|
+
* @property scaleReferenceSize - Container height at which a `fixedAspectRatio` gauge draws 1:1 with the design. A taller container enlarges the drawing proportionally, a shorter one shrinks it.
|
|
132
|
+
* @availableWhen scaleReferenceSize fixedAspectRatio==true
|
|
130
133
|
* @property showLabels - Show numerical value labels at primary tickmarks
|
|
131
134
|
* @property mainTickmarks - Array of values for main tickmarks. When undefined, no main tickmarks shown. When empty array [], defaults to [minValue, 0, maxValue].
|
|
132
135
|
* @property primaryTickmarkInterval - Interval for primary (longest) tickmarks with labels
|
|
@@ -163,27 +166,15 @@ export class ObcGaugeVertical extends AdviceMixin(
|
|
|
163
166
|
|
|
164
167
|
@property({type: String}) side: ExternalScaleSide = ExternalScaleSide.right;
|
|
165
168
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
* proportionally (like CSS transform:scale), except label font-size remains constant.
|
|
169
|
-
* When false (default), dimensions react to component properties.
|
|
170
|
-
*
|
|
171
|
-
* This property is intentionally not exposed as a public API or Storybook control.
|
|
172
|
-
* It can be set programmatically by parent components (e.g., GaugeTrend).
|
|
173
|
-
*/
|
|
174
|
-
fixedAspectRatio = false;
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Reference size for proportional scaling when fixedAspectRatio is true.
|
|
178
|
-
* At this height, the scale renders at native 1:1 (matches Figma design).
|
|
179
|
-
* Above this height, the scale grows proportionally; below, it shrinks.
|
|
180
|
-
* @default 384
|
|
181
|
-
*/
|
|
182
|
-
scaleReferenceSize = 384;
|
|
169
|
+
@property({type: Boolean}) fixedAspectRatio = false;
|
|
170
|
+
@property({type: Number}) scaleReferenceSize = 384;
|
|
183
171
|
|
|
184
172
|
@state()
|
|
185
173
|
private _scale = 1;
|
|
186
174
|
|
|
175
|
+
/** The drawing's width in viewBox units, kept from the last render for the scale measurement. */
|
|
176
|
+
private _viewBoxThickness = 0;
|
|
177
|
+
|
|
187
178
|
// ResizeController automatically subscribes/unsubscribes based on component lifecycle
|
|
188
179
|
// @ts-expect-error - Controller is used for side effects, not accessed directly
|
|
189
180
|
private _resizeController = new ResizeController(this, {
|
|
@@ -193,14 +184,12 @@ export class ObcGaugeVertical extends AdviceMixin(
|
|
|
193
184
|
const entry = entries[0];
|
|
194
185
|
if (!entry) return;
|
|
195
186
|
|
|
196
|
-
// Use the centralized function that computes scale based on reference size
|
|
197
|
-
// For vertical scales, compare container height to reference size
|
|
198
|
-
const containerMainAxisSize = entry.contentRect.height;
|
|
199
|
-
|
|
200
187
|
const scale = computeFixedAspectRatioScale({
|
|
201
188
|
orientation: ExternalScaleOrientation.vertical,
|
|
202
|
-
containerMainAxisSize,
|
|
189
|
+
containerMainAxisSize: entry.contentRect.height,
|
|
190
|
+
containerCrossAxisSize: entry.contentRect.width,
|
|
203
191
|
scaleReferenceSize: this.scaleReferenceSize,
|
|
192
|
+
viewBoxThickness: this._viewBoxThickness,
|
|
204
193
|
});
|
|
205
194
|
// Guard against zero-sized containers, but allow fractional scales < 1
|
|
206
195
|
this._scale = scale > 0 ? scale : 1;
|
|
@@ -260,10 +249,16 @@ export class ObcGaugeVertical extends AdviceMixin(
|
|
|
260
249
|
@property({type: Boolean}) highlightCurrentValue = false;
|
|
261
250
|
|
|
262
251
|
override render() {
|
|
252
|
+
// A chart pushes its own height to a slotted scale; in fixedAspectRatio
|
|
253
|
+
// mode the drawing keeps its reference length and the SVG scales it.
|
|
254
|
+
const effectiveLength = this.fixedAspectRatio
|
|
255
|
+
? this.scaleReferenceSize
|
|
256
|
+
: this.height;
|
|
257
|
+
|
|
263
258
|
const config: ExternalScaleConfig = {
|
|
264
259
|
orientation: ExternalScaleOrientation.vertical,
|
|
265
260
|
side: this.side,
|
|
266
|
-
length:
|
|
261
|
+
length: effectiveLength,
|
|
267
262
|
paddingStart: this.paddingTop,
|
|
268
263
|
paddingEnd: this.paddingBottom,
|
|
269
264
|
minValue: this.minValue,
|
|
@@ -315,11 +310,12 @@ export class ObcGaugeVertical extends AdviceMixin(
|
|
|
315
310
|
const layout = computeExternalScaleLayout(
|
|
316
311
|
toExternalScaleLayoutConfig(config)
|
|
317
312
|
);
|
|
313
|
+
this._viewBoxThickness = layout.thickness;
|
|
318
314
|
|
|
319
315
|
const parts = renderExternalScale(config);
|
|
320
316
|
|
|
321
317
|
const viewBox = computeExternalScaleViewBox(
|
|
322
|
-
{orientation: config.orientation, length:
|
|
318
|
+
{orientation: config.orientation, length: effectiveLength},
|
|
323
319
|
layout
|
|
324
320
|
);
|
|
325
321
|
const preserveAspectRatio = this.fixedAspectRatio
|
|
@@ -357,24 +353,44 @@ export class ObcGaugeVertical extends AdviceMixin(
|
|
|
357
353
|
override updated(changed: PropertyValues) {
|
|
358
354
|
super.updated(changed);
|
|
359
355
|
|
|
360
|
-
//
|
|
361
|
-
//
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
356
|
+
// Only the styles this element applied are removed: the first update
|
|
357
|
+
// lists every property, and a consumer's inline style is theirs.
|
|
358
|
+
if (changed.has('fixedAspectRatio')) {
|
|
359
|
+
if (this.fixedAspectRatio) {
|
|
360
|
+
this._applyFixedAspectRatioStyles();
|
|
361
|
+
this._updateScaleFromCurrentSize();
|
|
362
|
+
} else if (changed.get('fixedAspectRatio') === true) {
|
|
363
|
+
this._removeFixedAspectRatioStyles();
|
|
364
|
+
this._scale = 1;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (changed.has('scaleReferenceSize') && this.fixedAspectRatio) {
|
|
369
|
+
this._updateScaleFromCurrentSize();
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// The reported thickness follows the bands, the advice icons, the
|
|
373
|
+
// setpoint marker band and the mode, whichever mode is on; a resize
|
|
374
|
+
// re-reports through the ResizeController.
|
|
365
375
|
if (
|
|
366
|
-
(
|
|
367
|
-
|
|
376
|
+
changed.has('fixedAspectRatio') ||
|
|
377
|
+
changed.has('side') ||
|
|
378
|
+
changed.has('showLabels') ||
|
|
379
|
+
changed.has('advices') ||
|
|
368
380
|
this.setpointPresenceChanged(changed)
|
|
369
381
|
) {
|
|
382
|
+
// A thinner or thicker drawing under the same box changes the painted
|
|
383
|
+
// scale without a resize event.
|
|
384
|
+
if (this.fixedAspectRatio) this._measureScale();
|
|
370
385
|
this.reportDimensions();
|
|
371
386
|
}
|
|
372
387
|
}
|
|
373
388
|
|
|
374
389
|
/**
|
|
375
390
|
* Report scale dimensions to parent chart component.
|
|
376
|
-
*
|
|
377
|
-
*
|
|
391
|
+
* When fixedAspectRatio=true, reports the actual visual (scaled) thickness
|
|
392
|
+
* so the chart can correctly reserve space for the scale.
|
|
393
|
+
* When fixedAspectRatio=false, reports the base/unscaled thickness.
|
|
378
394
|
*/
|
|
379
395
|
private reportDimensions() {
|
|
380
396
|
const effectiveBarThickness = computeExternalScaleEffectiveBarThickness({
|
|
@@ -393,7 +409,7 @@ export class ObcGaugeVertical extends AdviceMixin(
|
|
|
393
409
|
barThickness: effectiveBarThickness,
|
|
394
410
|
tickThickness: this.tickThickness,
|
|
395
411
|
labelThickness: this.labelThickness,
|
|
396
|
-
length: this.height,
|
|
412
|
+
length: this.fixedAspectRatio ? this.scaleReferenceSize : this.height,
|
|
397
413
|
scaleType: this.scaleType,
|
|
398
414
|
hasAdviceIcon: !!this.advices?.some((a) => a.showIcon),
|
|
399
415
|
hasSetpoint:
|
|
@@ -402,10 +418,14 @@ export class ObcGaugeVertical extends AdviceMixin(
|
|
|
402
418
|
this.departingNewSetpoint !== undefined,
|
|
403
419
|
});
|
|
404
420
|
|
|
405
|
-
//
|
|
406
|
-
//
|
|
407
|
-
|
|
408
|
-
|
|
421
|
+
// The chart lays out in visual pixels, so a scaled drawing reports its
|
|
422
|
+
// scaled thickness.
|
|
423
|
+
const dimensions = this.fixedAspectRatio
|
|
424
|
+
? {
|
|
425
|
+
...baseDimensions,
|
|
426
|
+
thickness: Math.round(baseDimensions.thickness * this._scale),
|
|
427
|
+
}
|
|
428
|
+
: baseDimensions;
|
|
409
429
|
|
|
410
430
|
this.dispatchEvent(
|
|
411
431
|
new CustomEvent('scale-dimensions-changed', {
|
|
@@ -418,6 +438,74 @@ export class ObcGaugeVertical extends AdviceMixin(
|
|
|
418
438
|
protected override createRenderRoot() {
|
|
419
439
|
return this;
|
|
420
440
|
}
|
|
441
|
+
|
|
442
|
+
override connectedCallback(): void {
|
|
443
|
+
super.connectedCallback();
|
|
444
|
+
if (this.fixedAspectRatio) {
|
|
445
|
+
this._applyFixedAspectRatioStyles();
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/** The inline sizing, value and priority, the consumer had before fixedAspectRatio took the host. */
|
|
450
|
+
private _consumerSizing?: Record<
|
|
451
|
+
'display' | 'height' | 'width',
|
|
452
|
+
[value: string, priority: string]
|
|
453
|
+
>;
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* A custom element is inline by default, which gives the percentage-sized
|
|
457
|
+
* SVG nothing to fill; in fixedAspectRatio mode the host is a block that
|
|
458
|
+
* takes its container's height.
|
|
459
|
+
*/
|
|
460
|
+
private _applyFixedAspectRatioStyles(): void {
|
|
461
|
+
if (!this._consumerSizing) {
|
|
462
|
+
const snapshot = (name: string): [string, string] => [
|
|
463
|
+
this.style.getPropertyValue(name),
|
|
464
|
+
this.style.getPropertyPriority(name),
|
|
465
|
+
];
|
|
466
|
+
this._consumerSizing = {
|
|
467
|
+
display: snapshot('display'),
|
|
468
|
+
height: snapshot('height'),
|
|
469
|
+
width: snapshot('width'),
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
this.style.display = 'block';
|
|
473
|
+
this.style.height = '100%';
|
|
474
|
+
this.style.width = 'auto';
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
private _removeFixedAspectRatioStyles(): void {
|
|
478
|
+
const saved = this._consumerSizing;
|
|
479
|
+
this._consumerSizing = undefined;
|
|
480
|
+
for (const name of ['display', 'height', 'width'] as const) {
|
|
481
|
+
const [value, priority] = saved?.[name] ?? ['', ''];
|
|
482
|
+
this.style.setProperty(name, value, priority);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/** Reads the host's content box into the scale; false while the host has no size yet. */
|
|
487
|
+
private _measureScale(): boolean {
|
|
488
|
+
const {width, height} = readContentBox(this);
|
|
489
|
+
if (height <= 0) return false;
|
|
490
|
+
this._scale = computeFixedAspectRatioScale({
|
|
491
|
+
orientation: ExternalScaleOrientation.vertical,
|
|
492
|
+
containerMainAxisSize: height,
|
|
493
|
+
containerCrossAxisSize: width,
|
|
494
|
+
scaleReferenceSize: this.scaleReferenceSize,
|
|
495
|
+
viewBoxThickness: this._viewBoxThickness,
|
|
496
|
+
});
|
|
497
|
+
return true;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** Measures once layout has settled, then reports. */
|
|
501
|
+
private _updateScaleFromCurrentSize(): void {
|
|
502
|
+
requestAnimationFrame(() => {
|
|
503
|
+
if (this._measureScale()) {
|
|
504
|
+
this.requestUpdate();
|
|
505
|
+
this.reportDimensions();
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
}
|
|
421
509
|
}
|
|
422
510
|
|
|
423
511
|
declare global {
|