@swimlane/ngx-charts 25.0.0-beta.0 → 25.0.0-beta.1

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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## HEAD (unreleased)
4
4
 
5
+ - Enhancement: Added support for Angular 22
6
+ - Breaking: Dropped support for Angular 19 and 20 (requires Angular 21.2+)
7
+
8
+ ## 24.0.1
9
+
10
+ - Fix: Y-axis labels were cut off, misaligned when server-side rendered.
11
+
5
12
  ## 24.0.0
6
13
 
7
14
  - Fix: Area Charts were not server-side renderable
@@ -1282,6 +1282,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImpor
1282
1282
  args: [{
1283
1283
  selector: 'base-chart',
1284
1284
  template: ` <div></div> `,
1285
+ // eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection -- preserve pre-Angular-22 Default CD behavior
1285
1286
  changeDetection: ChangeDetectionStrategy.Eager,
1286
1287
  standalone: false
1287
1288
  }]
@@ -2067,13 +2068,19 @@ class YAxisTicksComponent {
2067
2068
  this.update();
2068
2069
  }
2069
2070
  ngAfterViewInit() {
2070
- setTimeout(() => this.updateDims());
2071
+ // Browser: measure after paint. SSR width is applied synchronously in update().
2072
+ if (isPlatformBrowser(this.platformId)) {
2073
+ setTimeout(() => this.updateDims());
2074
+ }
2071
2075
  }
2072
2076
  updateDims() {
2073
2077
  if (!isPlatformBrowser(this.platformId)) {
2074
- // for SSR, use approximate value instead of measured
2075
- this.width = this.getApproximateAxisWidth();
2076
- this.dimensionsChanged.emit({ width: this.width });
2078
+ // SSR: approximate — no DOM metrics available
2079
+ const width = this.getApproximateAxisWidth();
2080
+ if (width > 0 && width !== this.width) {
2081
+ this.width = width;
2082
+ this.dimensionsChanged.emit({ width: this.width });
2083
+ }
2077
2084
  return;
2078
2085
  }
2079
2086
  const width = parseInt(this.ticksElement.nativeElement.getBoundingClientRect().width, 10);
@@ -2162,7 +2169,13 @@ class YAxisTicksComponent {
2162
2169
  break;
2163
2170
  default:
2164
2171
  }
2165
- setTimeout(() => this.updateDims());
2172
+ // SSR must reserve axis width before HTML serialize (no deferred setTimeout).
2173
+ if (!isPlatformBrowser(this.platformId)) {
2174
+ this.updateDims();
2175
+ }
2176
+ else {
2177
+ setTimeout(() => this.updateDims());
2178
+ }
2166
2179
  }
