@swimlane/ngx-charts 24.0.0 → 24.0.2

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,14 @@
2
2
 
3
3
  ## HEAD (unreleased)
4
4
 
5
+ ## 24.0.2
6
+
7
+ - Fix: Side legend labels now truncate with CSS ellipsis instead of being hard-clipped when the legend width is constrained
8
+
9
+ ## 24.0.1
10
+
11
+ - Fix: Y-axis labels were cut off, misaligned when server-side rendered.
12
+
5
13
  ## 24.0.0
6
14
 
7
15
  - Fix: Area Charts were not server-side renderable
@@ -688,7 +688,13 @@ class LegendEntryComponent {
688
688
  }
689
689
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.12", ngImport: i0, type: LegendEntryComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
690
690
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.12", type: LegendEntryComponent, isStandalone: false, selector: "ngx-charts-legend-entry", inputs: { color: "color", label: "label", formattedLabel: "formattedLabel", isActive: "isActive" }, outputs: { select: "select", activate: "activate", deactivate: "deactivate", toggle: "toggle" }, host: { listeners: { "mouseenter": "onMouseEnter()", "mouseleave": "onMouseLeave()" } }, ngImport: i0, template: `
691
- <span [title]="formattedLabel" tabindex="-1" [class.active]="isActive" (click)="select.emit(formattedLabel)">
691
+ <span
692
+ [title]="formattedLabel"
693
+ tabindex="-1"
694
+ class="legend-entry"
695
+ [class.active]="isActive"
696
+ (click)="select.emit(formattedLabel)"
697
+ >
692
698
  <span class="legend-label-color" [style.background-color]="color" (click)="toggle.emit(formattedLabel)"> </span>
693
699
  <span class="legend-label-text">
694
700
  {{ trimmedLabel }}
