@swimlane/ngx-charts 23.0.0 → 23.1.0
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/fesm2022/swimlane-ngx-charts.mjs +174 -7
- package/fesm2022/swimlane-ngx-charts.mjs.map +1 -1
- package/index.d.ts +18 -3
- package/package.json +1 -1
- package/CHANGELOG.md +0 -761
- package/LICENSE +0 -21
- package/README.md +0 -79
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { PLATFORM_ID, Component, ViewEncapsulation, Inject, Input, ViewChild, HostBinding, HostListener, Injectable, EventEmitter, ChangeDetectionStrategy, Output, Directive, NgModule, ContentChild } from '@angular/core';
|
|
2
|
+
import { PLATFORM_ID, Component, ViewEncapsulation, Inject, Input, ViewChild, HostBinding, HostListener, Injectable, EventEmitter, ChangeDetectionStrategy, Output, Directive, NgModule, ContentChild, ViewChildren } from '@angular/core';
|
|
3
3
|
import * as i1 from '@angular/common';
|
|
4
4
|
import { isPlatformBrowser, isPlatformServer, CommonModule } from '@angular/common';
|
|
5
5
|
import { __decorate } from 'tslib';
|
|
@@ -4279,10 +4279,42 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImpor
|
|
|
4279
4279
|
type: Output
|
|
4280
4280
|
}] } });
|
|
4281
4281
|
|
|
4282
|
+
/**
|
|
4283
|
+
* Rounds percentages using the largest remainder method to ensure they always sum to 100%
|
|
4284
|
+
*
|
|
4285
|
+
* @param values Array of numeric values
|
|
4286
|
+
* @returns Array of rounded percentages with decimals
|
|
4287
|
+
*/
|
|
4288
|
+
function roundPercentagesWithDecimals(values, decimals = 2) {
|
|
4289
|
+
const total = values.reduce((a, b) => a + b, 0);
|
|
4290
|
+
if (total === 0)
|
|
4291
|
+
return values.map(_ => '0.00');
|
|
4292
|
+
const scale = Math.pow(10, decimals + 2);
|
|
4293
|
+
const rawUnits = values.map(v => (v / total) * scale);
|
|
4294
|
+
const floored = rawUnits.map(u => Math.floor(u));
|
|
4295
|
+
const remainders = rawUnits.map((u, i) => ({ i, rem: u - floored[i] }));
|
|
4296
|
+
const sumFloored = floored.reduce((a, b) => a + b, 0);
|
|
4297
|
+
const diff = scale - sumFloored;
|
|
4298
|
+
if (diff > 0) {
|
|
4299
|
+
remainders.sort((a, b) => b.rem - a.rem);
|
|
4300
|
+
for (let k = 0; k < diff; k++) {
|
|
4301
|
+
floored[remainders[k].i] += 1;
|
|
4302
|
+
}
|
|
4303
|
+
}
|
|
4304
|
+
else if (diff < 0) {
|
|
4305
|
+
remainders.sort((a, b) => a.rem - b.rem);
|
|
4306
|
+
for (let k = 0; k < -diff; k++) {
|
|
4307
|
+
floored[remainders[k].i] -= 1;
|
|
4308
|
+
}
|
|
4309
|
+
}
|
|
4310
|
+
return floored.map(u => (u / 100).toFixed(2));
|
|
4311
|
+
}
|
|
4312
|
+
|
|
4282
4313
|
class AdvancedLegendComponent {
|
|
4283
4314
|
constructor() {
|
|
4284
4315
|
this.label = 'Total';
|
|
4285
4316
|
this.animations = true;
|
|
4317
|
+
this.roundPercentages = true;
|
|
4286
4318
|
this.select = new EventEmitter();
|
|
4287
4319
|
this.activate = new EventEmitter();
|
|
4288
4320
|
this.deactivate = new EventEmitter();
|
|
@@ -4303,11 +4335,15 @@ class AdvancedLegendComponent {
|
|
|
4303
4335
|
this.legendItems = this.getLegendItems();
|
|
4304
4336
|
}
|
|
4305
4337
|
getLegendItems() {
|
|
4306
|
-
|
|
4338
|
+
const values = this.data.map(d => Number(d.value));
|
|
4339
|
+
const percentages = this.roundPercentages
|
|
4340
|
+
? roundPercentagesWithDecimals(values)
|
|
4341
|
+
: values.map(v => (v / this.total) * 100);
|
|
4342
|
+
return this.data.map((d, index) => {
|
|
4307
4343
|
const label = formatLabel(d.name);
|
|
4308
4344
|
const value = d.value;
|
|
4309
4345
|
const color = this.colors.getColor(label);
|
|
4310
|
-
const percentage = this.
|
|
4346
|
+
const percentage = this.roundPercentages ? percentages[index] : this.getPercentage(values[index]);
|
|
4311
4347
|
const formattedLabel = typeof this.labelFormatting === 'function' ? this.labelFormatting(label) : label;
|
|
4312
4348
|
return {
|
|
4313
4349
|
_value: value,
|
|
@@ -4317,15 +4353,20 @@ class AdvancedLegendComponent {
|
|
|
4317
4353
|
label: formattedLabel,
|
|
4318
4354
|
displayLabel: trimLabel(formattedLabel, 20),
|
|
4319
4355
|
origialLabel: d.name,
|
|
4320
|
-
percentage: this.percentageFormatting
|
|
4356
|
+
percentage: this.percentageFormatting
|
|
4357
|
+
? this.percentageFormatting(parseFloat(percentage.toLocaleString()))
|
|
4358
|
+
: percentage.toLocaleString()
|
|
4321
4359
|
};
|
|
4322
4360
|
});
|
|
4323
4361
|
}
|
|
4362
|
+
getPercentage(value) {
|
|
4363
|
+
return this.total > 0 ? (value / this.total) * 100 : 0;
|
|
4364
|
+
}
|
|
4324
4365
|
trackBy(index, item) {
|
|
4325
4366
|
return item.label;
|
|
4326
4367
|
}
|
|
4327
4368
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: AdvancedLegendComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
4328
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.0.4", type: AdvancedLegendComponent, isStandalone: false, selector: "ngx-charts-advanced-legend", inputs: { width: "width", data: "data", colors: "colors", label: "label", animations: "animations", valueFormatting: "valueFormatting", labelFormatting: "labelFormatting", percentageFormatting: "percentageFormatting" }, outputs: { select: "select", activate: "activate", deactivate: "deactivate" }, usesOnChanges: true, ngImport: i0, template: `
|
|
4369
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.0.4", type: AdvancedLegendComponent, isStandalone: false, selector: "ngx-charts-advanced-legend", inputs: { width: "width", data: "data", colors: "colors", label: "label", animations: "animations", roundPercentages: "roundPercentages", valueFormatting: "valueFormatting", labelFormatting: "labelFormatting", percentageFormatting: "percentageFormatting" }, outputs: { select: "select", activate: "activate", deactivate: "deactivate" }, usesOnChanges: true, ngImport: i0, template: `
|
|
4329
4370
|
<div class="advanced-pie-legend" [style.width.px]="width">
|
|
4330
4371
|
<div
|
|
4331
4372
|
*ngIf="animations"
|
|
@@ -4366,6 +4407,7 @@ class AdvancedLegendComponent {
|
|
|
4366
4407
|
*ngIf="animations"
|
|
4367
4408
|
class="item-percent"
|
|
4368
4409
|
ngx-charts-count-up
|
|
4410
|
+
[countDecimals]="2"
|
|
4369
4411
|
[countTo]="legendItem.percentage"
|
|
4370
4412
|
[countSuffix]="'%'"
|
|
4371
4413
|
></div>
|
|
@@ -4419,6 +4461,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImpor
|
|
|
4419
4461
|
*ngIf="animations"
|
|
4420
4462
|
class="item-percent"
|
|
4421
4463
|
ngx-charts-count-up
|
|
4464
|
+
[countDecimals]="2"
|
|
4422
4465
|
[countTo]="legendItem.percentage"
|
|
4423
4466
|
[countSuffix]="'%'"
|
|
4424
4467
|
></div>
|
|
@@ -4438,6 +4481,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImpor
|
|
|
4438
4481
|
type: Input
|
|
4439
4482
|
}], animations: [{
|
|
4440
4483
|
type: Input
|
|
4484
|
+
}], roundPercentages: [{
|
|
4485
|
+
type: Input
|
|
4441
4486
|
}], select: [{
|
|
4442
4487
|
type: Output
|
|
4443
4488
|
}], activate: [{
|
|
@@ -17131,7 +17176,7 @@ class AdvancedPieChartComponent extends BaseChartComponent {
|
|
|
17131
17176
|
</ngx-charts-advanced-legend>
|
|
17132
17177
|
</div>
|
|
17133
17178
|
</div>
|
|
17134
|
-
`, isInline: true, styles: [".ngx-charts-outer{animation:chartFadeIn linear .6s}@keyframes chartFadeIn{0%{opacity:0}20%{opacity:0}to{opacity:1}}.ngx-charts{float:left;overflow:visible}.ngx-charts .circle,.ngx-charts .cell,.ngx-charts .bar,.ngx-charts .node,.ngx-charts .link,.ngx-charts .arc{cursor:pointer}.ngx-charts .bar.active,.ngx-charts .bar:hover,.ngx-charts .cell.active,.ngx-charts .cell:hover,.ngx-charts .arc.active,.ngx-charts .arc:hover,.ngx-charts .node.active,.ngx-charts .node:hover,.ngx-charts .link.active,.ngx-charts .link:hover,.ngx-charts .card.active,.ngx-charts .card:hover{opacity:.8;transition:opacity .1s ease-in-out}.ngx-charts .bar:focus,.ngx-charts .cell:focus,.ngx-charts .arc:focus,.ngx-charts .node:focus,.ngx-charts .link:focus,.ngx-charts .card:focus{outline:none}.ngx-charts .bar.hidden,.ngx-charts .cell.hidden,.ngx-charts .arc.hidden,.ngx-charts .node.hidden,.ngx-charts .link.hidden,.ngx-charts .card.hidden{display:none}.ngx-charts g:focus{outline:none}.ngx-charts .line-series.inactive,.ngx-charts .line-series-range.inactive,.ngx-charts .polar-series-path.inactive,.ngx-charts .polar-series-area.inactive,.ngx-charts .area-series.inactive{transition:opacity .1s ease-in-out;opacity:.2}.ngx-charts .line-highlight{display:none}.ngx-charts .line-highlight.active{display:block}.ngx-charts .area{opacity:.6}.ngx-charts .circle:hover{cursor:pointer}.ngx-charts .label{font-size:12px;font-weight:400}.ngx-charts .tooltip-anchor{fill:#000}.ngx-charts .gridline-path{stroke:#ddd;stroke-width:1;fill:none}.ngx-charts .refline-path{stroke:#a8b2c7;stroke-width:1;stroke-dasharray:5;stroke-dashoffset:5}.ngx-charts .refline-label{font-size:9px}.ngx-charts .reference-area{fill-opacity:.05;fill:#000}.ngx-charts .gridline-path-dotted{stroke:#ddd;stroke-width:1;fill:none;stroke-dasharray:1,20;stroke-dashoffset:3}.ngx-charts .grid-panel rect{fill:none}.ngx-charts .grid-panel.odd rect{fill:#0000000d}\n", ".advanced-pie{display:inline-block;float:left}.advanced-pie-legend-wrapper{display:inline-block}\n"], dependencies: [{ kind: "component", type: ChartComponent, selector: "ngx-charts-chart", inputs: ["view", "showLegend", "legendOptions", "legendType", "activeEntries", "animations"], outputs: ["legendLabelClick", "legendLabelActivate", "legendLabelDeactivate"] }, { kind: "component", type: AdvancedLegendComponent, selector: "ngx-charts-advanced-legend", inputs: ["width", "data", "colors", "label", "animations", "valueFormatting", "labelFormatting", "percentageFormatting"], outputs: ["select", "activate", "deactivate"] }, { kind: "component", type: PieSeriesComponent, selector: "g[ngx-charts-pie-series]", inputs: ["colors", "series", "dims", "innerRadius", "outerRadius", "explodeSlices", "showLabels", "gradient", "activeEntries", "labelFormatting", "trimLabels", "maxLabelLength", "tooltipText", "tooltipDisabled", "tooltipTemplate", "animations"], outputs: ["select", "activate", "deactivate", "dblclick"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
|
17179
|
+
`, isInline: true, styles: [".ngx-charts-outer{animation:chartFadeIn linear .6s}@keyframes chartFadeIn{0%{opacity:0}20%{opacity:0}to{opacity:1}}.ngx-charts{float:left;overflow:visible}.ngx-charts .circle,.ngx-charts .cell,.ngx-charts .bar,.ngx-charts .node,.ngx-charts .link,.ngx-charts .arc{cursor:pointer}.ngx-charts .bar.active,.ngx-charts .bar:hover,.ngx-charts .cell.active,.ngx-charts .cell:hover,.ngx-charts .arc.active,.ngx-charts .arc:hover,.ngx-charts .node.active,.ngx-charts .node:hover,.ngx-charts .link.active,.ngx-charts .link:hover,.ngx-charts .card.active,.ngx-charts .card:hover{opacity:.8;transition:opacity .1s ease-in-out}.ngx-charts .bar:focus,.ngx-charts .cell:focus,.ngx-charts .arc:focus,.ngx-charts .node:focus,.ngx-charts .link:focus,.ngx-charts .card:focus{outline:none}.ngx-charts .bar.hidden,.ngx-charts .cell.hidden,.ngx-charts .arc.hidden,.ngx-charts .node.hidden,.ngx-charts .link.hidden,.ngx-charts .card.hidden{display:none}.ngx-charts g:focus{outline:none}.ngx-charts .line-series.inactive,.ngx-charts .line-series-range.inactive,.ngx-charts .polar-series-path.inactive,.ngx-charts .polar-series-area.inactive,.ngx-charts .area-series.inactive{transition:opacity .1s ease-in-out;opacity:.2}.ngx-charts .line-highlight{display:none}.ngx-charts .line-highlight.active{display:block}.ngx-charts .area{opacity:.6}.ngx-charts .circle:hover{cursor:pointer}.ngx-charts .label{font-size:12px;font-weight:400}.ngx-charts .tooltip-anchor{fill:#000}.ngx-charts .gridline-path{stroke:#ddd;stroke-width:1;fill:none}.ngx-charts .refline-path{stroke:#a8b2c7;stroke-width:1;stroke-dasharray:5;stroke-dashoffset:5}.ngx-charts .refline-label{font-size:9px}.ngx-charts .reference-area{fill-opacity:.05;fill:#000}.ngx-charts .gridline-path-dotted{stroke:#ddd;stroke-width:1;fill:none;stroke-dasharray:1,20;stroke-dashoffset:3}.ngx-charts .grid-panel rect{fill:none}.ngx-charts .grid-panel.odd rect{fill:#0000000d}\n", ".advanced-pie{display:inline-block;float:left}.advanced-pie-legend-wrapper{display:inline-block}\n"], dependencies: [{ kind: "component", type: ChartComponent, selector: "ngx-charts-chart", inputs: ["view", "showLegend", "legendOptions", "legendType", "activeEntries", "animations"], outputs: ["legendLabelClick", "legendLabelActivate", "legendLabelDeactivate"] }, { kind: "component", type: AdvancedLegendComponent, selector: "ngx-charts-advanced-legend", inputs: ["width", "data", "colors", "label", "animations", "roundPercentages", "valueFormatting", "labelFormatting", "percentageFormatting"], outputs: ["select", "activate", "deactivate"] }, { kind: "component", type: PieSeriesComponent, selector: "g[ngx-charts-pie-series]", inputs: ["colors", "series", "dims", "innerRadius", "outerRadius", "explodeSlices", "showLabels", "gradient", "activeEntries", "labelFormatting", "trimLabels", "maxLabelLength", "tooltipText", "tooltipDisabled", "tooltipTemplate", "animations"], outputs: ["select", "activate", "deactivate", "dblclick"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
|
17135
17180
|
}
|
|
17136
17181
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: AdvancedPieChartComponent, decorators: [{
|
|
17137
17182
|
type: Component,
|
|
@@ -20384,6 +20429,7 @@ class SankeyComponent extends BaseChartComponent {
|
|
|
20384
20429
|
this.showLabels = true;
|
|
20385
20430
|
this.tooltipDisabled = false;
|
|
20386
20431
|
this.activeEntries = [];
|
|
20432
|
+
this.truncateLabels = true;
|
|
20387
20433
|
this.activate = new EventEmitter();
|
|
20388
20434
|
this.deactivate = new EventEmitter();
|
|
20389
20435
|
this.margin = [10, 10, 10, 10];
|
|
@@ -20439,6 +20485,8 @@ class SankeyComponent extends BaseChartComponent {
|
|
|
20439
20485
|
},
|
|
20440
20486
|
transform: '',
|
|
20441
20487
|
label: this.labelFormatting ? this.labelFormatting(node.name) : node.name,
|
|
20488
|
+
originalLabel: node.name,
|
|
20489
|
+
node: node,
|
|
20442
20490
|
labelAnchor: TextAnchor.Start
|
|
20443
20491
|
};
|
|
20444
20492
|
rect.labelAnchor = this.getTextAnchor(node);
|
|
@@ -20465,6 +20513,11 @@ class SankeyComponent extends BaseChartComponent {
|
|
|
20465
20513
|
};
|
|
20466
20514
|
return linkPath;
|
|
20467
20515
|
});
|
|
20516
|
+
this.nodeLayerMap = this.getNodeLayerMap(data.nodes);
|
|
20517
|
+
if (this.truncateLabels) {
|
|
20518
|
+
this.truncateLabelsBasedOnAdjacentNodes();
|
|
20519
|
+
this.fixOverlappingLabels();
|
|
20520
|
+
}
|
|
20468
20521
|
this.transform = `translate(${this.dims.xOffset} , ${this.margin[0]})`;
|
|
20469
20522
|
}
|
|
20470
20523
|
getNodeTooltipText(node) {
|
|
@@ -20553,8 +20606,115 @@ class SankeyComponent extends BaseChartComponent {
|
|
|
20553
20606
|
get hasActive() {
|
|
20554
20607
|
return this.linkPaths.some(l => l.active) || this.nodeRects.some(r => r.active);
|
|
20555
20608
|
}
|
|
20609
|
+
/** Truncate labels to prevent overflow outside the chart */
|
|
20610
|
+
truncateLabelsBasedOnAdjacentNodes() {
|
|
20611
|
+
this.nodeRects.forEach(rect => {
|
|
20612
|
+
// Currently we dont display labels for nodes with height less than 15
|
|
20613
|
+
if (rect.height <= 15 || !rect.node) {
|
|
20614
|
+
return;
|
|
20615
|
+
}
|
|
20616
|
+
const availableWidth = this.calculateAvailableSpaceForLabel(rect);
|
|
20617
|
+
if (availableWidth > 0) {
|
|
20618
|
+
const charWidth = 6;
|
|
20619
|
+
const maxChars = Math.floor(availableWidth / charWidth);
|
|
20620
|
+
const truncatedLabel = trimLabel(rect.originalLabel, maxChars);
|
|
20621
|
+
rect.label = this.labelFormatting ? this.labelFormatting(truncatedLabel) : truncatedLabel;
|
|
20622
|
+
}
|
|
20623
|
+
});
|
|
20624
|
+
}
|
|
20625
|
+
calculateAvailableSpaceForLabel(rect) {
|
|
20626
|
+
const node = rect.node;
|
|
20627
|
+
const labelMargin = 10; // Margin between label and adjacent nodes
|
|
20628
|
+
const labelOffset = 5; // using in template [attr.x]="rect.width + 5"
|
|
20629
|
+
const rightSideExtraOffset = 15; // from [attr.dx]
|
|
20630
|
+
// Checking if the node is on left side or right side to label
|
|
20631
|
+
const isLeftSideNode = rect.labelAnchor === TextAnchor.Start;
|
|
20632
|
+
// Get corresponding nodes from adjacent layer
|
|
20633
|
+
const adjacentNodes = this.getAdjacentLayerNodes(node, isLeftSideNode);
|
|
20634
|
+
// Find nodes that vertically overlap with this node's label area
|
|
20635
|
+
const labelCenterY = rect.y + rect.height / 2;
|
|
20636
|
+
const labelHeight = 14;
|
|
20637
|
+
const labelTop = labelCenterY - labelHeight / 2;
|
|
20638
|
+
const labelBottom = labelCenterY + labelHeight / 2;
|
|
20639
|
+
let minDistance = Infinity;
|
|
20640
|
+
if (adjacentNodes?.length) {
|
|
20641
|
+
adjacentNodes.forEach(adjNode => {
|
|
20642
|
+
if (adjNode.y0 < labelBottom && adjNode.y1 > labelTop) {
|
|
20643
|
+
let distance;
|
|
20644
|
+
if (isLeftSideNode) {
|
|
20645
|
+
// Label starts at node.x1 + labelOffset and extends to the right
|
|
20646
|
+
const labelStart = rect.x + rect.width + labelOffset;
|
|
20647
|
+
distance = adjNode.x0 - labelStart - labelMargin;
|
|
20648
|
+
}
|
|
20649
|
+
else {
|
|
20650
|
+
// For right-side labels, text-anchor="end" means text extends left from the anchor point
|
|
20651
|
+
// The anchor is at node.x0 - rightSideExtraOffset
|
|
20652
|
+
const labelStart = rect.x - rightSideExtraOffset;
|
|
20653
|
+
distance = labelStart - adjNode.x1 - labelMargin;
|
|
20654
|
+
}
|
|
20655
|
+
minDistance = Math.min(minDistance, distance);
|
|
20656
|
+
}
|
|
20657
|
+
});
|
|
20658
|
+
}
|
|
20659
|
+
// If no adjacent nodes found, use distance to chart edge
|
|
20660
|
+
if (minDistance === Infinity) {
|
|
20661
|
+
const chartPadding = 20; // Padding from chart edges
|
|
20662
|
+
if (isLeftSideNode) {
|
|
20663
|
+
// Check distance to right edge of chart
|
|
20664
|
+
const labelStart = rect.x + rect.width + labelOffset;
|
|
20665
|
+
minDistance = this.dims.width - labelStart - chartPadding;
|
|
20666
|
+
}
|
|
20667
|
+
else {
|
|
20668
|
+
// Check distance to left edge of chart
|
|
20669
|
+
const labelAnchor = rect.x - rightSideExtraOffset;
|
|
20670
|
+
minDistance = labelAnchor - chartPadding;
|
|
20671
|
+
}
|
|
20672
|
+
}
|
|
20673
|
+
return Math.max(minDistance, 20); // At least 20px for label
|
|
20674
|
+
}
|
|
20675
|
+
getAdjacentLayerNodes(node, isLeftSideNode) {
|
|
20676
|
+
const currentLayer = node.layer;
|
|
20677
|
+
// Determine which layer to check based on label position
|
|
20678
|
+
const targetLayer = isLeftSideNode ? currentLayer + 1 : currentLayer - 1;
|
|
20679
|
+
// Filter nodes in the target layer
|
|
20680
|
+
const adjacentNodes = this.nodeLayerMap.get(targetLayer);
|
|
20681
|
+
// If no nodes in adjacent layer, try the next layer
|
|
20682
|
+
if (!adjacentNodes?.length) {
|
|
20683
|
+
const nextLayer = isLeftSideNode ? currentLayer + 2 : currentLayer - 2;
|
|
20684
|
+
return this.nodeLayerMap.get(nextLayer);
|
|
20685
|
+
}
|
|
20686
|
+
return adjacentNodes;
|
|
20687
|
+
}
|
|
20688
|
+
getNodeLayerMap(nodes) {
|
|
20689
|
+
const nodeLayerMap = new Map();
|
|
20690
|
+
nodes.forEach(node => {
|
|
20691
|
+
if (!nodeLayerMap.has(node.layer)) {
|
|
20692
|
+
nodeLayerMap.set(node.layer, []);
|
|
20693
|
+
}
|
|
20694
|
+
nodeLayerMap.get(node.layer).push(node);
|
|
20695
|
+
});
|
|
20696
|
+
return nodeLayerMap;
|
|
20697
|
+
}
|
|
20698
|
+
/** handle label overlapping between nodes on layer1 and layer2 */
|
|
20699
|
+
fixOverlappingLabels() {
|
|
20700
|
+
const firstLayerRects = this.nodeRects.filter(r => r.node && r.node.layer === 0);
|
|
20701
|
+
const secondLayerRects = this.nodeRects.filter(r => r.node && r.node.layer === 1);
|
|
20702
|
+
firstLayerRects.forEach(rect1 => {
|
|
20703
|
+
secondLayerRects.forEach(rect2 => {
|
|
20704
|
+
if (Math.abs(rect1.y + rect1.height / 2 - (rect2.y + rect2.height / 2)) < 14 &&
|
|
20705
|
+
rect1.height > 15 &&
|
|
20706
|
+
rect2.height > 15) {
|
|
20707
|
+
let width = rect2.x - (rect1.x + rect1.width);
|
|
20708
|
+
width /= 2;
|
|
20709
|
+
const charsToFit = Math.floor(width / 7);
|
|
20710
|
+
rect2.label = trimLabel(rect2.originalLabel, charsToFit);
|
|
20711
|
+
rect1.label = trimLabel(rect1.originalLabel, charsToFit);
|
|
20712
|
+
}
|
|
20713
|
+
});
|
|
20714
|
+
});
|
|
20715
|
+
}
|
|
20556
20716
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.4", ngImport: i0, type: SankeyComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
|
|
20557
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.0.4", type: SankeyComponent, isStandalone: false, selector: "ngx-charts-sankey", inputs: { showLabels: "showLabels", gradient: "gradient", tooltipDisabled: "tooltipDisabled", activeEntries: "activeEntries", labelFormatting: "labelFormatting" }, outputs: { activate: "activate", deactivate: "deactivate" }, queries: [{ propertyName: "tooltipTemplate", first: true, predicate: ["tooltipTemplate"], descendants: true }], usesInheritance: true, usesOnChanges: true, ngImport: i0, template: `
|
|
20717
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.0.4", type: SankeyComponent, isStandalone: false, selector: "ngx-charts-sankey", inputs: { showLabels: "showLabels", gradient: "gradient", tooltipDisabled: "tooltipDisabled", activeEntries: "activeEntries", labelFormatting: "labelFormatting", truncateLabels: "truncateLabels" }, outputs: { activate: "activate", deactivate: "deactivate" }, queries: [{ propertyName: "tooltipTemplate", first: true, predicate: ["tooltipTemplate"], descendants: true }], viewQueries: [{ propertyName: "labelElements", predicate: ["labelElement"], descendants: true }], usesInheritance: true, usesOnChanges: true, ngImport: i0, template: `
|
|
20558
20718
|
<ngx-charts-chart [view]="[width, height]" [animations]="animations">
|
|
20559
20719
|
<svg:g [attr.transform]="transform" class="sankey chart">
|
|
20560
20720
|
<svg:g
|
|
@@ -20614,6 +20774,7 @@ class SankeyComponent extends BaseChartComponent {
|
|
|
20614
20774
|
|
|
20615
20775
|
<svg:g *ngFor="let rect of nodeRects" [attr.transform]="rect.transform">
|
|
20616
20776
|
<svg:text
|
|
20777
|
+
#labelElement
|
|
20617
20778
|
*ngIf="showLabels && rect.height > 15"
|
|
20618
20779
|
class="label"
|
|
20619
20780
|
[attr.x]="rect.width + 5"
|
|
@@ -20692,6 +20853,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImpor
|
|
|
20692
20853
|
|
|
20693
20854
|
<svg:g *ngFor="let rect of nodeRects" [attr.transform]="rect.transform">
|
|
20694
20855
|
<svg:text
|
|
20856
|
+
#labelElement
|
|
20695
20857
|
*ngIf="showLabels && rect.height > 15"
|
|
20696
20858
|
class="label"
|
|
20697
20859
|
[attr.x]="rect.width + 5"
|
|
@@ -20717,10 +20879,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.4", ngImpor
|
|
|
20717
20879
|
type: Input
|
|
20718
20880
|
}], labelFormatting: [{
|
|
20719
20881
|
type: Input
|
|
20882
|
+
}], truncateLabels: [{
|
|
20883
|
+
type: Input
|
|
20720
20884
|
}], activate: [{
|
|
20721
20885
|
type: Output
|
|
20722
20886
|
}], deactivate: [{
|
|
20723
20887
|
type: Output
|
|
20888
|
+
}], labelElements: [{
|
|
20889
|
+
type: ViewChildren,
|
|
20890
|
+
args: ['labelElement']
|
|
20724
20891
|
}], tooltipTemplate: [{
|
|
20725
20892
|
type: ContentChild,
|
|
20726
20893
|
args: ['tooltipTemplate']
|