@swimlane/ngx-charts 24.0.0 → 24.0.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
|
@@ -2066,13 +2066,19 @@ class YAxisTicksComponent {
|
|
|
2066
2066
|
this.update();
|
|
2067
2067
|
}
|
|
2068
2068
|
ngAfterViewInit() {
|
|
2069
|
-
|
|
2069
|
+
// Browser: measure after paint. SSR width is applied synchronously in update().
|
|
2070
|
+
if (isPlatformBrowser(this.platformId)) {
|
|
2071
|
+
setTimeout(() => this.updateDims());
|
|
2072
|
+
}
|
|
2070
2073
|
}
|
|
2071
2074
|
updateDims() {
|
|
2072
2075
|
if (!isPlatformBrowser(this.platformId)) {
|
|
2073
|
-
//
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
+
// SSR: approximate — no DOM metrics available
|
|
2077
|
+
const width = this.getApproximateAxisWidth();
|
|
2078
|
+
if (width > 0 && width !== this.width) {
|
|
2079
|
+
this.width = width;
|
|
2080
|
+
this.dimensionsChanged.emit({ width: this.width });
|
|
2081
|
+
}
|
|
2076
2082
|
return;
|
|
2077
2083
|
}
|
|
2078
2084
|
const width = parseInt(this.ticksElement.nativeElement.getBoundingClientRect().width, 10);
|
|
@@ -2161,7 +2167,13 @@ class YAxisTicksComponent {
|
|
|
2161
2167
|
break;
|
|
2162
2168
|
default:
|
|
2163
2169
|
}
|
|
2164
|
-
|
|
2170
|
+
// SSR must reserve axis width before HTML serialize (no deferred setTimeout).
|
|
2171
|
+
if (!isPlatformBrowser(this.platformId)) {
|
|
2172
|
+
this.updateDims();
|
|
2173
|
+
}
|
|
2174
|
+
else {
|
|
2175
|
+
setTimeout(() => this.updateDims());
|
|
2176
|
+
}
|
|
2165
2177
|
}
|
|
2166
2178
|
setReferencelines() {
|
|
2167
2179
|
this.refMin = this.adjustedScale(Math.min.apply(null, this.referenceLines.map(item => item.value)));
|
|
@@ -2202,10 +2214,21 @@ class YAxisTicksComponent {
|
|
|
2202
2214
|
tickTrim(label) {
|
|
2203
2215
|
return this.trimTicks ? trimLabel(label, this.maxTickLength) : label;
|
|
2204
2216
|
}
|
|
2217
|
+
/** Approx px width for SSR / pre-measure seeding. */
|
|
2218
|
+
static { this.APPROX_CHAR_WIDTH = 7; }
|
|
2219
|
+
static approximateTickLabelsWidth(labels, trimTicks = true, maxTickLength = 16) {
|
|
2220
|
+
if (!labels?.length) {
|
|
2221
|
+
return 0;
|
|
2222
|
+
}
|
|
2223
|
+
const maxChars = Math.max(0, ...labels.map(label => (trimTicks ? trimLabel(label, maxTickLength) : String(label)).length));
|
|
2224
|
+
return maxChars * YAxisTicksComponent.APPROX_CHAR_WIDTH;
|
|
2225
|
+
}
|
|
2205
2226
|
getApproximateAxisWidth() {
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2227
|
+
if (!this.ticks?.length || !this.tickFormat) {
|
|
2228
|
+
return 0;
|
|
2229
|
+
}
|
|
2230
|
+
const labels = this.ticks.map(t => this.tickTrim(this.tickFormat(t)));
|
|
2231
|
+
return YAxisTicksComponent.approximateTickLabelsWidth(labels, false, this.maxTickLength);
|
|
2209
2232
|
}
|
|
2210
2233
|
tickChunks(label) {
|
|
2211
2234
|
if (label.toString().length > this.maxTickLength && this.scale.bandwidth) {
|
|
@@ -2430,6 +2453,8 @@ class YAxisComponent {
|
|
|
2430
2453
|
this.tickStroke = '#CCC';
|
|
2431
2454
|
this.strokeWidth = 1;
|
|
2432
2455
|
this.padding = 5;
|
|
2456
|
+
/** Last tick-label width emitted to the parent chart (not conflated with labelOffset). */
|
|
2457
|
+
this.emittedTickWidth = null;
|
|
2433
2458
|
}
|
|
2434
2459
|
ngOnChanges(changes) {
|
|
2435
2460
|
this.update();
|
|
@@ -2448,18 +2473,18 @@ class YAxisComponent {
|
|
|
2448
2473
|
}
|
|
2449
2474
|
}
|
|
2450
2475
|
emitTicksWidth({ width }) {
|
|
2451
|
-
if (width
|
|
2452
|
-
|
|
2453
|
-
setTimeout(() => {
|
|
2454
|
-
this.dimensionsChanged.emit({ width });
|
|
2455
|
-
}, 0);
|
|
2476
|
+
if (width == null || width === this.emittedTickWidth) {
|
|
2477
|
+
return;
|
|
2456
2478
|
}
|
|
2457
|
-
|
|
2479
|
+
this.emittedTickWidth = width;
|
|
2480
|
+
if (this.yOrient === Orientation.Right) {
|
|
2481
|
+
this.labelOffset = width + 65;
|
|
2482
|
+
}
|
|
2483
|
+
else {
|
|
2458
2484
|
this.labelOffset = width;
|
|
2459
|
-
setTimeout(() => {
|
|
2460
|
-
this.dimensionsChanged.emit({ width });
|
|
2461
|
-
}, 0);
|
|
2462
2485
|
}
|
|
2486
|
+
// Sync emit so SSR HTML serializes with reserved y-axis width (no setTimeout).
|
|
2487
|
+
this.dimensionsChanged.emit({ width });
|
|
2463
2488
|
}
|
|
2464
2489
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.12", ngImport: i0, type: YAxisComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
2465
2490
|
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 +7891,8 @@ class BarHorizontalComponent extends BaseChartComponent {
|
|
|
7866
7891
|
this.dataLabelMaxWidth = { negative: 0, positive: 0 };
|
|
7867
7892
|
}
|
|
7868
7893
|
this.margin = [10, 20 + this.dataLabelMaxWidth.positive, 10, 20 + this.dataLabelMaxWidth.negative];
|
|
7894
|
+
// Seed axis width before first measure so SSR/print HTML reserves label space.
|
|
7895
|
+
this.seedYAxisWidthFromResults();
|
|
7869
7896
|
this.dims = calculateViewDimensions({
|
|
7870
7897
|
width: this.width,
|
|
7871
7898
|
height: this.height,
|
|
@@ -7892,6 +7919,14 @@ class BarHorizontalComponent extends BaseChartComponent {
|
|
|
7892
7919
|
refLines.forEach(line => parent.appendChild(line));
|
|
7893
7920
|
}
|
|
7894
7921
|
}
|
|
7922
|
+
/** Approx Y-axis width from category labels when not yet measured (SSR-safe). */
|
|
7923
|
+
seedYAxisWidthFromResults() {
|
|
7924
|
+
if (!this.yAxis || this.yAxisWidth > 0 || !this.results?.length) {
|
|
7925
|
+
return;
|
|
7926
|
+
}
|
|
7927
|
+
const labels = this.results.map(d => formatLabel(d.name ?? d.label));
|
|
7928
|
+
this.yAxisWidth = YAxisTicksComponent.approximateTickLabelsWidth(labels, this.trimYAxisTicks !== false, this.maxYAxisTickLength ?? 16);
|
|
7929
|
+
}
|
|
7895
7930
|
getXScale() {
|
|
7896
7931
|
this.xDomain = this.getXDomain();
|
|
7897
7932
|
const scale = scaleLinear().range([0, this.dims.width]).domain(this.xDomain);
|
|
@@ -7944,10 +7979,16 @@ class BarHorizontalComponent extends BaseChartComponent {
|
|
|
7944
7979
|
return opts;
|
|
7945
7980
|
}
|
|
7946
7981
|
updateYAxisWidth({ width }) {
|
|
7982
|
+
if (width === this.yAxisWidth) {
|
|
7983
|
+
return;
|
|
7984
|
+
}
|
|
7947
7985
|
this.yAxisWidth = width;
|
|
7948
7986
|
this.update();
|
|
7949
7987
|
}
|
|
7950
7988
|
updateXAxisHeight({ height }) {
|
|
7989
|
+
if (height === this.xAxisHeight) {
|
|
7990
|
+
return;
|
|
7991
|
+
}
|
|
7951
7992
|
this.xAxisHeight = height;
|
|
7952
7993
|
this.update();
|
|
7953
7994
|
}
|