@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.
- package/bundle/openbridge-webcomponents.bundle.js +269 -67
- package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
- package/custom-elements.json +257 -14
- 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/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/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/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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { customElement } from "../../decorator.js";
|
|
2
2
|
import { CHART_DIMENSIONS } from "../../charthelpers/constants.js";
|
|
3
3
|
import { BorderRadiusPosition, FrameStyle, InstrumentState, Priority } from "../types.js";
|
|
4
|
-
import { AdvicePosition, ExternalScaleOrientation, ExternalScaleSide, FillMode, ScaleType, computeExternalScaleEffectiveBarThickness, computeExternalScaleLayout, computeExternalScaleViewBox, computeFixedAspectRatioScale, computeScaleDimensionsForReport, renderExternalScale, toExternalScaleLayoutConfig } from "../../building-blocks/external-scale/external-scale.js";
|
|
4
|
+
import { AdvicePosition, ExternalScaleOrientation, ExternalScaleSide, FillMode, ScaleType, computeExternalScaleEffectiveBarThickness, computeExternalScaleLayout, computeExternalScaleViewBox, computeFixedAspectRatioScale, computeScaleDimensionsForReport, readContentBox, renderExternalScale, toExternalScaleLayoutConfig } from "../../building-blocks/external-scale/external-scale.js";
|
|
5
5
|
import { SetpointMixin } from "../../svghelpers/setpoint-mixin.js";
|
|
6
6
|
import { AdviceMixin } from "../../svghelpers/advice-mixin.js";
|
|
7
7
|
import { nextAdviceMaskId } from "../../svghelpers/advice.js";
|
|
@@ -23,15 +23,17 @@ var ObcGaugeVertical = class ObcGaugeVertical extends AdviceMixin(SetpointMixin(
|
|
|
23
23
|
this.fixedAspectRatio = false;
|
|
24
24
|
this.scaleReferenceSize = 384;
|
|
25
25
|
this._scale = 1;
|
|
26
|
+
this._viewBoxThickness = 0;
|
|
26
27
|
this._resizeController = new ResizeController(this, { callback: (entries) => {
|
|
27
28
|
if (!this.fixedAspectRatio) return;
|
|
28
29
|
const entry = entries[0];
|
|
29
30
|
if (!entry) return;
|
|
30
|
-
const containerMainAxisSize = entry.contentRect.height;
|
|
31
31
|
const scale = computeFixedAspectRatioScale({
|
|
32
32
|
orientation: ExternalScaleOrientation.vertical,
|
|
33
|
-
containerMainAxisSize,
|
|
34
|
-
|
|
33
|
+
containerMainAxisSize: entry.contentRect.height,
|
|
34
|
+
containerCrossAxisSize: entry.contentRect.width,
|
|
35
|
+
scaleReferenceSize: this.scaleReferenceSize,
|
|
36
|
+
viewBoxThickness: this._viewBoxThickness
|
|
35
37
|
});
|
|
36
38
|
this._scale = scale > 0 ? scale : 1;
|
|
37
39
|
this.reportDimensions();
|
|
@@ -69,10 +71,11 @@ var ObcGaugeVertical = class ObcGaugeVertical extends AdviceMixin(SetpointMixin(
|
|
|
69
71
|
return true;
|
|
70
72
|
}
|
|
71
73
|
render() {
|
|
74
|
+
const effectiveLength = this.fixedAspectRatio ? this.scaleReferenceSize : this.height;
|
|
72
75
|
const config = {
|
|
73
76
|
orientation: ExternalScaleOrientation.vertical,
|
|
74
77
|
side: this.side,
|
|
75
|
-
length:
|
|
78
|
+
length: effectiveLength,
|
|
76
79
|
paddingStart: this.paddingTop,
|
|
77
80
|
paddingEnd: this.paddingBottom,
|
|
78
81
|
minValue: this.minValue,
|
|
@@ -119,10 +122,11 @@ var ObcGaugeVertical = class ObcGaugeVertical extends AdviceMixin(SetpointMixin(
|
|
|
119
122
|
highlightCurrentValue: this.highlightCurrentValue
|
|
120
123
|
};
|
|
121
124
|
const layout = computeExternalScaleLayout(toExternalScaleLayoutConfig(config));
|
|
125
|
+
this._viewBoxThickness = layout.thickness;
|
|
122
126
|
const parts = renderExternalScale(config);
|
|
123
127
|
const viewBox = computeExternalScaleViewBox({
|
|
124
128
|
orientation: config.orientation,
|
|
125
|
-
length:
|
|
129
|
+
length: effectiveLength
|
|
126
130
|
}, layout);
|
|
127
131
|
const preserveAspectRatio = this.fixedAspectRatio ? "xMidYMid meet" : "none";
|
|
128
132
|
return html`
|
|
@@ -146,12 +150,26 @@ var ObcGaugeVertical = class ObcGaugeVertical extends AdviceMixin(SetpointMixin(
|
|
|
146
150
|
}
|
|
147
151
|
updated(changed) {
|
|
148
152
|
super.updated(changed);
|
|
149
|
-
if (
|
|
153
|
+
if (changed.has("fixedAspectRatio")) {
|
|
154
|
+
if (this.fixedAspectRatio) {
|
|
155
|
+
this._applyFixedAspectRatioStyles();
|
|
156
|
+
this._updateScaleFromCurrentSize();
|
|
157
|
+
} else if (changed.get("fixedAspectRatio") === true) {
|
|
158
|
+
this._removeFixedAspectRatioStyles();
|
|
159
|
+
this._scale = 1;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (changed.has("scaleReferenceSize") && this.fixedAspectRatio) this._updateScaleFromCurrentSize();
|
|
163
|
+
if (changed.has("fixedAspectRatio") || changed.has("side") || changed.has("showLabels") || changed.has("advices") || this.setpointPresenceChanged(changed)) {
|
|
164
|
+
if (this.fixedAspectRatio) this._measureScale();
|
|
165
|
+
this.reportDimensions();
|
|
166
|
+
}
|
|
150
167
|
}
|
|
151
168
|
/**
|
|
152
169
|
* Report scale dimensions to parent chart component.
|
|
153
|
-
*
|
|
154
|
-
*
|
|
170
|
+
* When fixedAspectRatio=true, reports the actual visual (scaled) thickness
|
|
171
|
+
* so the chart can correctly reserve space for the scale.
|
|
172
|
+
* When fixedAspectRatio=false, reports the base/unscaled thickness.
|
|
155
173
|
*/
|
|
156
174
|
reportDimensions() {
|
|
157
175
|
const effectiveBarThickness = computeExternalScaleEffectiveBarThickness({
|
|
@@ -160,7 +178,7 @@ var ObcGaugeVertical = class ObcGaugeVertical extends AdviceMixin(SetpointMixin(
|
|
|
160
178
|
borderRadius: this.borderRadius,
|
|
161
179
|
scaleType: this.scaleType
|
|
162
180
|
});
|
|
163
|
-
const
|
|
181
|
+
const baseDimensions = computeScaleDimensionsForReport({
|
|
164
182
|
orientation: ExternalScaleOrientation.vertical,
|
|
165
183
|
side: this.side,
|
|
166
184
|
hasBar: this.hasBar,
|
|
@@ -169,11 +187,15 @@ var ObcGaugeVertical = class ObcGaugeVertical extends AdviceMixin(SetpointMixin(
|
|
|
169
187
|
barThickness: effectiveBarThickness,
|
|
170
188
|
tickThickness: this.tickThickness,
|
|
171
189
|
labelThickness: this.labelThickness,
|
|
172
|
-
length: this.height,
|
|
190
|
+
length: this.fixedAspectRatio ? this.scaleReferenceSize : this.height,
|
|
173
191
|
scaleType: this.scaleType,
|
|
174
192
|
hasAdviceIcon: !!this.advices?.some((a) => a.showIcon),
|
|
175
193
|
hasSetpoint: this.setpoint !== void 0 || this.newSetpoint !== void 0 || this.departingNewSetpoint !== void 0
|
|
176
194
|
});
|
|
195
|
+
const dimensions = this.fixedAspectRatio ? {
|
|
196
|
+
...baseDimensions,
|
|
197
|
+
thickness: Math.round(baseDimensions.thickness * this._scale)
|
|
198
|
+
} : baseDimensions;
|
|
177
199
|
this.dispatchEvent(new CustomEvent("scale-dimensions-changed", {
|
|
178
200
|
detail: dimensions,
|
|
179
201
|
bubbles: true
|
|
@@ -182,11 +204,69 @@ var ObcGaugeVertical = class ObcGaugeVertical extends AdviceMixin(SetpointMixin(
|
|
|
182
204
|
createRenderRoot() {
|
|
183
205
|
return this;
|
|
184
206
|
}
|
|
207
|
+
connectedCallback() {
|
|
208
|
+
super.connectedCallback();
|
|
209
|
+
if (this.fixedAspectRatio) this._applyFixedAspectRatioStyles();
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* A custom element is inline by default, which gives the percentage-sized
|
|
213
|
+
* SVG nothing to fill; in fixedAspectRatio mode the host is a block that
|
|
214
|
+
* takes its container's height.
|
|
215
|
+
*/
|
|
216
|
+
_applyFixedAspectRatioStyles() {
|
|
217
|
+
if (!this._consumerSizing) {
|
|
218
|
+
const snapshot = (name) => [this.style.getPropertyValue(name), this.style.getPropertyPriority(name)];
|
|
219
|
+
this._consumerSizing = {
|
|
220
|
+
display: snapshot("display"),
|
|
221
|
+
height: snapshot("height"),
|
|
222
|
+
width: snapshot("width")
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
this.style.display = "block";
|
|
226
|
+
this.style.height = "100%";
|
|
227
|
+
this.style.width = "auto";
|
|
228
|
+
}
|
|
229
|
+
_removeFixedAspectRatioStyles() {
|
|
230
|
+
const saved = this._consumerSizing;
|
|
231
|
+
this._consumerSizing = void 0;
|
|
232
|
+
for (const name of [
|
|
233
|
+
"display",
|
|
234
|
+
"height",
|
|
235
|
+
"width"
|
|
236
|
+
]) {
|
|
237
|
+
const [value, priority] = saved?.[name] ?? ["", ""];
|
|
238
|
+
this.style.setProperty(name, value, priority);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/** Reads the host's content box into the scale; false while the host has no size yet. */
|
|
242
|
+
_measureScale() {
|
|
243
|
+
const { width, height } = readContentBox(this);
|
|
244
|
+
if (height <= 0) return false;
|
|
245
|
+
this._scale = computeFixedAspectRatioScale({
|
|
246
|
+
orientation: ExternalScaleOrientation.vertical,
|
|
247
|
+
containerMainAxisSize: height,
|
|
248
|
+
containerCrossAxisSize: width,
|
|
249
|
+
scaleReferenceSize: this.scaleReferenceSize,
|
|
250
|
+
viewBoxThickness: this._viewBoxThickness
|
|
251
|
+
});
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
/** Measures once layout has settled, then reports. */
|
|
255
|
+
_updateScaleFromCurrentSize() {
|
|
256
|
+
requestAnimationFrame(() => {
|
|
257
|
+
if (this._measureScale()) {
|
|
258
|
+
this.requestUpdate();
|
|
259
|
+
this.reportDimensions();
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
185
263
|
};
|
|
186
264
|
__decorate([property({ type: Number })], ObcGaugeVertical.prototype, "minValue", void 0);
|
|
187
265
|
__decorate([property({ type: Number })], ObcGaugeVertical.prototype, "maxValue", void 0);
|
|
188
266
|
__decorate([property({ type: Boolean })], ObcGaugeVertical.prototype, "reverse", void 0);
|
|
189
267
|
__decorate([property({ type: String })], ObcGaugeVertical.prototype, "side", void 0);
|
|
268
|
+
__decorate([property({ type: Boolean })], ObcGaugeVertical.prototype, "fixedAspectRatio", void 0);
|
|
269
|
+
__decorate([property({ type: Number })], ObcGaugeVertical.prototype, "scaleReferenceSize", void 0);
|
|
190
270
|
__decorate([state()], ObcGaugeVertical.prototype, "_scale", void 0);
|
|
191
271
|
__decorate([property({
|
|
192
272
|
type: Boolean,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gauge-vertical.js","names":["_decorate"],"sources":["../../../src/navigation-instruments/gauge-vertical/gauge-vertical.ts"],"sourcesContent":["import {LitElement, html} from 'lit';\nimport {property, state} from 'lit/decorators.js';\nimport type {PropertyValues} from 'lit';\nimport {customElement} from '../../decorator.js';\nimport {ResizeController} from '@lit-labs/observers/resize-controller.js';\nimport {CHART_DIMENSIONS} from '../../charthelpers/constants.js';\nimport {\n InstrumentState,\n FrameStyle,\n BorderRadiusPosition,\n Priority,\n} from '../types.js';\nimport type {ExternalScaleConfig} from '../../building-blocks/external-scale/external-scale.js';\nimport {\n computeExternalScaleViewBox,\n computeFixedAspectRatioScale,\n computeExternalScaleLayout,\n renderExternalScale,\n toExternalScaleLayoutConfig,\n computeScaleDimensionsForReport,\n computeExternalScaleEffectiveBarThickness,\n ScaleType,\n FillMode,\n AdvicePosition,\n ExternalScaleOrientation,\n ExternalScaleSide,\n} from '../../building-blocks/external-scale/external-scale.js';\nimport {SetpointMixin} from '../../svghelpers/setpoint-mixin.js';\nimport {AdviceMixin} from '../../svghelpers/advice-mixin.js';\nimport {nextAdviceMaskId} from '../../svghelpers/advice.js';\n\n// Re-export shared enums for convenience\nexport {\n ScaleType,\n FillMode,\n AdvicePosition,\n FrameStyle,\n BorderRadiusPosition,\n InstrumentState,\n ExternalScaleSide,\n};\n\n/**\n * `<obc-gauge-vertical>` – A vertical gauge component with bar and scale background.\n *\n * Use `obc-gauge-vertical` when you need a standalone vertical gauge with a visible scale\n * and bar. This is ideal for displaying single values like tank levels, pressure, or\n * temperature where the scale context is always needed.\n *\n * This is the same as `obc-bar-vertical` (both use `external-scale.ts`)\n * but with several properties fixed for consistent gauge appearance.\n * Unlike `obc-bar-vertical`, this component always shows the bar and scale background.\n *\n * ---\n *\n * ### Features\n * - **Fixed Layout:** Height (384px), padding (32px), bar/tick/label thicknesses, and border radius are fixed for consistent gauge appearance.\n * - **Scale Configuration:**\n * - Configurable `minValue` and `maxValue` for the value range.\n * - Optional main, primary, secondary, and tertiary tickmarks at specified intervals.\n * - Labels shown at primary tickmark intervals (controlled via `showLabels`).\n * - **Side Positioning:** Can be placed on the `left` or `right` side via the `side` property.\n * - **Value Display:**\n * - `value` property drives the bar fill.\n * - `fillMode` controls visualization: `fill` shows bar from `fillMin` to `fillMax`; `tint` adds a marker at the `value` position.\n * - Set `priority` to `Priority.enhanced` to use the blue/enhanced color palette for bar fill and setpoint (default: `Priority.regular`).\n * - **Setpoint Marker:**\n * - Optional `setpoint` value displays a marker.\n * - Automatic at-setpoint detection with configurable deadband.\n * - **Advice Overlays:** Render advice ranges with different types and hinted states.\n * - **Fixed Aspect Ratio:** When enabled, scales the component proportionally while keeping label font-size constant.\n * - **Dimension Reporting:** Dispatches `scale-dimensions-changed` events for parent chart integration.\n *\n * ---\n *\n * ### Fixed Properties (not configurable)\n * - `height`: 384px\n * - `paddingTop`/`paddingBottom`: 32px (`CHART_DIMENSIONS.CANVAS_PADDING`)\n * - `barThickness`: 48px\n * - `tickThickness`: 24px\n * - `labelThickness`: 60px\n * - `borderRadius`: 8px (matches obc-component-size-medium)\n * - `scaleType`: regular\n * - `frameStyle`: regular\n * - `hasBar`: true\n * - `hasScale`: true\n * - `scaleBackground`: true\n * - `fixedAspectRatio`: true (always scales proportionally)\n *\n * ---\n *\n * ### Implementation\n * This is a higher fidelity implementation of the concept shown in `instrument-linear.ts`,\n * providing a complete gauge with container, scale background, tickmarks, labels, advice overlays, and setpoint marker.\n *\n * This is a thin web-component wrapper around the pure SVG building-block renderer in `external-scale.ts`.\n * It sets up the outer `<svg>`/`viewBox` for a vertical scale and delegates rendering/layout to:\n * - `computeExternalScaleLayout(...)`\n * - `renderExternalScale(config)`\n *\n * For renderer documentation see: **Building Blocks/External Scale**.\n *\n * For a version where these properties are user-configurable, see **Bars and Graphs/Bar Vertical**.\n *\n * ---\n *\n * ### Events\n * - `scale-dimensions-changed` – Fired when layout-affecting properties (`side`, `showLabels`) change, reporting dimensions to parent chart components.\n *\n * ---\n *\n * ### Example\n *\n * ```html\n * <obc-gauge-vertical\n * min-value=\"0\"\n * max-value=\"100\"\n * value=\"75\"\n * primary-tickmark-interval=\"20\"\n * secondary-tickmark-interval=\"10\"\n * setpoint=\"80\"\n * side=\"right\"\n * ></obc-gauge-vertical>\n * ```\n *\n * @property minValue - Minimum scale value\n * @property maxValue - Maximum scale value\n * @property reverse - Plot `minValue` at the top so values grow downward.\n * @property side - Which side of the chart area this scale lives on (left or right)\n * @property showLabels - Show numerical value labels at primary tickmarks\n * @property mainTickmarks - Array of values for main tickmarks. When undefined, no main tickmarks shown. When empty array [], defaults to [minValue, 0, maxValue].\n * @property primaryTickmarkInterval - Interval for primary (longest) tickmarks with labels\n * @property secondaryTickmarkInterval - Interval for secondary (medium) tickmarks\n * @property tertiaryTickmarkInterval - Interval for tertiary (shortest) tickmarks\n * @property borderRadiusPosition - Border radius position based on component layout\n * @property priority - Color priority: enhanced uses blue instrument colors for bar fill and setpoint\n * @property fillMode - Fill visualization mode: 'fill' shows bar from fillMin to fillMax; 'tint' adds a marker at the value position\n * @property fillMin - Minimum fill value (defaults to 0)\n * @property fillMax - Maximum fill value (defaults to value)\n * @property value - Current value (bar fill level)\n * @property state - Instrument state: active, loading, or off\n * @property advices - Advice/alert overlays with min, max, type, and hinted state. When undefined or empty, no advice shown.\n * @property highlightCurrentValue - When true, displays a dot indicator at the current value position.\n * The dot is rendered in the scale band, touching its inner edge (towards the chart).\n * This provides an alternative to bar fill for highlighting the current value.\n * @property focused - Earlier name for `touching`: a change to it sets `touching`, unless `touching` changes in the same update, which then wins. It is not updated from `touching`, so it does not read back the current value.\n * @fires {CustomEvent} scale-dimensions-changed - Fired when layout-affecting properties change, providing dimension info for parent chart integration. It bubbles to the chart slot the gauge sits in and does not leave the shadow root around it.\n * @stable\n */\n@customElement('obc-gauge-vertical')\nexport class ObcGaugeVertical extends AdviceMixin(\n SetpointMixin(LitElement, {\n defaultDeadband: 1,\n })\n) {\n @property({type: Number}) minValue = 0;\n @property({type: Number}) maxValue = 100;\n @property({type: Boolean}) reverse = false;\n\n private readonly height = 384;\n private readonly paddingTop = CHART_DIMENSIONS.CANVAS_PADDING;\n private readonly paddingBottom = CHART_DIMENSIONS.CANVAS_PADDING;\n\n @property({type: String}) side: ExternalScaleSide = ExternalScaleSide.right;\n\n /**\n * When true, freezes all internal calculations and scales the entire component\n * proportionally (like CSS transform:scale), except label font-size remains constant.\n * When false (default), dimensions react to component properties.\n *\n * This property is intentionally not exposed as a public API or Storybook control.\n * It can be set programmatically by parent components (e.g., GaugeTrend).\n */\n fixedAspectRatio = false;\n\n /**\n * Reference size for proportional scaling when fixedAspectRatio is true.\n * At this height, the scale renders at native 1:1 (matches Figma design).\n * Above this height, the scale grows proportionally; below, it shrinks.\n * @default 384\n */\n scaleReferenceSize = 384;\n\n @state()\n private _scale = 1;\n\n // ResizeController automatically subscribes/unsubscribes based on component lifecycle\n // @ts-expect-error - Controller is used for side effects, not accessed directly\n private _resizeController = new ResizeController(this, {\n callback: (entries) => {\n if (!this.fixedAspectRatio) return;\n\n const entry = entries[0];\n if (!entry) return;\n\n // Use the centralized function that computes scale based on reference size\n // For vertical scales, compare container height to reference size\n const containerMainAxisSize = entry.contentRect.height;\n\n const scale = computeFixedAspectRatioScale({\n orientation: ExternalScaleOrientation.vertical,\n containerMainAxisSize,\n scaleReferenceSize: this.scaleReferenceSize,\n });\n // Guard against zero-sized containers, but allow fractional scales < 1\n this._scale = scale > 0 ? scale : 1;\n\n // Report scaled dimensions to parent chart\n this.reportDimensions();\n },\n });\n\n @property({type: Boolean, attribute: false}) showLabels = true;\n private readonly barThickness = 48;\n private readonly tickThickness = 24;\n private readonly labelThickness = 60;\n\n @property({type: Array, attribute: false}) mainTickmarks?: number[] = [];\n @property({type: Number}) primaryTickmarkInterval?: number = undefined;\n @property({type: Number}) secondaryTickmarkInterval?: number = undefined;\n @property({type: Number}) tertiaryTickmarkInterval?: number = undefined;\n private readonly scaleType: ScaleType = ScaleType.regular;\n private readonly frameStyle: FrameStyle = FrameStyle.regular;\n @property({type: String, attribute: false})\n borderRadiusPosition?: BorderRadiusPosition =\n BorderRadiusPosition.innerFirstChild;\n\n private readonly borderRadius = 8;\n\n private get hasBar(): boolean {\n return true;\n }\n\n private get scaleBackground(): boolean {\n return true;\n }\n\n private get hasScale(): boolean {\n return true;\n }\n\n @property({type: String}) priority: Priority = Priority.regular;\n @property({type: String}) fillMode: FillMode = FillMode.fill;\n @property({type: Number}) fillMin?: number = undefined;\n @property({type: Number}) fillMax?: number = undefined;\n @property({type: Number}) value?: number = undefined;\n\n @property({type: String}) state: InstrumentState = InstrumentState.active;\n\n /**\n * @deprecated Use `touching` (from SetpointMixin) instead.\n * Kept for backward compatibility. Synced to `touching` in `willUpdate()`.\n */\n @property({type: Boolean}) focused = false;\n\n private readonly advicePosition: AdvicePosition = AdvicePosition.inner;\n // Mask ids are document-scoped, so each gauge names its own.\n private readonly _adviceMaskPrefix = nextAdviceMaskId('gauge');\n\n @property({type: Boolean}) highlightCurrentValue = false;\n\n override render() {\n const config: ExternalScaleConfig = {\n orientation: ExternalScaleOrientation.vertical,\n side: this.side,\n length: this.height,\n paddingStart: this.paddingTop,\n paddingEnd: this.paddingBottom,\n minValue: this.minValue,\n maxValue: this.maxValue,\n reverse: this.reverse,\n hasScale: this.hasScale,\n labels: this.showLabels,\n hasBar: this.hasBar,\n scaleBackground: this.scaleBackground,\n barThickness: this.barThickness,\n tickThickness: this.tickThickness,\n labelThickness: this.labelThickness,\n mainTickmarks: this.mainTickmarks,\n primaryTickmarkInterval: this.primaryTickmarkInterval,\n secondaryTickmarkInterval: this.secondaryTickmarkInterval,\n tertiaryTickmarkInterval: this.tertiaryTickmarkInterval,\n scaleType: this.scaleType,\n frameStyle: this.frameStyle,\n borderRadiusPosition: this.borderRadiusPosition,\n borderRadius: this.borderRadius,\n priority: this.priority,\n fillMode: this.fillMode,\n fillMin: this.fillMin,\n fillMax: this.fillMax,\n value: this.value,\n setpoint: this.setpoint,\n newSetpoint: this.newSetpoint,\n atSetpoint: this.atSetpoint,\n autoAtSetpoint: this.autoAtSetpoint,\n autoAtSetpointDeadband: this.autoAtSetpointDeadband,\n setpointAtZeroDeadband: this.setpointAtZeroDeadband,\n animateSetpoint: this.animateSetpoint,\n departingNewSetpoint: this.departingNewSetpoint,\n state: this.state,\n touching: this.touching,\n setpointOverride: this.setpointOverride,\n advicePosition: this.advicePosition,\n advices: this.advices,\n adviceTrigger: this.adviceTrigger,\n adviceEmphasis: this.adviceEmphasis,\n adviceMaskPrefix: this._adviceMaskPrefix,\n fixedAspectRatio: this.fixedAspectRatio,\n // Gauges are always in instrument mode - they use fixed borderRadius (8px)\n // and don't respond to .obc-component-size-* CSS classes for border radius\n instrumentMode: true,\n highlightCurrentValue: this.highlightCurrentValue,\n };\n\n const layout = computeExternalScaleLayout(\n toExternalScaleLayoutConfig(config)\n );\n\n const parts = renderExternalScale(config);\n\n const viewBox = computeExternalScaleViewBox(\n {orientation: config.orientation, length: this.height},\n layout\n );\n const preserveAspectRatio = this.fixedAspectRatio\n ? 'xMidYMid meet'\n : 'none';\n\n return html`\n <svg\n width=${this.fixedAspectRatio ? '100%' : `${viewBox.width}px`}\n height=${this.fixedAspectRatio ? '100%' : `${this.height}px`}\n viewBox=\"${viewBox.x} ${viewBox.y} ${viewBox.width} ${viewBox.height}\"\n preserveAspectRatio=\"${preserveAspectRatio}\"\n style=\"--scale: ${\n this.fixedAspectRatio ? this._scale : 1\n }; display: block;\"\n part=\"svg\"\n >\n ${parts.barContainer} ${parts.barFill} ${parts.scaleBackground}\n ${parts.tickmarks} ${parts.labels} ${parts.adviceOverlays}\n ${parts.currentValueDot} ${parts.setpoint}\n </svg>\n `;\n }\n\n override willUpdate(changed: PropertyValues): void {\n super.willUpdate(changed);\n\n // Sync deprecated alias to mixin property\n // Only sync if the alias was set and the mixin property was NOT also set.\n if (changed.has('focused') && !changed.has('touching')) {\n this.touching = this.focused;\n }\n }\n\n override updated(changed: PropertyValues) {\n super.updated(changed);\n\n // Report dimensions to parent chart\n // In fixedAspectRatio mode, we report after resize events trigger _scale updates\n // In regular mode, only emit when layout-affecting properties change\n // Setpoint presence changes the reported thickness (reserved marker band),\n // so it must re-report in both aspect-ratio modes.\n if (\n (!this.fixedAspectRatio &&\n (changed.has('side') || changed.has('showLabels'))) ||\n this.setpointPresenceChanged(changed)\n ) {\n this.reportDimensions();\n }\n }\n\n /**\n * Report scale dimensions to parent chart component.\n * Always reports unscaled/reference dimensions so the parent chart can apply\n * consistent proportional scaling in fixedAspectRatioScaling mode.\n */\n private reportDimensions() {\n const effectiveBarThickness = computeExternalScaleEffectiveBarThickness({\n hasBar: this.hasBar,\n barThickness: this.barThickness,\n borderRadius: this.borderRadius,\n scaleType: this.scaleType,\n });\n\n const baseDimensions = computeScaleDimensionsForReport({\n orientation: ExternalScaleOrientation.vertical,\n side: this.side,\n hasBar: this.hasBar,\n hasScale: this.hasScale,\n labels: this.showLabels,\n barThickness: effectiveBarThickness,\n tickThickness: this.tickThickness,\n labelThickness: this.labelThickness,\n length: this.height,\n scaleType: this.scaleType,\n hasAdviceIcon: !!this.advices?.some((a) => a.showIcon),\n hasSetpoint:\n this.setpoint !== undefined ||\n this.newSetpoint !== undefined ||\n this.departingNewSetpoint !== undefined,\n });\n\n // Always report unscaled/reference dimensions.\n // The parent chart component handles proportional scaling consistently\n // for both external scales and chart padding in fixedAspectRatioScaling mode.\n const dimensions = baseDimensions;\n\n this.dispatchEvent(\n new CustomEvent('scale-dimensions-changed', {\n detail: dimensions,\n bubbles: true,\n })\n );\n }\n\n protected override createRenderRoot() {\n return this;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'obc-gauge-vertical': ObcGaugeVertical;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAsJO,IAAM,mBAAN,MAAM,yBAAyB,YACpC,cAAc,YAAY,EACxB,iBAAiB,EACnB,CAAC,CACH,CAAC,CAAC;;;EACqC,KAAA,WAAA;EACA,KAAA,WAAA;EACA,KAAA,UAAA;EAEX,KAAA,SAAA;EACI,KAAA,aAAA,iBAAiB;EACd,KAAA,gBAAA,iBAAiB;EAEE,KAAA,OAAA,kBAAkB;EAUnD,KAAA,mBAAA;EAQE,KAAA,qBAAA;EAGJ,KAAA,SAAA;EAIW,KAAA,oBAAA,IAAI,iBAAiB,MAAM,EACrD,WAAW,YAAY;GACrB,IAAI,CAAC,KAAK,kBAAkB;GAE5B,MAAM,QAAQ,QAAQ;GACtB,IAAI,CAAC,OAAO;GAIZ,MAAM,wBAAwB,MAAM,YAAY;GAEhD,MAAM,QAAQ,6BAA6B;IACzC,aAAa,yBAAyB;IACtC;IACA,oBAAoB,KAAK;GAC3B,CAAC;GAED,KAAK,SAAS,QAAQ,IAAI,QAAQ;GAGlC,KAAK,iBAAiB;EACxB,EACF,CAAC;EAEyD,KAAA,aAAA;EAC1B,KAAA,eAAA;EACC,KAAA,gBAAA;EACC,KAAA,iBAAA;EAEoC,KAAA,gBAAA,CAAC;EACV,KAAA,0BAAA,KAAA;EACE,KAAA,4BAAA,KAAA;EACD,KAAA,2BAAA,KAAA;EACtB,KAAA,YAAA,UA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,CAAC,CAAA,GAAA,iBAAA,WAAA,6BAAA,KAAA,CAAA;AACvBA,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,iBAAA,WAAA,4BAAA,KAAA,CAAA;AAGvBA,WAAA,CAAA,SAAS;CAAC,MAAM;CAAQ,WAAW;AAAK,CAAC,CAAA,GAAA,iBAAA,WAAA,wBAAA,KAAA,CAAA;AAkBzCA,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,iBAAA,WAAA,YAAA,KAAA,CAAA;AACvBA,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,iBAAA,WAAA,YAAA,KAAA,CAAA;AACvBA,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,iBAAA,WAAA,WAAA,KAAA,CAAA;AACvBA,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,iBAAA,WAAA,WAAA,KAAA,CAAA;AACvBA,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,iBAAA,WAAA,SAAA,KAAA,CAAA;AAEvBA,WAAA,CAAA,SAAS,EAAC,MAAM,OAAM,CAAC,CAAA,GAAA,iBAAA,WAAA,SAAA,KAAA,CAAA;AAMvBA,WAAA,CAAA,SAAS,EAAC,MAAM,QAAO,CAAC,CAAA,GAAA,iBAAA,WAAA,WAAA,KAAA,CAAA;AAMxBA,WAAA,CAAA,SAAS,EAAC,MAAM,QAAO,CAAC,CAAA,GAAA,iBAAA,WAAA,yBAAA,KAAA,CAAA;AA9G1B,mBAAAA,WAAA,CAAA,cAAc,oBAAoB,CAAA,GAAA,gBAAA"}
|
|
1
|
+
{"version":3,"file":"gauge-vertical.js","names":["_decorate"],"sources":["../../../src/navigation-instruments/gauge-vertical/gauge-vertical.ts"],"sourcesContent":["import {LitElement, html} from 'lit';\nimport {property, state} from 'lit/decorators.js';\nimport type {PropertyValues} from 'lit';\nimport {customElement} from '../../decorator.js';\nimport {ResizeController} from '@lit-labs/observers/resize-controller.js';\nimport {CHART_DIMENSIONS} from '../../charthelpers/constants.js';\nimport {\n InstrumentState,\n FrameStyle,\n BorderRadiusPosition,\n Priority,\n} from '../types.js';\nimport type {ExternalScaleConfig} from '../../building-blocks/external-scale/external-scale.js';\nimport {\n computeExternalScaleViewBox,\n computeFixedAspectRatioScale,\n computeExternalScaleLayout,\n renderExternalScale,\n toExternalScaleLayoutConfig,\n computeScaleDimensionsForReport,\n computeExternalScaleEffectiveBarThickness,\n readContentBox,\n ScaleType,\n FillMode,\n AdvicePosition,\n ExternalScaleOrientation,\n ExternalScaleSide,\n} from '../../building-blocks/external-scale/external-scale.js';\nimport {SetpointMixin} from '../../svghelpers/setpoint-mixin.js';\nimport {AdviceMixin} from '../../svghelpers/advice-mixin.js';\nimport {nextAdviceMaskId} from '../../svghelpers/advice.js';\n\n// Re-export shared enums for convenience\nexport {\n ScaleType,\n FillMode,\n AdvicePosition,\n FrameStyle,\n BorderRadiusPosition,\n InstrumentState,\n ExternalScaleSide,\n};\n\n/**\n * `<obc-gauge-vertical>` – A vertical gauge component with bar and scale background.\n *\n * Use `obc-gauge-vertical` when you need a standalone vertical gauge with a visible scale\n * and bar. This is ideal for displaying single values like tank levels, pressure, or\n * temperature where the scale context is always needed.\n *\n * This is the same as `obc-bar-vertical` (both use `external-scale.ts`)\n * but with several properties fixed for consistent gauge appearance.\n * Unlike `obc-bar-vertical`, this component always shows the bar and scale background.\n *\n * ---\n *\n * ### Features\n * - **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`.\n * - **Scale Configuration:**\n * - Configurable `minValue` and `maxValue` for the value range.\n * - Optional main, primary, secondary, and tertiary tickmarks at specified intervals.\n * - Labels shown at primary tickmark intervals (controlled via `showLabels`).\n * - **Side Positioning:** Can be placed on the `left` or `right` side via the `side` property.\n * - **Value Display:**\n * - `value` property drives the bar fill.\n * - `fillMode` controls visualization: `fill` shows bar from `fillMin` to `fillMax`; `tint` adds a marker at the `value` position.\n * - Set `priority` to `Priority.enhanced` to use the blue/enhanced color palette for bar fill and setpoint (default: `Priority.regular`).\n * - **Setpoint Marker:**\n * - Optional `setpoint` value displays a marker.\n * - Automatic at-setpoint detection with configurable deadband.\n * - **Advice Overlays:** Render advice ranges with different types and hinted states.\n * - **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.\n * - **Dimension Reporting:** Dispatches `scale-dimensions-changed` events for parent chart integration.\n *\n * ---\n *\n * ### Fixed Properties (not configurable)\n * - `height`: 384px\n * - `paddingTop`/`paddingBottom`: 32px (`CHART_DIMENSIONS.CANVAS_PADDING`)\n * - `barThickness`: 48px\n * - `tickThickness`: 24px\n * - `labelThickness`: 60px\n * - `borderRadius`: 8px (matches obc-component-size-medium)\n * - `scaleType`: regular\n * - `frameStyle`: regular\n * - `hasBar`: true\n * - `hasScale`: true\n * - `scaleBackground`: true\n *\n * ---\n *\n * ### Implementation\n * This is a higher fidelity implementation of the concept shown in `instrument-linear.ts`,\n * providing a complete gauge with container, scale background, tickmarks, labels, advice overlays, and setpoint marker.\n *\n * This is a thin web-component wrapper around the pure SVG building-block renderer in `external-scale.ts`.\n * It sets up the outer `<svg>`/`viewBox` for a vertical scale and delegates rendering/layout to:\n * - `computeExternalScaleLayout(...)`\n * - `renderExternalScale(config)`\n *\n * For renderer documentation see: **Building Blocks/External Scale**.\n *\n * For a version where these properties are user-configurable, see **Bars and Graphs/Bar Vertical**.\n *\n * ---\n *\n * ### Events\n * - `scale-dimensions-changed` – Fired when layout-affecting properties (`side`, `showLabels`) change, reporting dimensions to parent chart components.\n *\n * ---\n *\n * ### Example\n *\n * ```html\n * <obc-gauge-vertical\n * min-value=\"0\"\n * max-value=\"100\"\n * value=\"75\"\n * primary-tickmark-interval=\"20\"\n * secondary-tickmark-interval=\"10\"\n * setpoint=\"80\"\n * side=\"right\"\n * ></obc-gauge-vertical>\n * ```\n *\n * @property minValue - Minimum scale value\n * @property maxValue - Maximum scale value\n * @property reverse - Plot `minValue` at the top so values grow downward.\n * @property side - Which side of the chart area this scale lives on (left or right)\n * @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.\n * @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.\n * @availableWhen scaleReferenceSize fixedAspectRatio==true\n * @property showLabels - Show numerical value labels at primary tickmarks\n * @property mainTickmarks - Array of values for main tickmarks. When undefined, no main tickmarks shown. When empty array [], defaults to [minValue, 0, maxValue].\n * @property primaryTickmarkInterval - Interval for primary (longest) tickmarks with labels\n * @property secondaryTickmarkInterval - Interval for secondary (medium) tickmarks\n * @property tertiaryTickmarkInterval - Interval for tertiary (shortest) tickmarks\n * @property borderRadiusPosition - Border radius position based on component layout\n * @property priority - Color priority: enhanced uses blue instrument colors for bar fill and setpoint\n * @property fillMode - Fill visualization mode: 'fill' shows bar from fillMin to fillMax; 'tint' adds a marker at the value position\n * @property fillMin - Minimum fill value (defaults to 0)\n * @property fillMax - Maximum fill value (defaults to value)\n * @property value - Current value (bar fill level)\n * @property state - Instrument state: active, loading, or off\n * @property advices - Advice/alert overlays with min, max, type, and hinted state. When undefined or empty, no advice shown.\n * @property highlightCurrentValue - When true, displays a dot indicator at the current value position.\n * The dot is rendered in the scale band, touching its inner edge (towards the chart).\n * This provides an alternative to bar fill for highlighting the current value.\n * @property focused - Earlier name for `touching`: a change to it sets `touching`, unless `touching` changes in the same update, which then wins. It is not updated from `touching`, so it does not read back the current value.\n * @fires {CustomEvent} scale-dimensions-changed - Fired when layout-affecting properties change, providing dimension info for parent chart integration. It bubbles to the chart slot the gauge sits in and does not leave the shadow root around it.\n * @stable\n */\n@customElement('obc-gauge-vertical')\nexport class ObcGaugeVertical extends AdviceMixin(\n SetpointMixin(LitElement, {\n defaultDeadband: 1,\n })\n) {\n @property({type: Number}) minValue = 0;\n @property({type: Number}) maxValue = 100;\n @property({type: Boolean}) reverse = false;\n\n private readonly height = 384;\n private readonly paddingTop = CHART_DIMENSIONS.CANVAS_PADDING;\n private readonly paddingBottom = CHART_DIMENSIONS.CANVAS_PADDING;\n\n @property({type: String}) side: ExternalScaleSide = ExternalScaleSide.right;\n\n @property({type: Boolean}) fixedAspectRatio = false;\n @property({type: Number}) scaleReferenceSize = 384;\n\n @state()\n private _scale = 1;\n\n /** The drawing's width in viewBox units, kept from the last render for the scale measurement. */\n private _viewBoxThickness = 0;\n\n // ResizeController automatically subscribes/unsubscribes based on component lifecycle\n // @ts-expect-error - Controller is used for side effects, not accessed directly\n private _resizeController = new ResizeController(this, {\n callback: (entries) => {\n if (!this.fixedAspectRatio) return;\n\n const entry = entries[0];\n if (!entry) return;\n\n const scale = computeFixedAspectRatioScale({\n orientation: ExternalScaleOrientation.vertical,\n containerMainAxisSize: entry.contentRect.height,\n containerCrossAxisSize: entry.contentRect.width,\n scaleReferenceSize: this.scaleReferenceSize,\n viewBoxThickness: this._viewBoxThickness,\n });\n // Guard against zero-sized containers, but allow fractional scales < 1\n this._scale = scale > 0 ? scale : 1;\n\n // Report scaled dimensions to parent chart\n this.reportDimensions();\n },\n });\n\n @property({type: Boolean, attribute: false}) showLabels = true;\n private readonly barThickness = 48;\n private readonly tickThickness = 24;\n private readonly labelThickness = 60;\n\n @property({type: Array, attribute: false}) mainTickmarks?: number[] = [];\n @property({type: Number}) primaryTickmarkInterval?: number = undefined;\n @property({type: Number}) secondaryTickmarkInterval?: number = undefined;\n @property({type: Number}) tertiaryTickmarkInterval?: number = undefined;\n private readonly scaleType: ScaleType = ScaleType.regular;\n private readonly frameStyle: FrameStyle = FrameStyle.regular;\n @property({type: String, attribute: false})\n borderRadiusPosition?: BorderRadiusPosition =\n BorderRadiusPosition.innerFirstChild;\n\n private readonly borderRadius = 8;\n\n private get hasBar(): boolean {\n return true;\n }\n\n private get scaleBackground(): boolean {\n return true;\n }\n\n private get hasScale(): boolean {\n return true;\n }\n\n @property({type: String}) priority: Priority = Priority.regular;\n @property({type: String}) fillMode: FillMode = FillMode.fill;\n @property({type: Number}) fillMin?: number = undefined;\n @property({type: Number}) fillMax?: number = undefined;\n @property({type: Number}) value?: number = undefined;\n\n @property({type: String}) state: InstrumentState = InstrumentState.active;\n\n /**\n * @deprecated Use `touching` (from SetpointMixin) instead.\n * Kept for backward compatibility. Synced to `touching` in `willUpdate()`.\n */\n @property({type: Boolean}) focused = false;\n\n private readonly advicePosition: AdvicePosition = AdvicePosition.inner;\n // Mask ids are document-scoped, so each gauge names its own.\n private readonly _adviceMaskPrefix = nextAdviceMaskId('gauge');\n\n @property({type: Boolean}) highlightCurrentValue = false;\n\n override render() {\n // A chart pushes its own height to a slotted scale; in fixedAspectRatio\n // mode the drawing keeps its reference length and the SVG scales it.\n const effectiveLength = this.fixedAspectRatio\n ? this.scaleReferenceSize\n : this.height;\n\n const config: ExternalScaleConfig = {\n orientation: ExternalScaleOrientation.vertical,\n side: this.side,\n length: effectiveLength,\n paddingStart: this.paddingTop,\n paddingEnd: this.paddingBottom,\n minValue: this.minValue,\n maxValue: this.maxValue,\n reverse: this.reverse,\n hasScale: this.hasScale,\n labels: this.showLabels,\n hasBar: this.hasBar,\n scaleBackground: this.scaleBackground,\n barThickness: this.barThickness,\n tickThickness: this.tickThickness,\n labelThickness: this.labelThickness,\n mainTickmarks: this.mainTickmarks,\n primaryTickmarkInterval: this.primaryTickmarkInterval,\n secondaryTickmarkInterval: this.secondaryTickmarkInterval,\n tertiaryTickmarkInterval: this.tertiaryTickmarkInterval,\n scaleType: this.scaleType,\n frameStyle: this.frameStyle,\n borderRadiusPosition: this.borderRadiusPosition,\n borderRadius: this.borderRadius,\n priority: this.priority,\n fillMode: this.fillMode,\n fillMin: this.fillMin,\n fillMax: this.fillMax,\n value: this.value,\n setpoint: this.setpoint,\n newSetpoint: this.newSetpoint,\n atSetpoint: this.atSetpoint,\n autoAtSetpoint: this.autoAtSetpoint,\n autoAtSetpointDeadband: this.autoAtSetpointDeadband,\n setpointAtZeroDeadband: this.setpointAtZeroDeadband,\n animateSetpoint: this.animateSetpoint,\n departingNewSetpoint: this.departingNewSetpoint,\n state: this.state,\n touching: this.touching,\n setpointOverride: this.setpointOverride,\n advicePosition: this.advicePosition,\n advices: this.advices,\n adviceTrigger: this.adviceTrigger,\n adviceEmphasis: this.adviceEmphasis,\n adviceMaskPrefix: this._adviceMaskPrefix,\n fixedAspectRatio: this.fixedAspectRatio,\n // Gauges are always in instrument mode - they use fixed borderRadius (8px)\n // and don't respond to .obc-component-size-* CSS classes for border radius\n instrumentMode: true,\n highlightCurrentValue: this.highlightCurrentValue,\n };\n\n const layout = computeExternalScaleLayout(\n toExternalScaleLayoutConfig(config)\n );\n this._viewBoxThickness = layout.thickness;\n\n const parts = renderExternalScale(config);\n\n const viewBox = computeExternalScaleViewBox(\n {orientation: config.orientation, length: effectiveLength},\n layout\n );\n const preserveAspectRatio = this.fixedAspectRatio\n ? 'xMidYMid meet'\n : 'none';\n\n return html`\n <svg\n width=${this.fixedAspectRatio ? '100%' : `${viewBox.width}px`}\n height=${this.fixedAspectRatio ? '100%' : `${this.height}px`}\n viewBox=\"${viewBox.x} ${viewBox.y} ${viewBox.width} ${viewBox.height}\"\n preserveAspectRatio=\"${preserveAspectRatio}\"\n style=\"--scale: ${\n this.fixedAspectRatio ? this._scale : 1\n }; display: block;\"\n part=\"svg\"\n >\n ${parts.barContainer} ${parts.barFill} ${parts.scaleBackground}\n ${parts.tickmarks} ${parts.labels} ${parts.adviceOverlays}\n ${parts.currentValueDot} ${parts.setpoint}\n </svg>\n `;\n }\n\n override willUpdate(changed: PropertyValues): void {\n super.willUpdate(changed);\n\n // Sync deprecated alias to mixin property\n // Only sync if the alias was set and the mixin property was NOT also set.\n if (changed.has('focused') && !changed.has('touching')) {\n this.touching = this.focused;\n }\n }\n\n override updated(changed: PropertyValues) {\n super.updated(changed);\n\n // Only the styles this element applied are removed: the first update\n // lists every property, and a consumer's inline style is theirs.\n if (changed.has('fixedAspectRatio')) {\n if (this.fixedAspectRatio) {\n this._applyFixedAspectRatioStyles();\n this._updateScaleFromCurrentSize();\n } else if (changed.get('fixedAspectRatio') === true) {\n this._removeFixedAspectRatioStyles();\n this._scale = 1;\n }\n }\n\n if (changed.has('scaleReferenceSize') && this.fixedAspectRatio) {\n this._updateScaleFromCurrentSize();\n }\n\n // The reported thickness follows the bands, the advice icons, the\n // setpoint marker band and the mode, whichever mode is on; a resize\n // re-reports through the ResizeController.\n if (\n changed.has('fixedAspectRatio') ||\n changed.has('side') ||\n changed.has('showLabels') ||\n changed.has('advices') ||\n this.setpointPresenceChanged(changed)\n ) {\n // A thinner or thicker drawing under the same box changes the painted\n // scale without a resize event.\n if (this.fixedAspectRatio) this._measureScale();\n this.reportDimensions();\n }\n }\n\n /**\n * Report scale dimensions to parent chart component.\n * When fixedAspectRatio=true, reports the actual visual (scaled) thickness\n * so the chart can correctly reserve space for the scale.\n * When fixedAspectRatio=false, reports the base/unscaled thickness.\n */\n private reportDimensions() {\n const effectiveBarThickness = computeExternalScaleEffectiveBarThickness({\n hasBar: this.hasBar,\n barThickness: this.barThickness,\n borderRadius: this.borderRadius,\n scaleType: this.scaleType,\n });\n\n const baseDimensions = computeScaleDimensionsForReport({\n orientation: ExternalScaleOrientation.vertical,\n side: this.side,\n hasBar: this.hasBar,\n hasScale: this.hasScale,\n labels: this.showLabels,\n barThickness: effectiveBarThickness,\n tickThickness: this.tickThickness,\n labelThickness: this.labelThickness,\n length: this.fixedAspectRatio ? this.scaleReferenceSize : this.height,\n scaleType: this.scaleType,\n hasAdviceIcon: !!this.advices?.some((a) => a.showIcon),\n hasSetpoint:\n this.setpoint !== undefined ||\n this.newSetpoint !== undefined ||\n this.departingNewSetpoint !== undefined,\n });\n\n // The chart lays out in visual pixels, so a scaled drawing reports its\n // scaled thickness.\n const dimensions = this.fixedAspectRatio\n ? {\n ...baseDimensions,\n thickness: Math.round(baseDimensions.thickness * this._scale),\n }\n : baseDimensions;\n\n this.dispatchEvent(\n new CustomEvent('scale-dimensions-changed', {\n detail: dimensions,\n bubbles: true,\n })\n );\n }\n\n protected override createRenderRoot() {\n return this;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n if (this.fixedAspectRatio) {\n this._applyFixedAspectRatioStyles();\n }\n }\n\n /** The inline sizing, value and priority, the consumer had before fixedAspectRatio took the host. */\n private _consumerSizing?: Record<\n 'display' | 'height' | 'width',\n [value: string, priority: string]\n >;\n\n /**\n * A custom element is inline by default, which gives the percentage-sized\n * SVG nothing to fill; in fixedAspectRatio mode the host is a block that\n * takes its container's height.\n */\n private _applyFixedAspectRatioStyles(): void {\n if (!this._consumerSizing) {\n const snapshot = (name: string): [string, string] => [\n this.style.getPropertyValue(name),\n this.style.getPropertyPriority(name),\n ];\n this._consumerSizing = {\n display: snapshot('display'),\n height: snapshot('height'),\n width: snapshot('width'),\n };\n }\n this.style.display = 'block';\n this.style.height = '100%';\n this.style.width = 'auto';\n }\n\n private _removeFixedAspectRatioStyles(): void {\n const saved = this._consumerSizing;\n this._consumerSizing = undefined;\n for (const name of ['display', 'height', 'width'] as const) {\n const [value, priority] = saved?.[name] ?? ['', ''];\n this.style.setProperty(name, value, priority);\n }\n }\n\n /** Reads the host's content box into the scale; false while the host has no size yet. */\n private _measureScale(): boolean {\n const {width, height} = readContentBox(this);\n if (height <= 0) return false;\n this._scale = computeFixedAspectRatioScale({\n orientation: ExternalScaleOrientation.vertical,\n containerMainAxisSize: height,\n containerCrossAxisSize: width,\n scaleReferenceSize: this.scaleReferenceSize,\n viewBoxThickness: this._viewBoxThickness,\n });\n return true;\n }\n\n /** Measures once layout has settled, then reports. */\n private _updateScaleFromCurrentSize(): void {\n requestAnimationFrame(() => {\n if (this._measureScale()) {\n this.requestUpdate();\n this.reportDimensions();\n }\n });\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'obc-gauge-vertical': ObcGaugeVertical;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAyJO,IAAM,mBAAN,MAAM,yBAAyB,YACpC,cAAc,YAAY,EACxB,iBAAiB,EACnB,CAAC,CACH,CAAC,CAAC;;;EACqC,KAAA,WAAA;EACA,KAAA,WAAA;EACA,KAAA,UAAA;EAEX,KAAA,SAAA;EACI,KAAA,aAAA,iBAAiB;EACd,KAAA,gBAAA,iBAAiB;EAEE,KAAA,OAAA,kBAAkB;EAExB,KAAA,mBAAA;EACC,KAAA,qBAAA;EAG9B,KAAA,SAAA;EAGW,KAAA,oBAAA;EAIA,KAAA,oBAAA,IAAI,iBAAiB,MAAM,EACrD,WAAW,YAAY;GACrB,IAAI,CAAC,KAAK,kBAAkB;GAE5B,MAAM,QAAQ,QAAQ;GACtB,IAAI,CAAC,OAAO;GAEZ,MAAM,QAAQ,6BAA6B;IACzC,aAAa,yBAAyB;IACtC,uBAAuB,MAAM,YAAY;IACzC,wBAAwB,MAAM,YAAY;IAC1C,oBAAoB,KAAK;IACzB,kBAAkB,KAAK;GACzB,CAAC;GAED,KAAK,SAAS,QAAQ,IAAI,QAAQ;GAGlC,KAAK,iBAAiB;EACxB,EACF,CAAC;EAEyD,KAAA,aAAA;EAC1B,KAAA,eAAA;EACC,KAAA,gBAAA;EACC,KAAA,iBAAA;EAEoC,KAAA,gBAAA,CAAC;EACV,KAAA,0BAAA,KAAA;EACE,KAAA,4BAAA,KAAA;EACD,KAAA,2BAAA,KAAA;EACtB,KAAA,YAAA,UAAU;EACR,KAAA,aAAA,WAAW;EAGnD,KAAA,uBAAA,qBAAqB;EAES,KAAA,eAAA;EAce,KAAA,WAAA,SAAS;EACT,KAAA,WAAA,SAAS;EACX,KAAA,UAAA,KAAA;EACA,KAAA,UAAA,KAAA;EACF,KAAA,QAAA,KAAA;EAEQ,KAAA,QAAA,gBAAgB;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,CAAA,SAAS,EAAC,MAAM,QAAO,CAAC,CAAA,GAAA,iBAAA,WAAA,yBAAA,KAAA,CAAA;AAhG1B,mBAAAA,WAAA,CAAA,cAAc,oBAAoB,CAAA,GAAA,gBAAA"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,102 @@
|
|
|
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 './bar-horizontal.js';
|
|
6
|
+
import type {ObcBarHorizontal} from './bar-horizontal.js';
|
|
7
|
+
|
|
8
|
+
const frame = () => new Promise((resolve) => requestAnimationFrame(resolve));
|
|
9
|
+
|
|
10
|
+
/** The scale factor settles a few frames after a size change. */
|
|
11
|
+
async function until(check: () => boolean, frames = 40): Promise<void> {
|
|
12
|
+
for (let i = 0; i < frames; i++) {
|
|
13
|
+
if (check()) return;
|
|
14
|
+
await frame();
|
|
15
|
+
}
|
|
16
|
+
throw new Error('the condition never held');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const svgOf = (el: Element) => el.querySelector('svg')!;
|
|
20
|
+
const scaleOf = (el: Element) =>
|
|
21
|
+
parseFloat(svgOf(el).style.getPropertyValue('--scale'));
|
|
22
|
+
|
|
23
|
+
/** Bar, ticks and labels with no setpoint: 48 + 24 + 60 = 132 thick. */
|
|
24
|
+
async function mount(boxStyle: string): Promise<ObcBarHorizontal> {
|
|
25
|
+
const screen = render(
|
|
26
|
+
html`<div style=${boxStyle}>
|
|
27
|
+
<obc-bar-horizontal
|
|
28
|
+
style="flex: 1"
|
|
29
|
+
.minValue=${0}
|
|
30
|
+
.maxValue=${100}
|
|
31
|
+
.value=${40}
|
|
32
|
+
.primaryTickmarkInterval=${20}
|
|
33
|
+
.hasBar=${true}
|
|
34
|
+
.hasScale=${true}
|
|
35
|
+
.barThickness=${48}
|
|
36
|
+
.scaleBackground=${true}
|
|
37
|
+
.fixedAspectRatio=${true}
|
|
38
|
+
></obc-bar-horizontal>
|
|
39
|
+
</div>`
|
|
40
|
+
);
|
|
41
|
+
const el = screen.container.querySelector(
|
|
42
|
+
'obc-bar-horizontal'
|
|
43
|
+
) as ObcBarHorizontal;
|
|
44
|
+
await el.updateComplete;
|
|
45
|
+
return el;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('obc-bar-horizontal fixed aspect ratio', () => {
|
|
49
|
+
it('scales by the host width when the height has room', async () => {
|
|
50
|
+
const el = await mount('display: block; width: 600px; height: 300px');
|
|
51
|
+
await until(() => Math.abs(scaleOf(el) - 600 / 384) < 1e-3);
|
|
52
|
+
expect(svgOf(el).getScreenCTM()!.a).toBeCloseTo(600 / 384, 3);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('follows the painted scale when the host is shorter than the drawing', async () => {
|
|
56
|
+
const el = await mount('display: flex; width: 600px; height: 100px');
|
|
57
|
+
const reports: number[] = [];
|
|
58
|
+
el.addEventListener('scale-dimensions-changed', (e) =>
|
|
59
|
+
reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
|
|
60
|
+
);
|
|
61
|
+
// meet: the 132-tall drawing fits 100 px before the 384-long one fits 600
|
|
62
|
+
await until(() => Math.abs(scaleOf(el) - 100 / 132) < 1e-3);
|
|
63
|
+
const svg = svgOf(el);
|
|
64
|
+
const text = svg.querySelector('text')!;
|
|
65
|
+
const painted = svg.getScreenCTM()!.a;
|
|
66
|
+
expect(painted).toBeCloseTo(100 / 132, 3);
|
|
67
|
+
expect(parseFloat(getComputedStyle(text).fontSize) * painted).toBeCloseTo(
|
|
68
|
+
12,
|
|
69
|
+
1
|
|
70
|
+
);
|
|
71
|
+
await until(() => reports[reports.length - 1] === 100);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('re-measures the scale when the drawing thickness changes under the same box', async () => {
|
|
75
|
+
const el = await mount('display: flex; width: 600px; height: 100px');
|
|
76
|
+
const reports: number[] = [];
|
|
77
|
+
el.addEventListener('scale-dimensions-changed', (e) =>
|
|
78
|
+
reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
|
|
79
|
+
);
|
|
80
|
+
await until(() => Math.abs(scaleOf(el) - 100 / 132) < 1e-3);
|
|
81
|
+
// 180 + 24 + 60 = 264 tall: the same 100 px now holds less than half
|
|
82
|
+
reports.length = 0;
|
|
83
|
+
el.barThickness = 180;
|
|
84
|
+
await until(() => Math.abs(scaleOf(el) - 100 / 264) < 1e-3);
|
|
85
|
+
await until(() => reports[reports.length - 1] === 100);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('measures the content box of a padded host', async () => {
|
|
89
|
+
const el = await mount('display: flex; width: 600px; height: 100px');
|
|
90
|
+
el.style.padding = '20px';
|
|
91
|
+
const reports: number[] = [];
|
|
92
|
+
el.addEventListener('scale-dimensions-changed', (e) =>
|
|
93
|
+
reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
|
|
94
|
+
);
|
|
95
|
+
// 60 px of content height for the 132-tall drawing
|
|
96
|
+
await until(() => Math.abs(scaleOf(el) - 60 / 132) < 1e-3);
|
|
97
|
+
reports.length = 0;
|
|
98
|
+
el.barThickness = 180;
|
|
99
|
+
await until(() => Math.abs(scaleOf(el) - 60 / 264) < 1e-3);
|
|
100
|
+
await until(() => reports[reports.length - 1] === 60);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -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,
|
|
@@ -166,6 +167,9 @@ export class ObcBarHorizontal extends AdviceMixin(
|
|
|
166
167
|
@state()
|
|
167
168
|
private _scale = 1;
|
|
168
169
|
|
|
170
|
+
/** The drawing's height in viewBox units, kept from the last render for the scale measurement. */
|
|
171
|
+
private _viewBoxThickness = 0;
|
|
172
|
+
|
|
169
173
|
// ResizeController automatically subscribes/unsubscribes based on component lifecycle
|
|
170
174
|
// @ts-expect-error - Controller is used for side effects, not accessed directly
|
|
171
175
|
private _resizeController = new ResizeController(this, {
|
|
@@ -175,14 +179,12 @@ export class ObcBarHorizontal extends AdviceMixin(
|
|
|
175
179
|
const entry = entries[0];
|
|
176
180
|
if (!entry) return;
|
|
177
181
|
|
|
178
|
-
// Use the centralized function that computes scale based on reference size
|
|
179
|
-
// For horizontal scales, compare container width to reference size
|
|
180
|
-
const containerMainAxisSize = entry.contentRect.width;
|
|
181
|
-
|
|
182
182
|
this._scale = computeFixedAspectRatioScale({
|
|
183
183
|
orientation: ExternalScaleOrientation.horizontal,
|
|
184
|
-
containerMainAxisSize,
|
|
184
|
+
containerMainAxisSize: entry.contentRect.width,
|
|
185
|
+
containerCrossAxisSize: entry.contentRect.height,
|
|
185
186
|
scaleReferenceSize: this.scaleReferenceSize,
|
|
187
|
+
viewBoxThickness: this._viewBoxThickness,
|
|
186
188
|
});
|
|
187
189
|
|
|
188
190
|
// Report scaled dimensions to parent chart
|
|
@@ -320,6 +322,7 @@ export class ObcBarHorizontal extends AdviceMixin(
|
|
|
320
322
|
const layout = computeExternalScaleLayout(
|
|
321
323
|
toExternalScaleLayoutConfig(config)
|
|
322
324
|
);
|
|
325
|
+
this._viewBoxThickness = layout.thickness;
|
|
323
326
|
|
|
324
327
|
const parts = renderExternalScale(config);
|
|
325
328
|
|
|
@@ -393,6 +396,9 @@ export class ObcBarHorizontal extends AdviceMixin(
|
|
|
393
396
|
this.setpointPresenceChanged(changed);
|
|
394
397
|
|
|
395
398
|
if (!this.fixedAspectRatio || layoutChanged) {
|
|
399
|
+
// A thinner or thicker drawing under the same box changes the painted
|
|
400
|
+
// scale without a resize event.
|
|
401
|
+
if (this.fixedAspectRatio) this._measureScale();
|
|
396
402
|
this.reportDimensions();
|
|
397
403
|
}
|
|
398
404
|
}
|
|
@@ -509,6 +515,20 @@ export class ObcBarHorizontal extends AdviceMixin(
|
|
|
509
515
|
this.style.height = '';
|
|
510
516
|
}
|
|
511
517
|
|
|
518
|
+
/** Reads the host's content box into the scale; false while the host has no size yet. */
|
|
519
|
+
private _measureScale(): boolean {
|
|
520
|
+
const {width, height} = readContentBox(this);
|
|
521
|
+
if (width <= 0) return false;
|
|
522
|
+
this._scale = computeFixedAspectRatioScale({
|
|
523
|
+
orientation: ExternalScaleOrientation.horizontal,
|
|
524
|
+
containerMainAxisSize: width,
|
|
525
|
+
containerCrossAxisSize: height,
|
|
526
|
+
scaleReferenceSize: this.scaleReferenceSize,
|
|
527
|
+
viewBoxThickness: this._viewBoxThickness,
|
|
528
|
+
});
|
|
529
|
+
return true;
|
|
530
|
+
}
|
|
531
|
+
|
|
512
532
|
/**
|
|
513
533
|
* Calculate scale based on current element size.
|
|
514
534
|
* Called when fixedAspectRatio is enabled or scaleReferenceSize changes.
|
|
@@ -516,13 +536,7 @@ export class ObcBarHorizontal extends AdviceMixin(
|
|
|
516
536
|
private _updateScaleFromCurrentSize(): void {
|
|
517
537
|
// Use requestAnimationFrame to ensure layout is complete
|
|
518
538
|
requestAnimationFrame(() => {
|
|
519
|
-
|
|
520
|
-
if (containerWidth > 0) {
|
|
521
|
-
this._scale = computeFixedAspectRatioScale({
|
|
522
|
-
orientation: ExternalScaleOrientation.horizontal,
|
|
523
|
-
containerMainAxisSize: containerWidth,
|
|
524
|
-
scaleReferenceSize: this.scaleReferenceSize,
|
|
525
|
-
});
|
|
539
|
+
if (this._measureScale()) {
|
|
526
540
|
this.requestUpdate();
|
|
527
541
|
// Report updated dimensions to parent (matches pattern in ResizeController and _refreshBorderRadiusFromCssVar)
|
|
528
542
|
this.reportDimensions();
|
|
@@ -542,17 +556,8 @@ export class ObcBarHorizontal extends AdviceMixin(
|
|
|
542
556
|
|
|
543
557
|
// In fixed-aspect-ratio mode, recompute scale when border radius changes
|
|
544
558
|
// (border radius affects effective bar thickness and therefore viewBox)
|
|
545
|
-
if (this.fixedAspectRatio) {
|
|
546
|
-
|
|
547
|
-
if (rect.width > 0) {
|
|
548
|
-
this._scale = computeFixedAspectRatioScale({
|
|
549
|
-
orientation: ExternalScaleOrientation.horizontal,
|
|
550
|
-
containerMainAxisSize: rect.width,
|
|
551
|
-
scaleReferenceSize: this.scaleReferenceSize,
|
|
552
|
-
});
|
|
553
|
-
// Report updated dimensions
|
|
554
|
-
this.reportDimensions();
|
|
555
|
-
}
|
|
559
|
+
if (this.fixedAspectRatio && this._measureScale()) {
|
|
560
|
+
this.reportDimensions();
|
|
556
561
|
}
|
|
557
562
|
}
|
|
558
563
|
|
|
@@ -0,0 +1,101 @@
|
|
|
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 './bar-vertical.js';
|
|
6
|
+
import type {ObcBarVertical} from './bar-vertical.js';
|
|
7
|
+
|
|
8
|
+
const frame = () => new Promise((resolve) => requestAnimationFrame(resolve));
|
|
9
|
+
|
|
10
|
+
/** The scale factor settles a few frames after a size change. */
|
|
11
|
+
async function until(check: () => boolean, frames = 40): Promise<void> {
|
|
12
|
+
for (let i = 0; i < frames; i++) {
|
|
13
|
+
if (check()) return;
|
|
14
|
+
await frame();
|
|
15
|
+
}
|
|
16
|
+
throw new Error('the condition never held');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const svgOf = (el: Element) => el.querySelector('svg')!;
|
|
20
|
+
const scaleOf = (el: Element) =>
|
|
21
|
+
parseFloat(svgOf(el).style.getPropertyValue('--scale'));
|
|
22
|
+
|
|
23
|
+
/** Bar, ticks and labels with no setpoint: 48 + 24 + 60 = 132 thick. */
|
|
24
|
+
async function mount(boxStyle: string): Promise<ObcBarVertical> {
|
|
25
|
+
const screen = render(
|
|
26
|
+
html`<div style=${boxStyle}>
|
|
27
|
+
<obc-bar-vertical
|
|
28
|
+
.minValue=${0}
|
|
29
|
+
.maxValue=${100}
|
|
30
|
+
.value=${40}
|
|
31
|
+
.primaryTickmarkInterval=${20}
|
|
32
|
+
.hasBar=${true}
|
|
33
|
+
.hasScale=${true}
|
|
34
|
+
.barThickness=${48}
|
|
35
|
+
.scaleBackground=${true}
|
|
36
|
+
.fixedAspectRatio=${true}
|
|
37
|
+
></obc-bar-vertical>
|
|
38
|
+
</div>`
|
|
39
|
+
);
|
|
40
|
+
const el = screen.container.querySelector(
|
|
41
|
+
'obc-bar-vertical'
|
|
42
|
+
) as ObcBarVertical;
|
|
43
|
+
await el.updateComplete;
|
|
44
|
+
return el;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe('obc-bar-vertical fixed aspect ratio', () => {
|
|
48
|
+
it('scales by the host height when the width has room', async () => {
|
|
49
|
+
const el = await mount('display: block; width: 400px; height: 600px');
|
|
50
|
+
await until(() => Math.abs(scaleOf(el) - 600 / 384) < 1e-3);
|
|
51
|
+
expect(svgOf(el).getScreenCTM()!.a).toBeCloseTo(600 / 384, 3);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('follows the painted scale when the host is narrower than the drawing', async () => {
|
|
55
|
+
const el = await mount('display: block; width: 120px; height: 600px');
|
|
56
|
+
const reports: number[] = [];
|
|
57
|
+
el.addEventListener('scale-dimensions-changed', (e) =>
|
|
58
|
+
reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
|
|
59
|
+
);
|
|
60
|
+
// meet: the 132-wide drawing fits 120 px before the 384-long one fits 600
|
|
61
|
+
await until(() => Math.abs(scaleOf(el) - 120 / 132) < 1e-3);
|
|
62
|
+
const svg = svgOf(el);
|
|
63
|
+
const text = svg.querySelector('text')!;
|
|
64
|
+
const painted = svg.getScreenCTM()!.a;
|
|
65
|
+
expect(painted).toBeCloseTo(120 / 132, 3);
|
|
66
|
+
expect(parseFloat(getComputedStyle(text).fontSize) * painted).toBeCloseTo(
|
|
67
|
+
12,
|
|
68
|
+
1
|
|
69
|
+
);
|
|
70
|
+
await until(() => reports[reports.length - 1] === 120);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('re-measures the scale when the drawing thickness changes under the same box', async () => {
|
|
74
|
+
const el = await mount('display: block; width: 120px; height: 600px');
|
|
75
|
+
const reports: number[] = [];
|
|
76
|
+
el.addEventListener('scale-dimensions-changed', (e) =>
|
|
77
|
+
reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
|
|
78
|
+
);
|
|
79
|
+
await until(() => Math.abs(scaleOf(el) - 120 / 132) < 1e-3);
|
|
80
|
+
// 180 + 24 + 60 = 264 wide: the same 120 px now holds less than half
|
|
81
|
+
reports.length = 0;
|
|
82
|
+
el.barThickness = 180;
|
|
83
|
+
await until(() => Math.abs(scaleOf(el) - 120 / 264) < 1e-3);
|
|
84
|
+
await until(() => reports[reports.length - 1] === 120);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('measures the content box of a padded host', async () => {
|
|
88
|
+
const el = await mount('display: block; width: 120px; height: 600px');
|
|
89
|
+
el.style.padding = '20px';
|
|
90
|
+
const reports: number[] = [];
|
|
91
|
+
el.addEventListener('scale-dimensions-changed', (e) =>
|
|
92
|
+
reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
|
|
93
|
+
);
|
|
94
|
+
// 80 px of content width for the 132-wide drawing
|
|
95
|
+
await until(() => Math.abs(scaleOf(el) - 80 / 132) < 1e-3);
|
|
96
|
+
reports.length = 0;
|
|
97
|
+
el.barThickness = 180;
|
|
98
|
+
await until(() => Math.abs(scaleOf(el) - 80 / 264) < 1e-3);
|
|
99
|
+
await until(() => reports[reports.length - 1] === 80);
|
|
100
|
+
});
|
|
101
|
+
});
|