@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
|
@@ -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:** Width (384px), padding (32px), bar/tick/label thicknesses, and border radius are fixed for consistent gauge appearance.
|
|
58
|
+
* - **Fixed Layout:** Width (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 width 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 right so values grow leftward.
|
|
129
129
|
* @property side - Which side of the chart area this scale lives on (top or bottom)
|
|
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 width.
|
|
131
|
+
* @property scaleReferenceSize - Container width at which a `fixedAspectRatio` gauge draws 1:1 with the design. A wider container enlarges the drawing proportionally, a narrower 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 ObcGaugeHorizontal extends AdviceMixin(
|
|
|
163
166
|
|
|
164
167
|
@property({type: String}) side: ExternalScaleSide = ExternalScaleSide.bottom;
|
|
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 width, the scale renders at native 1:1 (matches Figma design).
|
|
179
|
-
* Above this width, 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 height 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 ObcGaugeHorizontal 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 horizontal scales, compare container width to reference size
|
|
198
|
-
const containerMainAxisSize = entry.contentRect.width;
|
|
199
|
-
|
|
200
187
|
const scale = computeFixedAspectRatioScale({
|
|
201
188
|
orientation: ExternalScaleOrientation.horizontal,
|
|
202
|
-
containerMainAxisSize,
|
|
189
|
+
containerMainAxisSize: entry.contentRect.width,
|
|
190
|
+
containerCrossAxisSize: entry.contentRect.height,
|
|
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 ObcGaugeHorizontal extends AdviceMixin(
|
|
|
260
249
|
@property({type: Boolean}) highlightCurrentValue = false;
|
|
261
250
|
|
|
262
251
|
override render() {
|
|
252
|
+
// A chart pushes its own width 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.width;
|
|
257
|
+
|
|
263
258
|
const config: ExternalScaleConfig = {
|
|
264
259
|
orientation: ExternalScaleOrientation.horizontal,
|
|
265
260
|
side: this.side,
|
|
266
|
-
length:
|
|
261
|
+
length: effectiveLength,
|
|
267
262
|
paddingStart: this.paddingLeft,
|
|
268
263
|
paddingEnd: this.paddingRight,
|
|
269
264
|
minValue: this.minValue,
|
|
@@ -315,11 +310,12 @@ export class ObcGaugeHorizontal 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 ObcGaugeHorizontal 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 ObcGaugeHorizontal extends AdviceMixin(
|
|
|
393
409
|
barThickness: effectiveBarThickness,
|
|
394
410
|
tickThickness: this.tickThickness,
|
|
395
411
|
labelThickness: this.labelThickness,
|
|
396
|
-
length: this.width,
|
|
412
|
+
length: this.fixedAspectRatio ? this.scaleReferenceSize : this.width,
|
|
397
413
|
scaleType: this.scaleType,
|
|
398
414
|
hasAdviceIcon: !!this.advices?.some((a) => a.showIcon),
|
|
399
415
|
hasSetpoint:
|
|
@@ -402,10 +418,14 @@ export class ObcGaugeHorizontal 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 ObcGaugeHorizontal 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' | 'width' | 'height',
|
|
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 width.
|
|
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
|
+
width: snapshot('width'),
|
|
469
|
+
height: snapshot('height'),
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
this.style.display = 'block';
|
|
473
|
+
this.style.width = '100%';
|
|
474
|
+
this.style.height = 'auto';
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
private _removeFixedAspectRatioStyles(): void {
|
|
478
|
+
const saved = this._consumerSizing;
|
|
479
|
+
this._consumerSizing = undefined;
|
|
480
|
+
for (const name of ['display', 'width', 'height'] 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 (width <= 0) return false;
|
|
490
|
+
this._scale = computeFixedAspectRatioScale({
|
|
491
|
+
orientation: ExternalScaleOrientation.horizontal,
|
|
492
|
+
containerMainAxisSize: width,
|
|
493
|
+
containerCrossAxisSize: height,
|
|
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 {
|
|
@@ -416,6 +416,10 @@ export const ScaleReferenceSizeComparison: StoryObj = {
|
|
|
416
416
|
border: 2px dashed var(--instrument-frame-tertiary-color);
|
|
417
417
|
padding: 0;
|
|
418
418
|
box-sizing: content-box;
|
|
419
|
+
resize: both;
|
|
420
|
+
overflow: auto;
|
|
421
|
+
min-width: 120px;
|
|
422
|
+
min-height: 120px;
|
|
419
423
|
}
|
|
420
424
|
.scale-comparison-label {
|
|
421
425
|
font-family: var(--font-family-main);
|
|
@@ -452,6 +456,10 @@ export const ScaleReferenceSizeComparison: StoryObj = {
|
|
|
452
456
|
<strong>Right:</strong> scaleReferenceSize=384, container=384px →
|
|
453
457
|
Scale factor 1.0 (native size)
|
|
454
458
|
</li>
|
|
459
|
+
<li>
|
|
460
|
+
<strong>Drag a box corner:</strong> the drawing follows the box
|
|
461
|
+
width (height from the 1:1 ratio) while the label font stays put.
|
|
462
|
+
</li>
|
|
455
463
|
</ul>
|
|
456
464
|
</div>
|
|
457
465
|
|
|
@@ -0,0 +1,284 @@
|
|
|
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-vertical.js';
|
|
6
|
+
import '../../bars-graphs/line-graph/line-graph.js';
|
|
7
|
+
import {ExternalScaleSide} from './gauge-vertical.js';
|
|
8
|
+
import type {ObcGaugeVertical} from './gauge-vertical.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<ObcGaugeVertical> {
|
|
28
|
+
const screen = render(
|
|
29
|
+
html`<div style="display: block; width: 480px; height: 600px">
|
|
30
|
+
<obc-gauge-vertical
|
|
31
|
+
.minValue=${0}
|
|
32
|
+
.maxValue=${100}
|
|
33
|
+
.value=${40}
|
|
34
|
+
.primaryTickmarkInterval=${20}
|
|
35
|
+
.fixedAspectRatio=${fixedAspectRatio}
|
|
36
|
+
></obc-gauge-vertical>
|
|
37
|
+
</div>`
|
|
38
|
+
);
|
|
39
|
+
const el = screen.container.querySelector(
|
|
40
|
+
'obc-gauge-vertical'
|
|
41
|
+
) as ObcGaugeVertical;
|
|
42
|
+
await el.updateComplete;
|
|
43
|
+
return el;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
describe('obc-gauge-vertical 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('height')).toBe('384px');
|
|
51
|
+
expect(svg.getAttribute('preserveAspectRatio')).toBe('none');
|
|
52
|
+
expect(Math.round(svg.getBoundingClientRect().height)).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.height).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().height)).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.left;
|
|
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('height')).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-vertical
|
|
122
|
+
slot="right-scale"
|
|
123
|
+
.minValue=${0}
|
|
124
|
+
.maxValue=${100}
|
|
125
|
+
.value=${40}
|
|
126
|
+
.primaryTickmarkInterval=${20}
|
|
127
|
+
></obc-gauge-vertical>
|
|
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-vertical'
|
|
135
|
+
) as ObcGaugeVertical;
|
|
136
|
+
await chart.updateComplete;
|
|
137
|
+
const reports: number[] = [];
|
|
138
|
+
chart
|
|
139
|
+
.shadowRoot!.querySelector('slot[name="right-scale"]')!
|
|
140
|
+
.addEventListener('scale-dimensions-changed', (e) =>
|
|
141
|
+
reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
|
|
142
|
+
);
|
|
143
|
+
// The slot is 400 px tall: 132 × 400 / 384 = 137.5
|
|
144
|
+
await until(() => Math.abs(scaleOf(el) - 400 / 384) < 1e-3, 90);
|
|
145
|
+
await until(() => reports[reports.length - 1] === 138, 90);
|
|
146
|
+
// The chart widens the slot once its debounced layout runs.
|
|
147
|
+
await until(
|
|
148
|
+
() => Math.round(svgOf(el).getBoundingClientRect().width) === 138,
|
|
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-vertical
|
|
156
|
+
style="display: none; height: 300px"
|
|
157
|
+
.minValue=${0}
|
|
158
|
+
.maxValue=${100}
|
|
159
|
+
></obc-gauge-vertical>`
|
|
160
|
+
);
|
|
161
|
+
const el = screen.container.querySelector(
|
|
162
|
+
'obc-gauge-vertical'
|
|
163
|
+
) as ObcGaugeVertical;
|
|
164
|
+
await el.updateComplete;
|
|
165
|
+
await frame();
|
|
166
|
+
expect(el.style.display).toBe('none');
|
|
167
|
+
expect(el.style.height).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: 300px; height: 600px">
|
|
173
|
+
<obc-gauge-vertical
|
|
174
|
+
style="display: inline-block; height: 300px !important; width: 120px"
|
|
175
|
+
.minValue=${0}
|
|
176
|
+
.maxValue=${100}
|
|
177
|
+
></obc-gauge-vertical>
|
|
178
|
+
</div>`
|
|
179
|
+
);
|
|
180
|
+
const el = screen.container.querySelector(
|
|
181
|
+
'obc-gauge-vertical'
|
|
182
|
+
) as ObcGaugeVertical;
|
|
183
|
+
await el.updateComplete;
|
|
184
|
+
el.fixedAspectRatio = true;
|
|
185
|
+
await until(() => scaleOf(el) !== 1);
|
|
186
|
+
expect(el.style.height).toBe('100%');
|
|
187
|
+
el.fixedAspectRatio = false;
|
|
188
|
+
await el.updateComplete;
|
|
189
|
+
expect(el.style.display).toBe('inline-block');
|
|
190
|
+
expect(el.style.height).toBe('300px');
|
|
191
|
+
expect(el.style.getPropertyPriority('height')).toBe('important');
|
|
192
|
+
expect(el.style.width).toBe('120px');
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('follows the painted scale when the host is narrower than the drawing', async () => {
|
|
196
|
+
const screen = render(
|
|
197
|
+
html`<div style="display: block; width: 120px; height: 600px">
|
|
198
|
+
<obc-gauge-vertical
|
|
199
|
+
.minValue=${0}
|
|
200
|
+
.maxValue=${100}
|
|
201
|
+
.value=${40}
|
|
202
|
+
.primaryTickmarkInterval=${20}
|
|
203
|
+
.fixedAspectRatio=${true}
|
|
204
|
+
></obc-gauge-vertical>
|
|
205
|
+
</div>`
|
|
206
|
+
);
|
|
207
|
+
const el = screen.container.querySelector(
|
|
208
|
+
'obc-gauge-vertical'
|
|
209
|
+
) as ObcGaugeVertical;
|
|
210
|
+
await el.updateComplete;
|
|
211
|
+
const reports: number[] = [];
|
|
212
|
+
el.addEventListener('scale-dimensions-changed', (e) =>
|
|
213
|
+
reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
|
|
214
|
+
);
|
|
215
|
+
// meet: the 132-wide drawing fits 120 px before the 384-long one fits 600
|
|
216
|
+
await until(() => Math.abs(scaleOf(el) - 120 / 132) < 1e-3);
|
|
217
|
+
const svg = svgOf(el);
|
|
218
|
+
const text = svg.querySelector('text')!;
|
|
219
|
+
const painted = svg.getScreenCTM()!.a;
|
|
220
|
+
expect(painted).toBeCloseTo(120 / 132, 3);
|
|
221
|
+
expect(parseFloat(getComputedStyle(text).fontSize) * painted).toBeCloseTo(
|
|
222
|
+
12,
|
|
223
|
+
1
|
|
224
|
+
);
|
|
225
|
+
await until(() => reports[reports.length - 1] === 120);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('re-measures the scale when the drawing thickness changes under the same box', async () => {
|
|
229
|
+
const screen = render(
|
|
230
|
+
html`<div style="display: block; width: 120px; height: 600px">
|
|
231
|
+
<obc-gauge-vertical
|
|
232
|
+
.minValue=${0}
|
|
233
|
+
.maxValue=${100}
|
|
234
|
+
.value=${40}
|
|
235
|
+
.primaryTickmarkInterval=${20}
|
|
236
|
+
.fixedAspectRatio=${true}
|
|
237
|
+
></obc-gauge-vertical>
|
|
238
|
+
</div>`
|
|
239
|
+
);
|
|
240
|
+
const el = screen.container.querySelector(
|
|
241
|
+
'obc-gauge-vertical'
|
|
242
|
+
) as ObcGaugeVertical;
|
|
243
|
+
await el.updateComplete;
|
|
244
|
+
const reports: number[] = [];
|
|
245
|
+
el.addEventListener('scale-dimensions-changed', (e) =>
|
|
246
|
+
reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
|
|
247
|
+
);
|
|
248
|
+
await until(() => Math.abs(scaleOf(el) - 120 / 132) < 1e-3);
|
|
249
|
+
// 48 + 24 = 72 wide without labels: 120 px has room, the height decides
|
|
250
|
+
el.showLabels = false;
|
|
251
|
+
await until(() => Math.abs(scaleOf(el) - 600 / 384) < 1e-3);
|
|
252
|
+
await until(() => reports[reports.length - 1] === 113);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('measures the content box of a padded host', async () => {
|
|
256
|
+
const screen = render(
|
|
257
|
+
html`<div style="display: block; width: 120px; height: 600px">
|
|
258
|
+
<obc-gauge-vertical
|
|
259
|
+
style="padding: 20px"
|
|
260
|
+
.minValue=${0}
|
|
261
|
+
.maxValue=${100}
|
|
262
|
+
.value=${40}
|
|
263
|
+
.primaryTickmarkInterval=${20}
|
|
264
|
+
.fixedAspectRatio=${true}
|
|
265
|
+
></obc-gauge-vertical>
|
|
266
|
+
</div>`
|
|
267
|
+
);
|
|
268
|
+
const el = screen.container.querySelector(
|
|
269
|
+
'obc-gauge-vertical'
|
|
270
|
+
) as ObcGaugeVertical;
|
|
271
|
+
await el.updateComplete;
|
|
272
|
+
const reports: number[] = [];
|
|
273
|
+
el.addEventListener('scale-dimensions-changed', (e) =>
|
|
274
|
+
reports.push((e as CustomEvent<{thickness: number}>).detail.thickness)
|
|
275
|
+
);
|
|
276
|
+
// 80 px of content width for the 132-wide drawing
|
|
277
|
+
await until(() => Math.abs(scaleOf(el) - 80 / 132) < 1e-3);
|
|
278
|
+
reports.length = 0;
|
|
279
|
+
// 72 wide without labels: 80 / 72 is still under the height's 1.5625
|
|
280
|
+
el.showLabels = false;
|
|
281
|
+
await until(() => Math.abs(scaleOf(el) - 80 / 72) < 1e-3);
|
|
282
|
+
await until(() => reports[reports.length - 1] === 80);
|
|
283
|
+
});
|
|
284
|
+
});
|