@oicl/openbridge-webcomponents-full-bundle 2.0.0-next.127 → 2.0.0-next.128

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.
@@ -42,11 +42,36 @@ canvas {
42
42
  display: block;
43
43
  }
44
44
 
45
- /* Fixed aspect ratio scaling mode: canvas fills wrapper */
45
+ /* Fixed aspect ratio scaling mode: the canvas container must be a definite
46
+ box, not shrink-to-fit. The wrapper is a column flex with align-items:
47
+ center, so the container would otherwise size to the canvas' max-content
48
+ width — and a canvas with an auto width and a definite height resolves
49
+ against its intrinsic 2:1 ratio, capping the chart at height * 2. */
46
50
 
47
- :host([fixedaspectratioscaling]) canvas {
51
+ :host([fixedaspectratioscaling]) .canvas-and-slots-container {
48
52
  width: 100%;
49
- height: var(--chart-height, auto);
53
+ }
54
+
55
+ /* Fixed aspect ratio scaling mode: canvas fills wrapper.
56
+
57
+ \`!important\` is load-bearing, not a shortcut. Chart.js measures the
58
+ container with getBoundingClientRect() — which is scaled by any ancestor
59
+ CSS \`zoom\` — and writes that number straight back as an inline
60
+ \`style="width/height: Npx"\`. The browser then scales that CSS-pixel value
61
+ by the same zoom a second time, so the canvas lands at zoom² of its cell
62
+ (64% at zoom 0.8, 156% at zoom 1.25). Overriding the inline style pins the
63
+ canvas to the box the layout actually gave it at every zoom level; Chart.js
64
+ keeps using its own measurement for the drawing buffer, which only affects
65
+ raster resolution, not geometry.
66
+
67
+ No auto margins here either: Chart.js subtracts the canvas' resolved
68
+ margins from the container width, so centring it with \`margin: 0 auto\`
69
+ makes the leftover space permanently unavailable to it. */
70
+
71
+ :host([fixedaspectratioscaling]) canvas {
72
+ width: 100% !important;
73
+ height: var(--chart-height, auto) !important;
74
+ margin: 0;
50
75
  }
51
76
  `;
52
77
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"chart-common.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"chart-common.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oicl/openbridge-webcomponents-full-bundle",
3
- "version": "2.0.0-next.127",
3
+ "version": "2.0.0-next.128",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -181,6 +181,16 @@ const LINE_GRAPH_RECREATE_PROP_NAMES = [
181
181
  'fixedAspectRatioScaling',
182
182
  ] as const;
183
183
 
184
+ /**
185
+ * Properties that define the chart's reference size, and therefore invalidate
186
+ * the derived `computedWidth` / `computedHeight` pair.
187
+ */
188
+ const LINE_GRAPH_DIMENSION_PROP_NAMES = [
189
+ 'width',
190
+ 'height',
191
+ 'fixedAspectRatioScaling',
192
+ ] as const;
193
+
184
194
  /**
185
195
  * Abstract base class for line and area chart components built on Chart.js.
186
196
  *
@@ -1264,8 +1274,8 @@ export class ObcChartLineBase extends LitElement {
1264
1274
  * Synchronize scale and chart dimensions/data
1265
1275
  * This is the main coordination function
1266
1276
  */
1267
- private syncScalesAndChart() {
1268
- if (this.isUpdatingScales) return;
1277
+ private syncScalesAndChart(): boolean {
1278
+ if (this.isUpdatingScales) return false;
1269
1279
  this.isUpdatingScales = true;
1270
1280
 
1271
1281
  // console.debug(`[chart-line-base] Syncing scales and chart`, {
@@ -1298,7 +1308,7 @@ export class ObcChartLineBase extends LitElement {
1298
1308
  effectiveWidth,
1299
1309
  effectiveHeight,
1300
1310
  });
1301
- return;
1311
+ return false;
1302
1312
  }
1303
1313
 
1304
1314
  // Step 3: Update slotted scales with coordinated properties
@@ -1310,6 +1320,7 @@ export class ObcChartLineBase extends LitElement {
1310
1320
  this.chart.destroy();
1311
1321
  }
1312
1322
  this.createChart();
1323
+ return true;
1313
1324
  } finally {
1314
1325
  this.isUpdatingScales = false;
1315
1326
  }
@@ -1667,6 +1678,24 @@ export class ObcChartLineBase extends LitElement {
1667
1678
  return;
1668
1679
  }
1669
1680
 
1681
+ // `computedWidth` / `computedHeight` are the pixel size everything below
1682
+ // derives from (`--chart-height`, the slotted scales' height, the padding
1683
+ // scale factor). They were only ever refreshed from the wrapper's
1684
+ // ResizeObserver, so re-assigning `width` / `height` rebuilt the chart
1685
+ // against the *previous* aspect ratio and the new one only took effect on
1686
+ // the next container resize (issue #1138).
1687
+ //
1688
+ // This runs before the `hasLabelPadding` branch below: the two can change
1689
+ // in the same update (the tank sets both on its embedded gauge-trend), and
1690
+ // taking the label-padding path first would rebuild against a stale
1691
+ // derived size. Nothing is lost by going through here instead — a rebuild
1692
+ // from `updateComputedDimensions()` goes via `syncScalesAndChart()`, which
1693
+ // performs the same `updateScaleProperties()` cascade.
1694
+ if (this.hasAnyChanged(changed, LINE_GRAPH_DIMENSION_PROP_NAMES)) {
1695
+ // Recreates the chart itself when the derived size actually moved.
1696
+ if (this.updateComputedDimensions()) return;
1697
+ }
1698
+
1670
1699
  // `hasLabelPadding` cascades into slotted scales via `updateScaleProperties()`
1671
1700
  // (toggles `showLabels`, which collapses/expands the bar's label band and
1672
1701
  // changes its reported thickness). That path only runs through
@@ -1789,24 +1818,32 @@ export class ObcChartLineBase extends LitElement {
1789
1818
  }
1790
1819
 
1791
1820
  /**
1792
- * Calculate actual dimensions based on parent width and aspect ratio.
1793
- * Only used when fixedAspectRatioScaling is true.
1821
+ * Refresh `computedWidth` / `computedHeight`, the derived pixel size the
1822
+ * chart and its slotted scales are laid out from.
1823
+ *
1824
+ * In pixel mode they simply mirror `width` / `height`. Only in
1825
+ * `fixedAspectRatioScaling` mode are they derived — from the wrapper's
1826
+ * measured width and the aspect ratio the `width` / `height` pair defines —
1827
+ * and only then can this rebuild the chart.
1828
+ *
1829
+ * @returns `true` when the change was significant enough that the chart was
1830
+ * rebuilt here, so the caller must not rebuild it a second time.
1794
1831
  */
1795
- private updateComputedDimensions() {
1832
+ private updateComputedDimensions(): boolean {
1796
1833
  if (!this.fixedAspectRatioScaling) {
1797
1834
  // In pixel mode, use width/height directly
1798
1835
  this.computedWidth = this.width;
1799
1836
  this.computedHeight = this.height;
1800
- return;
1837
+ return false;
1801
1838
  }
1802
1839
 
1803
1840
  // Get the wrapper element
1804
1841
  const wrapper = this.renderRoot.querySelector('.wrapper') as HTMLElement;
1805
- if (!wrapper) return;
1842
+ if (!wrapper) return false;
1806
1843
 
1807
1844
  // Get parent's available width
1808
1845
  const parentWidth = wrapper.clientWidth;
1809
- if (parentWidth <= 0) return;
1846
+ if (parentWidth <= 0) return false;
1810
1847
 
1811
1848
  // Calculate aspect ratio from width/height properties
1812
1849
  const aspectRatio = this.width / this.height;
@@ -1836,13 +1873,18 @@ export class ObcChartLineBase extends LitElement {
1836
1873
  // Note: syncScalesAndChart() handles chart destruction and creation internally,
1837
1874
  // so we only call createChart() directly when there are no external scales.
1838
1875
  if (this.hasExternalScales()) {
1839
- this.syncScalesAndChart();
1876
+ // syncScalesAndChart() bails without rebuilding when a sync is already
1877
+ // in flight or the effective chart area is degenerate; reporting its
1878
+ // real outcome keeps the caller's own rebuild as the fallback.
1879
+ return this.syncScalesAndChart();
1840
1880
  } else if (this.chart) {
1841
1881
  // No external scales - just recreate chart
1842
1882
  this.chart.destroy();
1843
1883
  this.createChart();
1884
+ return true;
1844
1885
  }
1845
1886
  }
1887
+ return false;
1846
1888
  }
1847
1889
 
1848
1890
  /**