2167
2180
  setReferencelines() {
2168
2181
  this.refMin = this.adjustedScale(Math.min.apply(null, this.referenceLines.map(item => item.value)));
@@ -2203,10 +2216,21 @@ class YAxisTicksComponent {
2203
2216
  tickTrim(label) {
2204
2217
  return this.trimTicks ? trimLabel(label, this.maxTickLength) : label;
2205
2218
  }
2219
+ /** Approx px width for SSR / pre-measure seeding. */
2220
+ static { this.APPROX_CHAR_WIDTH = 7; }
2221
+ static approximateTickLabelsWidth(labels, trimTicks = true, maxTickLength = 16) {
2222
+ if (!labels?.length) {
2223
+ return 0;
2224
+ }
2225
+ const maxChars = Math.max(0, ...labels.map(label => (trimTicks ? trimLabel(label, maxTickLength) : String(label)).length));
2226
+ return maxChars * YAxisTicksComponent.APPROX_CHAR_WIDTH;
2227
+ }
2206
2228
  getApproximateAxisWidth() {
2207
- const maxChars = Math.max(...this.ticks.map(t => this.tickTrim(this.tickFormat(t)).length));
2208
- const charWidth = 7;
2209
- return maxChars * charWidth;
2229
+ if (!this.ticks?.length || !this.tickFormat) {
2230
+ return 0;
2231
+ }
2232
+ const labels = this.ticks.map(t => this.tickTrim(this.tickFormat(t)));
2233
+ return YAxisTicksComponent.approximateTickLabelsWidth(labels, false, this.maxTickLength);
2210
2234
  }
2211
2235
  tickChunks(label) {
2212
2236
  if (label.toString().length > this.maxTickLength && this.scale.bandwidth) {
@@ -2431,6 +2455,8 @@ class YAxisComponent {
2431
2455
  this.tickStroke = '#CCC';
2432
2456
  this.strokeWidth = 1;
2433
2457
  this.padding = 5;
2458
+ /** Last tick-label width emitted to the parent chart (not conflated with labelOffset). */
2459
+ this.emittedTickWidth = null;
2434
2460
  }
2435
2461
  ngOnChanges(changes) {
2436
2462
  this.update();
@@ -2449,18 +2475,18 @@ class YAxisComponent {
2449
2475
  }
2450
2476
  }
2451
2477
  emitTicksWidth({ width }) {
2452
- if (width !== this.labelOffset && this.yOrient === Orientation.Right) {
2453
- this.labelOffset = width + this.labelOffset;
2454
- setTimeout(() => {
2455
- this.dimensionsChanged.emit({ width });
2456
- }, 0);
2478
+ if (width == null || width === this.emittedTickWidth) {
2479
+ return;
2480
+ }
2481
+ this.emittedTickWidth = width;
2482
+ if (this.yOrient === Orientation.Right) {
2483
+ this.labelOffset = width + 65;
2457
2484
  }
2458
- else if (width !== this.labelOffset) {
2485
+ else {
2459
2486
  this.labelOffset = width;
2460
- setTimeout(() => {
2461
- this.dimensionsChanged.emit({ width });
2462
- }, 0);
2463
2487
  }
2488
+ // Sync emit so SSR HTML serializes with reserved y-axis width (no setTimeout).
2489
+ this.dimensionsChanged.emit({ width });
2464
2490
  }
2465
2491
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: YAxisComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
2466
2492
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "22.0.8", type: YAxisComponent, isStandalone: false, selector: "g[ngx-charts-y-axis]", inputs: { yScale: "yScale", dims: "dims", trimTicks: "trimTicks", maxTickLength: "maxTickLength", tickFormatting: "tickFormatting", ticks: "ticks", showGridLines: "showGridLines", showLabel: "showLabel", labelText: "labelText", yAxisTickCount: "yAxisTickCount", yOrient: "yOrient", referenceLines: "referenceLines", showRefLines: "showRefLines", showRefLabels: "showRefLabels", yAxisOffset: "yAxisOffset", wrapTicks: "wrapTicks" }, outputs: { dimensionsChanged: "dimensionsChanged" }, viewQueries: [{ propertyName: "ticksComponent", first: true, predicate: YAxisTicksComponent, descendants: true }], usesOnChanges: true, ngImport: i0, template: `
@@ -3775,6 +3801,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImpor
3775
3801
  args: [{
3776
3802
  selector: '[ngx-charts-count-up]',
3777
3803
  template: ` {{ value }} `,
3804
+ // eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection -- preserve pre-Angular-22 Default CD behavior
3778
3805
  changeDetection: ChangeDetectionStrategy.Eager,
3779
3806
  standalone: false
3780
3807
  }]
@@ -7868,6 +7895,8 @@ class BarHorizontalComponent extends BaseChartComponent {
7868
7895
  this.dataLabelMaxWidth = { negative: 0, positive: 0 };
7869
7896
  }
7870
7897
  this.margin = [10, 20 + this.dataLabelMaxWidth.positive, 10, 20 + this.dataLabelMaxWidth.negative];
7898
+ // Seed axis width before first measure so SSR/print HTML reserves label space.
7899
+ this.seedYAxisWidthFromResults();
7871
7900
  this.dims = calculateViewDimensions({
7872
7901
  width: this.width,
7873
7902
  height: this.height,
@@ -7894,6 +7923,14 @@ class BarHorizontalComponent extends BaseChartComponent {
7894
7923
  refLines.forEach(line => parent.appendChild(line));
7895
7924
  }
7896
7925
  }
7926
+ /** Approx Y-axis width from category labels when not yet measured (SSR-safe). */
7927
+ seedYAxisWidthFromResults() {
7928
+ if (!this.yAxis || this.yAxisWidth > 0 || !this.results?.length) {
7929
+ return;
7930
+ }
7931
+ const labels = this.results.map(d => formatLabel(d.name ?? d.label));
7932
+ this.yAxisWidth = YAxisTicksComponent.approximateTickLabelsWidth(labels, this.trimYAxisTicks !== false, this.maxYAxisTickLength ?? 16);
7933
+ }
7897
7934
  getXScale() {
7898
7935
  this.xDomain = this.getXDomain();
7899
7936
  const scale = scaleLinear().range([0, this.dims.width]).domain(this.xDomain);
@@ -7946,10 +7983,16 @@ class BarHorizontalComponent extends BaseChartComponent {
7946
7983
  return opts;
7947
7984
  }
7948
7985
  updateYAxisWidth({ width }) {
7986
+ if (width === this.yAxisWidth) {
7987
+ return;
7988
+ }
7949
7989
  this.yAxisWidth = width;
7950
7990
  this.update();
7951
7991
  }
7952
7992
  updateXAxisHeight({ height }) {
7993
+ if (height === this.xAxisHeight) {
7994
+ return;
7995
+ }
7953
7996
  this.xAxisHeight = height;
7954
7997
  this.update();
7955
7998
  }
@@ -20981,8 +21024,6 @@ function tickFormat(fieldType, groupByType) {
20981
21024
  };
20982
21025
  }
20983
21026
 
20984
- /* eslint-disable @typescript-eslint/no-empty-interface */
20985
-
20986
21027
  /*
20987
21028
  * Public API Surface of ngx-charts
20988
21029
  */