@@ -701,7 +707,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.12", ngImpo
701
707
  args: [{
702
708
  selector: 'ngx-charts-legend-entry',
703
709
  template: `
704
- <span [title]="formattedLabel" tabindex="-1" [class.active]="isActive" (click)="select.emit(formattedLabel)">
710
+ <span
711
+ [title]="formattedLabel"
712
+ tabindex="-1"
713
+ class="legend-entry"
714
+ [class.active]="isActive"
715
+ (click)="select.emit(formattedLabel)"
716
+ >
705
717
  <span class="legend-label-color" [style.background-color]="color" (click)="toggle.emit(formattedLabel)"> </span>
706
718
  <span class="legend-label-text">
707
719
  {{ trimmedLabel }}
@@ -792,7 +804,13 @@ class LegendComponent {
792
804
  <span class="legend-title-text">{{ title }}</span>
793
805
  </header>
794
806
  <div class="legend-wrap">
795
- <ul class="legend-labels" [class.horizontal-legend]="horizontal" [style.max-height.px]="height - 45">
807
+ <ul
808
+ class="legend-labels"
809
+ [class.horizontal-legend]="horizontal"
810
+ [class.vertical-legend]="!horizontal"
811
+ [style.max-height.px]="!horizontal ? height - 45 : null"
812
+ [style.max-width.px]="horizontal && width ? width - 10 : null"
813
+ >
796
814
  <li *ngFor="let entry of legendEntries; trackBy: trackBy" class="legend-label">
797
815
  <ngx-charts-legend-entry
798
816
  [label]="entry.label"
@@ -808,7 +826,7 @@ class LegendComponent {
808
826
  </ul>
809
827
  </div>
810
828
  </div>
811
- `, isInline: true, styles: [".chart-legend{display:inline-block;padding:0;width:auto!important}.chart-legend .legend-title{white-space:nowrap;overflow:hidden;margin-left:10px;margin-bottom:5px;font-size:14px;font-weight:700}.chart-legend ul,.chart-legend li{padding:0;margin:0;list-style:none}.chart-legend .horizontal-legend li{display:inline-block}.chart-legend .legend-wrap{width:calc(100% - 10px)}.chart-legend .legend-labels{line-height:85%;list-style:none;text-align:left;float:left;width:100%;border-radius:3px;overflow-y:auto;overflow-x:hidden;white-space:nowrap;background:#0000000d}.chart-legend .legend-label{cursor:pointer;font-size:90%;margin:8px;color:#afb7c8}.chart-legend .legend-label:hover{color:#000;-webkit-transition:.2s;-moz-transition:.2s;transition:.2s}.chart-legend .legend-label .active .legend-label-text{color:#000}.chart-legend .legend-label-color{display:inline-block;height:15px;width:15px;margin-right:5px;color:#5b646b;border-radius:3px}.chart-legend .legend-label-text{display:inline-block;vertical-align:top;line-height:15px;font-size:12px;width:calc(100% - 20px);text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.chart-legend .legend-title-text{vertical-align:bottom;display:inline-block;line-height:16px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}\n"], dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: LegendEntryComponent, selector: "ngx-charts-legend-entry", inputs: ["color", "label", "formattedLabel", "isActive"], outputs: ["select", "activate", "deactivate", "toggle"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
829
+ `, isInline: true, styles: [".chart-legend{display:inline-block;padding:0;max-width:100%;box-sizing:border-box;overflow:hidden;vertical-align:top}.chart-legend .legend-title{white-space:nowrap;overflow:hidden;margin-left:10px;margin-bottom:5px;font-size:14px;font-weight:700}.chart-legend ul,.chart-legend li{padding:0;margin:0;list-style:none}.chart-legend .vertical-legend .legend-label{width:100%;max-width:calc(100% - 20px)}.chart-legend .vertical-legend .legend-entry{display:flex;flex-grow:1;align-items:center;overflow:hidden}.chart-legend .legend-wrap{width:calc(100% - 10px);min-width:0}.chart-legend .legend-labels{line-height:85%;list-style:none;text-align:left;display:flex;flex-wrap:wrap;white-space:nowrap;border-radius:3px;background:#0000000d}.chart-legend .legend-labels.vertical-legend{overflow-x:hidden;overflow-y:auto}.chart-legend .legend-labels.horizontal-legend{max-width:100%;overflow-x:auto;overflow-y:hidden}.chart-legend .legend-labels.horizontal-legend li{display:inline-block}.chart-legend .legend-label{cursor:pointer;font-size:90%;margin:8px;color:#afb7c8}.chart-legend .legend-label:hover{color:#000;-webkit-transition:.2s;-moz-transition:.2s;transition:.2s}.chart-legend .legend-label .active .legend-label-text{color:#000}.chart-legend .legend-label-color{display:inline-block;height:15px;width:15px;min-width:15px;margin-right:5px;color:#5b646b;border-radius:3px}.chart-legend .legend-label-text{display:inline-block;vertical-align:top;line-height:15px;font-size:12px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.chart-legend .legend-title-text{vertical-align:bottom;display:inline-block;line-height:16px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}\n"], dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: LegendEntryComponent, selector: "ngx-charts-legend-entry", inputs: ["color", "label", "formattedLabel", "isActive"], outputs: ["select", "activate", "deactivate", "toggle"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
812
830
  }
813
831
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.12", ngImport: i0, type: LegendComponent, decorators: [{
814
832
  type: Component,
@@ -818,7 +836,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.12", ngImpo
818
836
  <span class="legend-title-text">{{ title }}</span>
819
837
  </header>
820
838
  <div class="legend-wrap">
821
- <ul class="legend-labels" [class.horizontal-legend]="horizontal" [style.max-height.px]="height - 45">
839
+ <ul
840
+ class="legend-labels"
841
+ [class.horizontal-legend]="horizontal"
842
+ [class.vertical-legend]="!horizontal"
843
+ [style.max-height.px]="!horizontal ? height - 45 : null"
844
+ [style.max-width.px]="horizontal && width ? width - 10 : null"
845
+ >
822
846
  <li *ngFor="let entry of legendEntries; trackBy: trackBy" class="legend-label">
823
847
  <ngx-charts-legend-entry
824
848
  [label]="entry.label"
@@ -834,7 +858,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.12", ngImpo
834
858
  </ul>
835
859
  </div>
836
860
  </div>
837
- `, encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, standalone: false, styles: [".chart-legend{display:inline-block;padding:0;width:auto!important}.chart-legend .legend-title{white-space:nowrap;overflow:hidden;margin-left:10px;margin-bottom:5px;font-size:14px;font-weight:700}.chart-legend ul,.chart-legend li{padding:0;margin:0;list-style:none}.chart-legend .horizontal-legend li{display:inline-block}.chart-legend .legend-wrap{width:calc(100% - 10px)}.chart-legend .legend-labels{line-height:85%;list-style:none;text-align:left;float:left;width:100%;border-radius:3px;overflow-y:auto;overflow-x:hidden;white-space:nowrap;background:#0000000d}.chart-legend .legend-label{cursor:pointer;font-size:90%;margin:8px;color:#afb7c8}.chart-legend .legend-label:hover{color:#000;-webkit-transition:.2s;-moz-transition:.2s;transition:.2s}.chart-legend .legend-label .active .legend-label-text{color:#000}.chart-legend .legend-label-color{display:inline-block;height:15px;width:15px;margin-right:5px;color:#5b646b;border-radius:3px}.chart-legend .legend-label-text{display:inline-block;vertical-align:top;line-height:15px;font-size:12px;width:calc(100% - 20px);text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.chart-legend .legend-title-text{vertical-align:bottom;display:inline-block;line-height:16px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}\n"] }]
861
+ `, encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, standalone: false, styles: [".chart-legend{display:inline-block;padding:0;max-width:100%;box-sizing:border-box;overflow:hidden;vertical-align:top}.chart-legend .legend-title{white-space:nowrap;overflow:hidden;margin-left:10px;margin-bottom:5px;font-size:14px;font-weight:700}.chart-legend ul,.chart-legend li{padding:0;margin:0;list-style:none}.chart-legend .vertical-legend .legend-label{width:100%;max-width:calc(100% - 20px)}.chart-legend .vertical-legend .legend-entry{display:flex;flex-grow:1;align-items:center;overflow:hidden}.chart-legend .legend-wrap{width:calc(100% - 10px);min-width:0}.chart-legend .legend-labels{line-height:85%;list-style:none;text-align:left;display:flex;flex-wrap:wrap;white-space:nowrap;border-radius:3px;background:#0000000d}.chart-legend .legend-labels.vertical-legend{overflow-x:hidden;overflow-y:auto}.chart-legend .legend-labels.horizontal-legend{max-width:100%;overflow-x:auto;overflow-y:hidden}.chart-legend .legend-labels.horizontal-legend li{display:inline-block}.chart-legend .legend-label{cursor:pointer;font-size:90%;margin:8px;color:#afb7c8}.chart-legend .legend-label:hover{color:#000;-webkit-transition:.2s;-moz-transition:.2s;transition:.2s}.chart-legend .legend-label .active .legend-label-text{color:#000}.chart-legend .legend-label-color{display:inline-block;height:15px;width:15px;min-width:15px;margin-right:5px;color:#5b646b;border-radius:3px}.chart-legend .legend-label-text{display:inline-block;vertical-align:top;line-height:15px;font-size:12px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.chart-legend .legend-title-text{vertical-align:bottom;display:inline-block;line-height:16px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}\n"] }]
838
862
  }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }], propDecorators: { data: [{
839
863
  type: Input
840
864
  }], title: [{
@@ -973,6 +997,8 @@ class ChartComponent {
973
997
  <ngx-charts-scale-legend
974
998
  *ngIf="showLegend && legendType === LegendType.ScaleLegend"
975
999
  class="chart-legend"
1000
+ [style.width.px]="legendWidth"
1001
+ [style.maxWidth.px]="legendWidth"
976
1002
  [horizontal]="legendOptions && legendOptions.position === LegendPosition.Below"
977
1003
  [valueRange]="legendOptions.domain"
978
1004
  [colors]="legendOptions.colors"
@@ -983,6 +1009,8 @@ class ChartComponent {
983
1009
  <ngx-charts-legend
984
1010
  *ngIf="showLegend && legendType === LegendType.Legend"
985
1011
  class="chart-legend"
1012
+ [style.width.px]="legendWidth"
1013
+ [style.maxWidth.px]="legendWidth"
986
1014
  [horizontal]="legendOptions && legendOptions.position === LegendPosition.Below"
987
1015
  [data]="legendOptions.domain"
988
1016
  [title]="legendOptions.title"
@@ -1011,6 +1039,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.12", ngImpo
1011
1039
  <ngx-charts-scale-legend
1012
1040
  *ngIf="showLegend && legendType === LegendType.ScaleLegend"
1013
1041
  class="chart-legend"
1042
+ [style.width.px]="legendWidth"
1043
+ [style.maxWidth.px]="legendWidth"
1014
1044
  [horizontal]="legendOptions && legendOptions.position === LegendPosition.Below"
1015
1045
  [valueRange]="legendOptions.domain"
1016
1046
  [colors]="legendOptions.colors"
@@ -1021,6 +1051,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.12", ngImpo
1021
1051
  <ngx-charts-legend
1022
1052
  *ngIf="showLegend && legendType === LegendType.Legend"
1023
1053
  class="chart-legend"
1054
+ [style.width.px]="legendWidth"
1055
+ [style.maxWidth.px]="legendWidth"
1024
1056
  [horizontal]="legendOptions && legendOptions.position === LegendPosition.Below"
1025
1057
  [data]="legendOptions.domain"
1026
1058
  [title]="legendOptions.title"
@@ -2066,13 +2098,19 @@ class YAxisTicksComponent {
2066
2098
  this.update();
2067
2099
  }
2068
2100
  ngAfterViewInit() {
2069
- setTimeout(() => this.updateDims());
2101
+ // Browser: measure after paint. SSR width is applied synchronously in update().
2102
+ if (isPlatformBrowser(this.platformId)) {
2103
+ setTimeout(() => this.updateDims());
2104
+ }
2070
2105
  }
2071
2106
  updateDims() {
2072
2107
  if (!isPlatformBrowser(this.platformId)) {
2073
- // for SSR, use approximate value instead of measured
2074
- this.width = this.getApproximateAxisWidth();
2075
- this.dimensionsChanged.emit({ width: this.width });
2108
+ // SSR: approximate — no DOM metrics available
2109
+ const width = this.getApproximateAxisWidth();
2110
+ if (width > 0 && width !== this.width) {
2111
+ this.width = width;
2112
+ this.dimensionsChanged.emit({ width: this.width });
2113
+ }
2076
2114
  return;
2077
2115
  }
2078
2116
  const width = parseInt(this.ticksElement.nativeElement.getBoundingClientRect().width, 10);
@@ -2161,7 +2199,13 @@ class YAxisTicksComponent {
2161
2199
  break;
2162
2200
  default:
2163
2201
  }
2164
- setTimeout(() => this.updateDims());
2202
+ // SSR must reserve axis width before HTML serialize (no deferred setTimeout).
2203
+ if (!isPlatformBrowser(this.platformId)) {
2204
+ this.updateDims();
2205
+ }
2206
+ else {
2207
+ setTimeout(() => this.updateDims());
2208
+ }
2165
2209
  }
2166
2210
  setReferencelines() {
2167
2211
  this.refMin = this.adjustedScale(Math.min.apply(null, this.referenceLines.map(item => item.value)));
@@ -2202,10 +2246,21 @@ class YAxisTicksComponent {
2202
2246
  tickTrim(label) {
2203
2247
  return this.trimTicks ? trimLabel(label, this.maxTickLength) : label;
2204
2248
  }
2249
+ /** Approx px width for SSR / pre-measure seeding. */
2250
+ static { this.APPROX_CHAR_WIDTH = 7; }
2251
+ static approximateTickLabelsWidth(labels, trimTicks = true, maxTickLength = 16) {
2252
+ if (!labels?.length) {
2253
+ return 0;
2254
+ }
2255
+ const maxChars = Math.max(0, ...labels.map(label => (trimTicks ? trimLabel(label, maxTickLength) : String(label)).length));
2256
+ return maxChars * YAxisTicksComponent.APPROX_CHAR_WIDTH;
2257
+ }
2205
2258
  getApproximateAxisWidth() {
2206
- const maxChars = Math.max(...this.ticks.map(t => this.tickTrim(this.tickFormat(t)).length));
2207
- const charWidth = 7;
2208
- return maxChars * charWidth;
2259
+ if (!this.ticks?.length || !this.tickFormat) {
2260
+ return 0;
2261
+ }
2262
+ const labels = this.ticks.map(t => this.tickTrim(this.tickFormat(t)));
2263
+ return YAxisTicksComponent.approximateTickLabelsWidth(labels, false, this.maxTickLength);
2209
2264
  }
2210
2265
  tickChunks(label) {
2211
2266
  if (label.toString().length > this.maxTickLength && this.scale.bandwidth) {
@@ -2430,6 +2485,8 @@ class YAxisComponent {
2430
2485
  this.tickStroke = '#CCC';
2431
2486
  this.strokeWidth = 1;
2432
2487
  this.padding = 5;
2488
+ /** Last tick-label width emitted to the parent chart (not conflated with labelOffset). */
2489
+ this.emittedTickWidth = null;
2433
2490
  }
2434
2491
  ngOnChanges(changes) {
2435
2492
  this.update();
@@ -2448,18 +2505,18 @@ class YAxisComponent {
2448
2505
  }
2449
2506
  }
2450
2507
  emitTicksWidth({ width }) {
2451
- if (width !== this.labelOffset && this.yOrient === Orientation.Right) {
2452
- this.labelOffset = width + this.labelOffset;
2453
- setTimeout(() => {
2454
- this.dimensionsChanged.emit({ width });
2455
- }, 0);
2508
+ if (width == null || width === this.emittedTickWidth) {
2509
+ return;
2456
2510
  }
2457
- else if (width !== this.labelOffset) {
2511
+ this.emittedTickWidth = width;
2512
+ if (this.yOrient === Orientation.Right) {
2513
+ this.labelOffset = width + 65;
2514
+ }
2515
+ else {
2458
2516
  this.labelOffset = width;
2459
- setTimeout(() => {
2460
- this.dimensionsChanged.emit({ width });
2461
- }, 0);
2462
2517
  }
2518
+ // Sync emit so SSR HTML serializes with reserved y-axis width (no setTimeout).
2519
+ this.dimensionsChanged.emit({ width });
2463
2520
  }
2464
2521
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.12", ngImport: i0, type: YAxisComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
2465
2522
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.12", 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: `
@@ -7866,6 +7923,8 @@ class BarHorizontalComponent extends BaseChartComponent {
7866
7923
  this.dataLabelMaxWidth = { negative: 0, positive: 0 };
7867
7924
  }
7868
7925
  this.margin = [10, 20 + this.dataLabelMaxWidth.positive, 10, 20 + this.dataLabelMaxWidth.negative];
7926
+ // Seed axis width before first measure so SSR/print HTML reserves label space.
7927
+ this.seedYAxisWidthFromResults();
7869
7928
  this.dims = calculateViewDimensions({
7870
7929
  width: this.width,
7871
7930
  height: this.height,
@@ -7892,6 +7951,14 @@ class BarHorizontalComponent extends BaseChartComponent {
7892
7951
  refLines.forEach(line => parent.appendChild(line));
7893
7952
  }
7894
7953
  }
7954
+ /** Approx Y-axis width from category labels when not yet measured (SSR-safe). */
7955
+ seedYAxisWidthFromResults() {
7956
+ if (!this.yAxis || this.yAxisWidth > 0 || !this.results?.length) {
7957
+ return;
7958
+ }
7959
+ const labels = this.results.map(d => formatLabel(d.name ?? d.label));
7960
+ this.yAxisWidth = YAxisTicksComponent.approximateTickLabelsWidth(labels, this.trimYAxisTicks !== false, this.maxYAxisTickLength ?? 16);
7961
+ }
7895
7962
  getXScale() {
7896
7963
  this.xDomain = this.getXDomain();
7897
7964
  const scale = scaleLinear().range([0, this.dims.width]).domain(this.xDomain);
@@ -7944,10 +8011,16 @@ class BarHorizontalComponent extends BaseChartComponent {
7944
8011
  return opts;
7945
8012
  }
7946
8013
  updateYAxisWidth({ width }) {
8014
+ if (width === this.yAxisWidth) {
8015
+ return;
8016
+ }
7947
8017
  this.yAxisWidth = width;
7948
8018
  this.update();
7949
8019
  }
7950
8020
  updateXAxisHeight({ height }) {
8021
+ if (height === this.xAxisHeight) {
8022
+ return;
8023
+ }
7951
8024
  this.xAxisHeight = height;
7952
8025
  this.update();
7953
8026
  }