pace-chart-lib 0.0.7 → 0.0.8
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/README.md +10 -10
- package/dist/Components1/Charts/ChartsWithAxis/ChartsWithAxisFunctions.d.ts +46 -0
- package/dist/Components1/Charts/ChartsWithAxis/ChartsWithAxisFunctions.js +2285 -0
- package/dist/Components1/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.d.ts +169 -0
- package/dist/Components1/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.js +47 -0
- package/dist/Components1/Charts/ChartsWithAxis/LineFamily/LineChart.d.ts +4 -0
- package/dist/Components1/Charts/ChartsWithAxis/LineFamily/LineChart.js +403 -0
- package/dist/Components1/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.d.ts +0 -0
- package/dist/Components1/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.js +0 -0
- package/dist/Components1/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.d.ts +0 -0
- package/dist/Components1/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.js +0 -0
- package/dist/Components1/Charts/Core/Common.type.d.ts +8 -0
- package/dist/Components1/Charts/Core/Common.type.js +9 -0
- package/dist/Components1/Charts/Core/CommonFunctions.d.ts +12 -0
- package/dist/Components1/Charts/Core/CommonFunctions.js +512 -0
- package/dist/Components1/Charts/Core/DefaultProperties.d.ts +586 -0
- package/dist/Components1/Charts/Core/DefaultProperties.js +585 -0
- package/dist/Services/ErrorLog.d.ts +1 -0
- package/dist/Services/ErrorLog.js +3 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/AreaChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/AreaChart.js +497 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/LineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/LineChart.js +491 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackAreaChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackAreaChart.js +520 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackLineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackLineChart.js +553 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackAreaChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackAreaChart.js +519 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackLineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackLineChart.js +553 -0
- package/dist/components/Charts/ChartsWithAxis/BarFamily/BarChart.d.ts +12 -0
- package/dist/components/Charts/ChartsWithAxis/BarFamily/BarChart.js +9 -0
- package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisFunctions.d.ts +623 -0
- package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisFunctions.js +4897 -0
- package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.d.ts +0 -0
- package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.js +0 -0
- package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.types.d.ts +173 -0
- package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.types.js +49 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart copy.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart copy.js +486 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart.js +498 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnHistogramChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnHistogramChart.js +417 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/CustomColumnChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/CustomColumnChart.js +1014 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LayeredColumnChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LayeredColumnChart.js +479 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LineChart.js +451 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackColumnChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackColumnChart.js +535 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackLineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackLineChart.js +512 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackColumnChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackColumnChart.js +532 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackLineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackLineChart.js +512 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/BarChart.d.ts +12 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/BarChart.js +9 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalBarChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalBarChart.js +498 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalHistogramChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalHistogramChart.js +498 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredColumnChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredColumnChart.js +479 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredHorizontalBarChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredHorizontalBarChart.js +479 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/NormalizedStackHorizontalBarChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/NormalizedStackHorizontalBarChart.js +474 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/StackHorizontalBarChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/StackHorizontalBarChart.js +464 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/100%StackLineChart.d.ts +0 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/100%StackLineChart.js +0 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/LineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/LineChart.js +452 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalisedStackLineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalisedStackLineChart.js +554 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalizedStackLineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalizedStackLineChart.js +513 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/StackLineChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/LineFamily/StackLineChart.js +508 -0
- package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/TornadoChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/TornadoChart.js +395 -0
- package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/WaterfallChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/WaterfallChart.js +608 -0
- package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxis.types.d.ts +0 -0
- package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxis.types.js +0 -0
- package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.d.ts +92 -0
- package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.js +815 -0
- package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.d.ts +0 -0
- package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.js +0 -0
- package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.types.d.ts +108 -0
- package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.types.js +32 -0
- package/dist/components/Charts/ChartsWithoutAxis/Maps/Cordinates.d.ts +26 -0
- package/dist/components/Charts/ChartsWithoutAxis/Maps/Cordinates.js +15021 -0
- package/dist/components/Charts/ChartsWithoutAxis/Maps/Maps.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/Maps/Maps.js +391 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/BubbleChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/BubbleChart.js +367 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/OrganizationChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/OrganizationChart.js +569 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ProgressChart.d.ts +3 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ProgressChart.js +212 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/PyramidChart.d.ts +3 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/PyramidChart.js +401 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/RadialBarChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/RadialBarChart.js +313 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/SankeyChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/SankeyChart.js +719 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ScatterChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ScatterChart.js +807 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/Speedometer.d.ts +3 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/Speedometer.js +514 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/VennChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/VennChart.js +282 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/WordCloud.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/WordCloud.js +207 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/DonutChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/DonutChart.js +476 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieChart.d.ts +4 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieChart.js +420 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieFamilyCommonFunctions.d.ts +10 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieFamilyCommonFunctions.js +106 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieofPieChart.d.ts +3 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieofPieChart.js +507 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/TreemapChart.d.ts +3 -0
- package/dist/components/Charts/ChartsWithoutAxis/PieFamily/TreemapChart.js +246 -0
- package/dist/components/Charts/Core/Common.type.d.ts +0 -0
- package/dist/components/Charts/Core/Common.type.js +0 -0
- package/dist/components/Charts/Core/Common.types.d.ts +369 -0
- package/dist/components/Charts/Core/Common.types.js +133 -0
- package/dist/components/Charts/Core/CommonFunctions.d.ts +236 -0
- package/dist/components/Charts/Core/CommonFunctions.js +1778 -0
- package/dist/components/Charts/Core/DefaultChartDataProperties.d.ts +65 -0
- package/dist/components/Charts/Core/DefaultChartDataProperties.js +64 -0
- package/dist/components/Charts/Core/DefaultProperties.d.ts +0 -0
- package/dist/components/Charts/Core/DefaultProperties.js +0 -0
- package/dist/components/Charts/Core/DefaultProperties.type.d.ts +586 -0
- package/dist/components/Charts/Core/DefaultProperties.type.js +585 -0
- package/dist/components/Charts/Core/DefaultProperties.types.d.ts +592 -0
- package/dist/components/Charts/Core/DefaultProperties.types.js +592 -0
- package/dist/index.d.ts +34 -2
- package/dist/index.js +40 -2
- package/package.json +40 -29
- package/dist/components/charts/linechart/LineChart.d.ts +0 -12
- package/dist/components/charts/linechart/LineChart.js +0 -5
- /package/dist/{components/charts/barchart → Components1/Charts/ChartsWithAxis/BarFamily}/BarChart.d.ts +0 -0
- /package/dist/{components/charts/barchart → Components1/Charts/ChartsWithAxis/BarFamily}/BarChart.js +0 -0
|
@@ -0,0 +1,719 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
//#region imports
|
|
3
|
+
import * as d3 from "d3";
|
|
4
|
+
import * as d3sankey from "d3-sankey";
|
|
5
|
+
import { useEffect, useRef } from "react";
|
|
6
|
+
import { fontStyleOptions, } from "../../Core/Common.types";
|
|
7
|
+
import { convertStringToNumber, drawChartTitle, firstFunctionBeforeRender, getNumberWithFormatFunction, hideTooltipOnMouseOut, initChartArea, initSvg, marginCalculationsForChartsWithoutLegends, preCalculateTextDimensions, showTooltipOnMouseMove, } from "../../Core/CommonFunctions";
|
|
8
|
+
import { chartMargins } from "../../Core/DefaultProperties.types";
|
|
9
|
+
import { TSankeyDataLabelPostion, } from "../ChartsWithoutAxisTypes.types";
|
|
10
|
+
import { logError } from "../../../../Services/ErrorLog";
|
|
11
|
+
//#endregion
|
|
12
|
+
const SankeyChart = ({ sankeyLinks, sankeyNodes, formatOptions, chartId, }) => {
|
|
13
|
+
//#region Variables
|
|
14
|
+
let renderCount = 0; // Counter to track the number of renders
|
|
15
|
+
const svgRef = useRef(); // Reference to the SVG element
|
|
16
|
+
let nodeEntries = sankeyNodes; // Data for the word cloud, expected to be an array of objects with properties
|
|
17
|
+
let chartFormatOptions; // Format options for the chart
|
|
18
|
+
let width; // svg total width
|
|
19
|
+
let height; // svg total height
|
|
20
|
+
let min = Number.MAX_VALUE; // svg total height
|
|
21
|
+
let max = Number.MIN_VALUE; // svg total height
|
|
22
|
+
let chartTitleHeight = 40; // Height of the chart title
|
|
23
|
+
let margins = chartMargins; // Margins for the chart
|
|
24
|
+
let innerHeight; // Height of the chart excluding margins
|
|
25
|
+
let innerWidth; // Width of the chart excluding margins
|
|
26
|
+
let chartAreaTagG; // Group element for the chart area
|
|
27
|
+
let svg; // SVG element for the chart
|
|
28
|
+
let scale; // Scale for the font size based on data values
|
|
29
|
+
let totalMeasureValue = 0;
|
|
30
|
+
let dataLabelPosition = TSankeyDataLabelPostion.left; // Default data label position
|
|
31
|
+
let maxNodeLabelWidth = 0; // Maximum width of the label
|
|
32
|
+
let isLabelWrapped = false; // Flag to check if label is wrapped
|
|
33
|
+
let layerWiseTotal = new Map();
|
|
34
|
+
let layerWisePercentage = new Map();
|
|
35
|
+
let nodesFillOpacity = 0.8; // Default fill opacity for nodes
|
|
36
|
+
let linksFillOpacity = 0.8; // Default fill opacity for links
|
|
37
|
+
let wrappedLabelMaxWidth = 0; // Maximum width for wrapped labels
|
|
38
|
+
//#endregion
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
drawChart(); // Draw the chart when the component mounts
|
|
41
|
+
}, [formatOptions]);
|
|
42
|
+
const drawChart = () => {
|
|
43
|
+
({ chartFormatOptions, svg, width, height } = firstFunctionBeforeRender(svgRef, formatOptions));
|
|
44
|
+
({ margins, chartTitleHeight, innerHeight, innerWidth } =
|
|
45
|
+
marginCalculationsForChartsWithoutLegends(chartFormatOptions, height, width));
|
|
46
|
+
prepareDataForSankey();
|
|
47
|
+
initSvg(svgRef, width, height, chartFormatOptions); // Initialize SVG with width, height and background color
|
|
48
|
+
chartAreaTagG = initChartArea(svg, margins);
|
|
49
|
+
drawChartTitle(svgRef, chartTitleHeight, width, chartFormatOptions);
|
|
50
|
+
inittree();
|
|
51
|
+
};
|
|
52
|
+
const prepareDataForSankey = () => {
|
|
53
|
+
try {
|
|
54
|
+
nodesFillOpacity = convertStringToNumber(chartFormatOptions.nodes.nodesFillOpacity);
|
|
55
|
+
linksFillOpacity = convertStringToNumber(chartFormatOptions.links.linksFillOpacity);
|
|
56
|
+
sankeyNodes.forEach((d) => {
|
|
57
|
+
d["totalValue"] = 0;
|
|
58
|
+
});
|
|
59
|
+
sankeyNodes.forEach((d) => sankeyLinks.forEach((j) => (d.name == j.source || d.name == j.target) &&
|
|
60
|
+
(d["totalValue"] = (d["totalValue"] || 0) + j.value)));
|
|
61
|
+
(sankeyNodes = sankeyNodes.filter((d) => d["totalValue"] != 0)),
|
|
62
|
+
(sankeyLinks = sankeyLinks.filter((d) => d.value != 0));
|
|
63
|
+
let layersArray = assignNodeLayers(sankeyLinks);
|
|
64
|
+
let nodeLayerMap = new Map();
|
|
65
|
+
layersArray.forEach((layer) => {
|
|
66
|
+
layer.nodes.forEach((node) => {
|
|
67
|
+
nodeLayerMap.set(node, layer.layer);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
sankeyNodes.forEach((node) => {
|
|
71
|
+
let nodeLayerNumber = nodeLayerMap.get(node.name);
|
|
72
|
+
layerWiseTotal.set(nodeLayerNumber, (layerWiseTotal.get(nodeLayerNumber) || 0) + node.totalValue);
|
|
73
|
+
});
|
|
74
|
+
sankeyNodes.forEach((node) => {
|
|
75
|
+
layerWisePercentage.set(node.name, (node.totalValue / layerWiseTotal.get(nodeLayerMap.get(node.name))) *
|
|
76
|
+
100);
|
|
77
|
+
});
|
|
78
|
+
calculateMaxNodeValueWidth(layersArray);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
logError("SankeyChart.tsx", "prepareDataForSankey", error);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const calculateMaxNodeValueWidth = (layersArray) => {
|
|
85
|
+
try {
|
|
86
|
+
isLabelWrapped = chartFormatOptions.nodes.nodesLabelWrap;
|
|
87
|
+
dataLabelPosition = chartFormatOptions.nodes.nodesLabelVisibility
|
|
88
|
+
? chartFormatOptions.nodes.sankeyChartType
|
|
89
|
+
: "None";
|
|
90
|
+
let maxLabel = "";
|
|
91
|
+
let maxValue = 0;
|
|
92
|
+
sankeyNodes.forEach((node) => {
|
|
93
|
+
maxLabel = node.name.length > maxLabel.length ? node.name : maxLabel;
|
|
94
|
+
maxValue =
|
|
95
|
+
node.totalValue.toString().length > maxValue.toString().length
|
|
96
|
+
? node.totalValue
|
|
97
|
+
: maxValue;
|
|
98
|
+
});
|
|
99
|
+
let maxLabelWidth = preCalculateTextDimensions(maxLabel, convertStringToNumber(chartFormatOptions.nodes.nodesLabelFontSize), chartFormatOptions.nodes.nodesLabelFontFamily);
|
|
100
|
+
let maxValueWidth = preCalculateTextDimensions(getNumberWithFormatFunction(chartFormatOptions.nodes.nodesLabelDisplayUnits, chartFormatOptions.nodes.nodeLabelNumberFormat, chartFormatOptions.nodes.nodeLabelDecimalPrecision)(maxValue), convertStringToNumber(chartFormatOptions.nodes.nodesLabelFontSize), chartFormatOptions.nodes.nodesLabelFontFamily);
|
|
101
|
+
maxNodeLabelWidth =
|
|
102
|
+
Math.max(maxLabelWidth.width, maxValueWidth.width) + 6;
|
|
103
|
+
isLabelWrapped &&
|
|
104
|
+
(maxNodeLabelWidth = Math.min(innerWidth * 0.1, maxNodeLabelWidth));
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
logError("SankeyChart.tsx", "calculateMaxNodeValueWidth", error);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const getsankey = (nodes, links) => {
|
|
111
|
+
try {
|
|
112
|
+
let Spacing = chartFormatOptions.nodes.spacing !== undefined
|
|
113
|
+
? convertStringToNumber(chartFormatOptions.nodes.spacing) * 1.5
|
|
114
|
+
: 15;
|
|
115
|
+
let nodeWidth = chartFormatOptions.nodes.sankeyNodeWidth !== undefined
|
|
116
|
+
? chartFormatOptions.nodes.sankeyNodeWidth
|
|
117
|
+
: 10;
|
|
118
|
+
let xAndYCoordinate = [];
|
|
119
|
+
let widthAndHeight = [];
|
|
120
|
+
switch (dataLabelPosition) {
|
|
121
|
+
case TSankeyDataLabelPostion.center:
|
|
122
|
+
xAndYCoordinate = [1, 5];
|
|
123
|
+
widthAndHeight = [innerWidth, innerHeight];
|
|
124
|
+
break;
|
|
125
|
+
case TSankeyDataLabelPostion.right:
|
|
126
|
+
xAndYCoordinate = [1, 5];
|
|
127
|
+
widthAndHeight = [maxNodeLabelWidth, innerHeight];
|
|
128
|
+
break;
|
|
129
|
+
case TSankeyDataLabelPostion.left:
|
|
130
|
+
xAndYCoordinate = [maxNodeLabelWidth, 5];
|
|
131
|
+
widthAndHeight = [innerWidth, innerHeight];
|
|
132
|
+
break;
|
|
133
|
+
default:
|
|
134
|
+
xAndYCoordinate = [1, 5];
|
|
135
|
+
widthAndHeight = [innerWidth, innerHeight];
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
const sankey = d3sankey
|
|
139
|
+
.sankey()
|
|
140
|
+
.nodeId((d) => d.name)
|
|
141
|
+
.nodeAlign(d3sankey["sankeyJustify"])
|
|
142
|
+
.nodeWidth(nodeWidth)
|
|
143
|
+
.nodePadding(Spacing)
|
|
144
|
+
.extent([xAndYCoordinate, widthAndHeight])
|
|
145
|
+
.nodeSort(null);
|
|
146
|
+
return sankey({
|
|
147
|
+
nodes: nodes.map((d) => Object.assign({}, d)),
|
|
148
|
+
links: links.map((d) => Object.assign({}, d)),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
logError("SankeyChart.tsx", "getsankey", error);
|
|
153
|
+
return { nodes: [], links: [] };
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const inittree = () => {
|
|
157
|
+
try {
|
|
158
|
+
// const color = d3.scaleOrdinal(d3.schemeCategory10);
|
|
159
|
+
let curviness = chartFormatOptions.nodes.curviness !== undefined
|
|
160
|
+
? chartFormatOptions.nodes.curviness !== "0"
|
|
161
|
+
? chartFormatOptions.nodes.curviness
|
|
162
|
+
: 0.1
|
|
163
|
+
: 0.5;
|
|
164
|
+
const { nodes, links } = getsankey(sankeyNodes, sankeyLinks);
|
|
165
|
+
function centerAlignNodesByLayer() {
|
|
166
|
+
try {
|
|
167
|
+
const layers = {};
|
|
168
|
+
// Group nodes by layer
|
|
169
|
+
nodes.forEach((node) => {
|
|
170
|
+
const x = node.x0;
|
|
171
|
+
if (!layers[x])
|
|
172
|
+
layers[x] = [];
|
|
173
|
+
layers[x].push(node);
|
|
174
|
+
});
|
|
175
|
+
Object.keys(layers).forEach((layerX) => {
|
|
176
|
+
const layer = layers[layerX];
|
|
177
|
+
if (layer.length === 0)
|
|
178
|
+
return;
|
|
179
|
+
// Sort layer for predictable top-to-bottom order
|
|
180
|
+
layer.sort((a, b) => a.y0 - b.y0);
|
|
181
|
+
const topNode = layer[0];
|
|
182
|
+
const bottomNode = layer[layer.length - 1];
|
|
183
|
+
const topHeight = topNode.y1 - topNode.y0;
|
|
184
|
+
const bottomHeight = bottomNode.y1 - bottomNode.y0;
|
|
185
|
+
// Top-align the top node
|
|
186
|
+
topNode.y0 = 0;
|
|
187
|
+
topNode.y1 = topHeight;
|
|
188
|
+
// Bottom-align the bottom node
|
|
189
|
+
bottomNode.y1 = innerHeight;
|
|
190
|
+
bottomNode.y0 = innerHeight - bottomHeight;
|
|
191
|
+
// Adjust middle nodes
|
|
192
|
+
if (layer.length > 2) {
|
|
193
|
+
const middleNodes = layer.slice(1, layer.length - 1);
|
|
194
|
+
const availableHeight = bottomNode.y0 - topNode.y1;
|
|
195
|
+
const totalMiddleHeight = d3.sum(middleNodes, (d) => d.y1 - d.y0);
|
|
196
|
+
const middleGap = (availableHeight - totalMiddleHeight) /
|
|
197
|
+
(middleNodes.length + 1);
|
|
198
|
+
let currentY = topNode.y1 + middleGap;
|
|
199
|
+
middleNodes.forEach((node) => {
|
|
200
|
+
const nodeHeight = node.y1 - node.y0;
|
|
201
|
+
node.y0 = currentY;
|
|
202
|
+
node.y1 = currentY + nodeHeight;
|
|
203
|
+
currentY += nodeHeight + middleGap;
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
logError("SankeyChart.tsx", "centerAlignNodesByLayer", error);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
arrangeFlows();
|
|
213
|
+
centerAlignNodesByLayer();
|
|
214
|
+
arrangeFlows(); // Recompute flow offsets after repositioning
|
|
215
|
+
// Function to properly stack links within each node
|
|
216
|
+
function arrangeFlows() {
|
|
217
|
+
try {
|
|
218
|
+
nodes.forEach((node) => {
|
|
219
|
+
let sy = 0, ty = 0; // Track flow offsets
|
|
220
|
+
// Assign positions to source links
|
|
221
|
+
node.sourceLinks.forEach((link) => {
|
|
222
|
+
link.sy = sy;
|
|
223
|
+
sy += link.width; // Move next link below
|
|
224
|
+
});
|
|
225
|
+
// Assign positions to target links
|
|
226
|
+
node.targetLinks.forEach((link) => {
|
|
227
|
+
link.ty = ty;
|
|
228
|
+
ty += link.width; // Move next link below
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
logError("SankeyChart.tsx", "arrangeFlows", error);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
// Function to dynamically generate a curved link path based on curviness
|
|
237
|
+
function sankeyLinkCustom(curviness) {
|
|
238
|
+
return function (d) {
|
|
239
|
+
try {
|
|
240
|
+
const x0 = d.source.x1, y0 = d.source.y0 + d.sy + d.width / 2;
|
|
241
|
+
const x1 = d.target.x0, y1 = d.target.y0 + d.ty + d.width / 2;
|
|
242
|
+
const dx = x1 - x0;
|
|
243
|
+
const cx1 = x0 + dx * curviness;
|
|
244
|
+
const cx2 = x1 - dx * curviness;
|
|
245
|
+
return `M${x0},${y0} C${cx1},${y0} ${cx2},${y1} ${x1},${y1}`;
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
logError("SankeyChart.tsx", "sankeyLinkCustom", error);
|
|
249
|
+
return "";
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
// Call function to arrange links properly before rendering
|
|
254
|
+
arrangeFlows();
|
|
255
|
+
const Nodes = chartAreaTagG
|
|
256
|
+
.append("g")
|
|
257
|
+
.selectAll("rect")
|
|
258
|
+
.data(nodes)
|
|
259
|
+
.enter()
|
|
260
|
+
.append("rect")
|
|
261
|
+
.style("fill-opacity", nodesFillOpacity)
|
|
262
|
+
.attr("id", (d) => "Node" + d.index)
|
|
263
|
+
.attr("class", "sankey-nodes")
|
|
264
|
+
.attr("stroke", chartFormatOptions.nodes.nodesBorderColor !== "#ffffff"
|
|
265
|
+
? chartFormatOptions.nodes.nodesBorderColor
|
|
266
|
+
: "none")
|
|
267
|
+
.attr("stroke-width", chartFormatOptions.nodes.nodesBorderVisibility
|
|
268
|
+
? chartFormatOptions.nodes.nodesBorderThickness
|
|
269
|
+
: 0)
|
|
270
|
+
.attr("x", (d) => d.x0)
|
|
271
|
+
.attr("y", (d) => d.y0)
|
|
272
|
+
.attr("height", (d) => d.y1 - d.y0)
|
|
273
|
+
.attr("width", (d) => d.x1 - d.x0)
|
|
274
|
+
.attr("fill", (d) => (d.color ? d.color : "#ffffff"))
|
|
275
|
+
.on("mousemove", function (event, d) {
|
|
276
|
+
try {
|
|
277
|
+
if (chartFormatOptions.toolTip.toolTipVisibility) {
|
|
278
|
+
showTooltipOnMouseMove([
|
|
279
|
+
{
|
|
280
|
+
key: d.name,
|
|
281
|
+
value: chartFormatOptions.toolTip.toolTipNumberFormat == ",.0%"
|
|
282
|
+
? layerWisePercentage.get(d.name) + "%"
|
|
283
|
+
: getNumberWithFormatFunction("None", chartFormatOptions.toolTip.toolTipNumberFormat, chartFormatOptions.toolTip.toolTipDecimalPrecision)(d.value),
|
|
284
|
+
},
|
|
285
|
+
], chartFormatOptions);
|
|
286
|
+
}
|
|
287
|
+
// All Elements
|
|
288
|
+
chartAreaTagG
|
|
289
|
+
.selectAll(".sankey-nodes")
|
|
290
|
+
.style("fill-opacity", 0.1)
|
|
291
|
+
.style("stroke", "none");
|
|
292
|
+
chartAreaTagG
|
|
293
|
+
.selectAll(".sankey-nodes-texts")
|
|
294
|
+
.style("opacity", "0");
|
|
295
|
+
chartAreaTagG
|
|
296
|
+
.selectAll(".sankey-links")
|
|
297
|
+
.style("stroke-opacity", 0.1);
|
|
298
|
+
// This Particular Node
|
|
299
|
+
chartAreaTagG
|
|
300
|
+
.select(`#Node${d.index}`)
|
|
301
|
+
.style("stroke", chartFormatOptions.nodes.nodesBorderColor !== "#ffffff"
|
|
302
|
+
? chartFormatOptions.nodes.nodesBorderColor
|
|
303
|
+
: "none")
|
|
304
|
+
.style("fill-opacity", nodesFillOpacity)
|
|
305
|
+
.style("cursor", "pointer");
|
|
306
|
+
chartAreaTagG.select(`#Label${d.index}`).style("opacity", 1);
|
|
307
|
+
// All Source Links
|
|
308
|
+
d.sourceLinks.forEach((j) => {
|
|
309
|
+
//Node
|
|
310
|
+
chartAreaTagG
|
|
311
|
+
.select(`#Node${j.target.index}`)
|
|
312
|
+
.style("fill-opacity", nodesFillOpacity)
|
|
313
|
+
.style("stroke", chartFormatOptions.nodes.nodesBorderColor !== "#ffffff"
|
|
314
|
+
? chartFormatOptions.nodes.nodesBorderColor
|
|
315
|
+
: "none");
|
|
316
|
+
//Link
|
|
317
|
+
chartAreaTagG
|
|
318
|
+
.select(`#Link${j.index}`)
|
|
319
|
+
.style("stroke-opacity", linksFillOpacity);
|
|
320
|
+
//Labels
|
|
321
|
+
chartAreaTagG
|
|
322
|
+
.select(`#Label${j.target.index}`)
|
|
323
|
+
.style("opacity", 1);
|
|
324
|
+
});
|
|
325
|
+
// All Target Links
|
|
326
|
+
d.targetLinks.forEach((j) => {
|
|
327
|
+
//Node
|
|
328
|
+
chartAreaTagG
|
|
329
|
+
.select(`#Node${j.source.index}`)
|
|
330
|
+
.style("fill-opacity", nodesFillOpacity)
|
|
331
|
+
.style("stroke", chartFormatOptions.nodes.nodesBorderColor !== "#ffffff"
|
|
332
|
+
? chartFormatOptions.nodes.nodesBorderColor
|
|
333
|
+
: "none");
|
|
334
|
+
//Link
|
|
335
|
+
chartAreaTagG
|
|
336
|
+
.select(`#Link${j.index}`)
|
|
337
|
+
.style("stroke-opacity", linksFillOpacity);
|
|
338
|
+
//Label
|
|
339
|
+
chartAreaTagG
|
|
340
|
+
.select(`#Label${j.source.index}`)
|
|
341
|
+
.style("opacity", 1);
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
logError("SankeyChart.tsx", "Nodes.onMouseMove", error);
|
|
346
|
+
}
|
|
347
|
+
})
|
|
348
|
+
.on("mouseout", function (d) {
|
|
349
|
+
try {
|
|
350
|
+
//Node
|
|
351
|
+
chartAreaTagG
|
|
352
|
+
.selectAll(".sankey-nodes")
|
|
353
|
+
.style("fill-opacity", nodesFillOpacity)
|
|
354
|
+
.style("stroke", chartFormatOptions.nodes.nodesBorderColor !== "#ffffff"
|
|
355
|
+
? chartFormatOptions.nodes.nodesBorderColor
|
|
356
|
+
: "none");
|
|
357
|
+
//Link
|
|
358
|
+
chartAreaTagG
|
|
359
|
+
.selectAll(".sankey-links")
|
|
360
|
+
.style("stroke-opacity", linksFillOpacity);
|
|
361
|
+
//Label
|
|
362
|
+
chartAreaTagG
|
|
363
|
+
.selectAll(".sankey-nodes-texts")
|
|
364
|
+
.style("opacity", "1");
|
|
365
|
+
// chartAreaTagG.select(this).style("cursor", "none");
|
|
366
|
+
if (chartFormatOptions.toolTip.toolTipVisibility) {
|
|
367
|
+
hideTooltipOnMouseOut();
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
catch (error) {
|
|
371
|
+
logError("SankeyChart.tsx", "Nodes.onMouseOut", error);
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
//LINKS
|
|
375
|
+
const link = chartAreaTagG
|
|
376
|
+
.append("g")
|
|
377
|
+
.attr("fill", "none")
|
|
378
|
+
.selectAll("g")
|
|
379
|
+
.data(links)
|
|
380
|
+
.enter()
|
|
381
|
+
.append("g")
|
|
382
|
+
.style("mix-blend-mode", "multiply");
|
|
383
|
+
link
|
|
384
|
+
.append("path")
|
|
385
|
+
.attr("class", "sankey-links")
|
|
386
|
+
.attr("stroke-opacity", linksFillOpacity)
|
|
387
|
+
.attr("id", (d) => "Link" + d.index)
|
|
388
|
+
.attr("d", sankeyLinkCustom(curviness))
|
|
389
|
+
.attr("stroke", (d) => chartFormatOptions.links.linksColor === "Source"
|
|
390
|
+
? d.source.color
|
|
391
|
+
: d.target.color)
|
|
392
|
+
.attr("stroke-width", (d) => Math.max(1, d.width))
|
|
393
|
+
.on("mousemove", function (event, d) {
|
|
394
|
+
try {
|
|
395
|
+
// All Elements
|
|
396
|
+
chartAreaTagG
|
|
397
|
+
.selectAll(".sankey-links")
|
|
398
|
+
.style("stroke-opacity", 0.1);
|
|
399
|
+
chartAreaTagG
|
|
400
|
+
.selectAll(".sankey-nodes")
|
|
401
|
+
.style("stroke", "none")
|
|
402
|
+
.style("fill-opacity", 0.1);
|
|
403
|
+
chartAreaTagG
|
|
404
|
+
.selectAll(".sankey-nodes-texts")
|
|
405
|
+
.style("opacity", "0");
|
|
406
|
+
// This Particular Element
|
|
407
|
+
chartAreaTagG
|
|
408
|
+
.select(`#Link${d.index}`)
|
|
409
|
+
.style("stroke-opacity", linksFillOpacity)
|
|
410
|
+
.style("cursor", "pointer");
|
|
411
|
+
// This Link's Nodes and Nodes Border
|
|
412
|
+
chartAreaTagG
|
|
413
|
+
.select(`#Node${d.target.index}`)
|
|
414
|
+
.style("fill-opacity", nodesFillOpacity)
|
|
415
|
+
.style("Stroke", chartFormatOptions.nodes.nodesBorderColor !== "#ffffff"
|
|
416
|
+
? chartFormatOptions.nodes.nodesBorderColor
|
|
417
|
+
: "none");
|
|
418
|
+
chartAreaTagG
|
|
419
|
+
.select(`#Node${d.source.index}`)
|
|
420
|
+
.style("fill-opacity", nodesFillOpacity)
|
|
421
|
+
.style("Stroke", chartFormatOptions.nodes.nodesBorderColor !== "#ffffff"
|
|
422
|
+
? chartFormatOptions.nodes.nodesBorderColor
|
|
423
|
+
: "none");
|
|
424
|
+
// This Link's Node's Labdels
|
|
425
|
+
chartAreaTagG.select(`#Label${d.target.index}`).style("opacity", 1);
|
|
426
|
+
chartAreaTagG.select(`#Label${d.source.index}`).style("opacity", 1);
|
|
427
|
+
if (chartFormatOptions.toolTip.toolTipVisibility) {
|
|
428
|
+
showTooltipOnMouseMove([
|
|
429
|
+
{
|
|
430
|
+
key: d.source.name + "→" + d.target.name,
|
|
431
|
+
value: getNumberWithFormatFunction("None", chartFormatOptions.toolTip.toolTipNumberFormat, chartFormatOptions.toolTip.toolTipDecimalPrecision)(d.value),
|
|
432
|
+
},
|
|
433
|
+
], chartFormatOptions);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
catch (error) {
|
|
437
|
+
logError("SankeyChart.tsx", "link.onMouseMove", error);
|
|
438
|
+
}
|
|
439
|
+
})
|
|
440
|
+
.on("mouseout", function (d) {
|
|
441
|
+
try {
|
|
442
|
+
if (chartFormatOptions.toolTip.toolTipVisibility) {
|
|
443
|
+
hideTooltipOnMouseOut();
|
|
444
|
+
}
|
|
445
|
+
// All Elements
|
|
446
|
+
chartAreaTagG
|
|
447
|
+
.selectAll(".sankey-nodes")
|
|
448
|
+
.style("fill-opacity", nodesFillOpacity);
|
|
449
|
+
chartAreaTagG
|
|
450
|
+
.selectAll(".sankey-nodes")
|
|
451
|
+
.style("stroke", chartFormatOptions.nodes.nodesBorderColor !== "#ffffff"
|
|
452
|
+
? chartFormatOptions.nodes.nodesBorderColor
|
|
453
|
+
: "none");
|
|
454
|
+
chartAreaTagG
|
|
455
|
+
.selectAll(".sankey-links")
|
|
456
|
+
.style("stroke-opacity", linksFillOpacity);
|
|
457
|
+
chartAreaTagG
|
|
458
|
+
.selectAll(".sankey-nodes-texts")
|
|
459
|
+
.style("opacity", "1");
|
|
460
|
+
// Ensure the node captures hover events
|
|
461
|
+
d3.select(this).select("rect").style("pointer-events", "all");
|
|
462
|
+
// This Particular Element
|
|
463
|
+
d3.select(this).style("cursor", "none");
|
|
464
|
+
}
|
|
465
|
+
catch (error) {
|
|
466
|
+
logError("SankeyChart.tsx", "link.onMouseOut", error);
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
// LABELS
|
|
470
|
+
if (chartFormatOptions.nodes.nodesLabelVisibility) {
|
|
471
|
+
try {
|
|
472
|
+
const texts = chartAreaTagG
|
|
473
|
+
.append("g")
|
|
474
|
+
.attr("font-family", chartFormatOptions.nodes.nodesLabelFontFamily)
|
|
475
|
+
.attr("font-size", chartFormatOptions.nodes.nodesLabelFontSize)
|
|
476
|
+
.style("font-style", chartFormatOptions.nodes.nodesLabelFontStyle.includes(fontStyleOptions.italic)
|
|
477
|
+
? fontStyleOptions.italic
|
|
478
|
+
: "")
|
|
479
|
+
.style("text-decoration", chartFormatOptions.nodes.nodesLabelFontStyle.includes(fontStyleOptions.underline)
|
|
480
|
+
? fontStyleOptions.underline
|
|
481
|
+
: "")
|
|
482
|
+
.style("font-weight", chartFormatOptions.nodes.nodesLabelFontStyle.includes(fontStyleOptions.bold)
|
|
483
|
+
? fontStyleOptions.bold
|
|
484
|
+
: "")
|
|
485
|
+
.attr("display", chartFormatOptions.nodes.nodesLabelVisibility ? "visible" : "none")
|
|
486
|
+
.selectAll("text")
|
|
487
|
+
.data(nodes)
|
|
488
|
+
.enter()
|
|
489
|
+
.append("g")
|
|
490
|
+
.attr("class", "sankey-nodes-texts")
|
|
491
|
+
.attr("id", (d) => "Label" + d.index)
|
|
492
|
+
.each(function (d) {
|
|
493
|
+
try {
|
|
494
|
+
if (chartFormatOptions.nodes.sankeyChartType !== "None") {
|
|
495
|
+
const nodeWidth = chartFormatOptions.nodes.sankeyNodeWidth;
|
|
496
|
+
const isInside = dataLabelPosition === TSankeyDataLabelPostion.center;
|
|
497
|
+
// Append foreignObject for data label
|
|
498
|
+
const div = d3
|
|
499
|
+
.select(this)
|
|
500
|
+
.append("foreignObject")
|
|
501
|
+
.attr("x", getXandYPositionOfLables(d)["x"])
|
|
502
|
+
.attr("y", getXandYPositionOfLables(d)["y"] - 16)
|
|
503
|
+
.attr("width", (d) => isInside ? nodeWidth : maxNodeLabelWidth) // Node width if inside, otherwise fixed width
|
|
504
|
+
.attr("height", 20);
|
|
505
|
+
div
|
|
506
|
+
.append("xhtml:div")
|
|
507
|
+
.style("white-space", isInside ? "nowrap" : isLabelWrapped ? "nowrap" : "normal") // Wrap text only when Outside
|
|
508
|
+
.style("overflow", isInside
|
|
509
|
+
? "hidden"
|
|
510
|
+
: isLabelWrapped
|
|
511
|
+
? "hidden"
|
|
512
|
+
: "visible") // Full text visibility Outside
|
|
513
|
+
.style("text-overflow", isInside
|
|
514
|
+
? "ellipsis"
|
|
515
|
+
: isLabelWrapped
|
|
516
|
+
? "ellipsis"
|
|
517
|
+
: "clip")
|
|
518
|
+
.style("display", "block")
|
|
519
|
+
.style("max-width", (d) => isInside ? "100px" : maxNodeLabelWidth + "px") // Auto width for Outside mode
|
|
520
|
+
.style("padding", "0 3px")
|
|
521
|
+
.style("color", chartFormatOptions.nodes.nodesLabelColor)
|
|
522
|
+
.style("font-family", chartFormatOptions.nodes.nodesLabelFontFamily)
|
|
523
|
+
.style("font-size", chartFormatOptions.nodes.nodesLabelFontSize + "px")
|
|
524
|
+
.style("font-style", chartFormatOptions.nodes.nodesLabelFontStyle.includes(fontStyleOptions.italic)
|
|
525
|
+
? fontStyleOptions.italic
|
|
526
|
+
: "")
|
|
527
|
+
.style("text-decoration", chartFormatOptions.nodes.nodesLabelFontStyle.includes(fontStyleOptions.underline)
|
|
528
|
+
? fontStyleOptions.underline
|
|
529
|
+
: "")
|
|
530
|
+
.style("font-weight", chartFormatOptions.nodes.nodesLabelFontStyle.includes(fontStyleOptions.bold)
|
|
531
|
+
? fontStyleOptions.bold
|
|
532
|
+
: "")
|
|
533
|
+
.style("text-align", chartFormatOptions.nodes.sankeyChartType === "Left"
|
|
534
|
+
? "right"
|
|
535
|
+
: chartFormatOptions.nodes.sankeyChartType === "Center"
|
|
536
|
+
? "center"
|
|
537
|
+
: "left")
|
|
538
|
+
.style("line-height", "20px")
|
|
539
|
+
.attr("title", (d) => {
|
|
540
|
+
if (layerWisePercentage.get(d.name) > 5) {
|
|
541
|
+
return d.alias ? d.alias : d.name;
|
|
542
|
+
}
|
|
543
|
+
return "";
|
|
544
|
+
})
|
|
545
|
+
.text((d) => {
|
|
546
|
+
if (layerWisePercentage.get(d.name) > 5) {
|
|
547
|
+
return d.alias ? d.alias : d.name;
|
|
548
|
+
}
|
|
549
|
+
return "";
|
|
550
|
+
});
|
|
551
|
+
// Append foreignObject for data value
|
|
552
|
+
const divValue = d3
|
|
553
|
+
.select(this)
|
|
554
|
+
.append("foreignObject")
|
|
555
|
+
.attr("x", getXandYPositionOfLables(d)["x"]) // Align X position properly
|
|
556
|
+
.attr("y", getXandYPositionOfLables(d)["y"]) // Keep value vertically aligned
|
|
557
|
+
.attr("width", (d) => isInside ? nodeWidth : maxNodeLabelWidth)
|
|
558
|
+
.attr("height", 20);
|
|
559
|
+
divValue
|
|
560
|
+
.append("xhtml:div")
|
|
561
|
+
.style("white-space", isInside ? "nowrap" : isLabelWrapped ? "nowrap" : "normal") // Wrap text only when Outside
|
|
562
|
+
.style("overflow", isInside
|
|
563
|
+
? "hidden"
|
|
564
|
+
: isLabelWrapped
|
|
565
|
+
? "hidden"
|
|
566
|
+
: "visible") // Full text visibility Outside
|
|
567
|
+
.style("text-overflow", isInside
|
|
568
|
+
? "ellipsis"
|
|
569
|
+
: isLabelWrapped
|
|
570
|
+
? "ellipsis"
|
|
571
|
+
: "clip")
|
|
572
|
+
.style("display", "block")
|
|
573
|
+
.style("max-width", (d) => isInside ? "100px" : maxNodeLabelWidth + "px") // Auto width for Outside mode
|
|
574
|
+
.style("padding", "0 3px") // Auto width for Outside mode
|
|
575
|
+
.style("color", chartFormatOptions.nodes.nodesLabelColor)
|
|
576
|
+
.style("font-family", chartFormatOptions.nodes.nodesLabelFontFamily)
|
|
577
|
+
.style("font-size", chartFormatOptions.nodes.nodesLabelFontSize + "px")
|
|
578
|
+
.style("font-style", chartFormatOptions.nodes.nodesLabelFontStyle.includes(fontStyleOptions.italic)
|
|
579
|
+
? fontStyleOptions.italic
|
|
580
|
+
: "")
|
|
581
|
+
.style("text-decoration", chartFormatOptions.nodes.nodesLabelFontStyle.includes(fontStyleOptions.underline)
|
|
582
|
+
? fontStyleOptions.underline
|
|
583
|
+
: "")
|
|
584
|
+
.style("font-weight", chartFormatOptions.nodes.nodesLabelFontStyle.includes(fontStyleOptions.bold)
|
|
585
|
+
? fontStyleOptions.bold
|
|
586
|
+
: "")
|
|
587
|
+
.style("text-align", chartFormatOptions.nodes.sankeyChartType === "Left"
|
|
588
|
+
? "right"
|
|
589
|
+
: chartFormatOptions.nodes.sankeyChartType === "Center"
|
|
590
|
+
? "center"
|
|
591
|
+
: "left") // Align value same as label
|
|
592
|
+
.style("line-height", "20px")
|
|
593
|
+
.attr("title", (d) => {
|
|
594
|
+
if (layerWisePercentage.get(d.name) > 5) {
|
|
595
|
+
return chartFormatOptions.nodes
|
|
596
|
+
.nodeLabelNumberFormat === ",.0%"
|
|
597
|
+
? layerWisePercentage
|
|
598
|
+
.get(d.name)
|
|
599
|
+
.toFixed(parseFloat(chartFormatOptions.nodes
|
|
600
|
+
.nodeLabelDecimalPrecision)) + "%"
|
|
601
|
+
: getNumberWithFormatFunction(chartFormatOptions.nodes.nodesLabelDisplayUnits, chartFormatOptions.nodes.nodeLabelNumberFormat, chartFormatOptions.nodes.nodeLabelDecimalPrecision)(d.totalValue);
|
|
602
|
+
}
|
|
603
|
+
return "";
|
|
604
|
+
})
|
|
605
|
+
.text((d) => {
|
|
606
|
+
if (layerWisePercentage.get(d.name) > 5) {
|
|
607
|
+
return chartFormatOptions.nodes
|
|
608
|
+
.nodeLabelNumberFormat === ",.0%"
|
|
609
|
+
? layerWisePercentage
|
|
610
|
+
.get(d.name)
|
|
611
|
+
.toFixed(parseFloat(chartFormatOptions.nodes
|
|
612
|
+
.nodeLabelDecimalPrecision)) + "%"
|
|
613
|
+
: getNumberWithFormatFunction(chartFormatOptions.nodes.nodesLabelDisplayUnits, chartFormatOptions.nodes.nodeLabelNumberFormat, chartFormatOptions.nodes.nodeLabelDecimalPrecision)(d.totalValue);
|
|
614
|
+
}
|
|
615
|
+
return "";
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
catch (error) {
|
|
620
|
+
logError("SankeyChart.tsx", "texts.each", error);
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
catch (error) {
|
|
625
|
+
logError("SankeyChart.tsx", "inittree.texts", error);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
catch (error) {
|
|
630
|
+
logError("SankeyChart.tsx", "inittree", error);
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
function assignNodeLayers(links) {
|
|
634
|
+
try {
|
|
635
|
+
const incoming = new Map(); // node -> Set of incoming sources
|
|
636
|
+
const outgoing = new Map(); // node -> Set of outgoing targets
|
|
637
|
+
const allNodes = new Set();
|
|
638
|
+
// Build graph
|
|
639
|
+
for (const { source, target } of links) {
|
|
640
|
+
allNodes.add(source);
|
|
641
|
+
allNodes.add(target);
|
|
642
|
+
if (!incoming.has(target))
|
|
643
|
+
incoming.set(target, new Set());
|
|
644
|
+
if (!outgoing.has(source))
|
|
645
|
+
outgoing.set(source, new Set());
|
|
646
|
+
incoming.get(target).add(source);
|
|
647
|
+
outgoing.get(source).add(target);
|
|
648
|
+
}
|
|
649
|
+
// Nodes with no incoming links => layer 0
|
|
650
|
+
const layerMap = new Map();
|
|
651
|
+
const queue = [];
|
|
652
|
+
for (const node of allNodes) {
|
|
653
|
+
if (!incoming.has(node)) {
|
|
654
|
+
layerMap.set(node, 0);
|
|
655
|
+
queue.push(node);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
// BFS to assign layer numbers
|
|
659
|
+
while (queue.length > 0) {
|
|
660
|
+
const node = queue.shift();
|
|
661
|
+
const currentLayer = layerMap.get(node);
|
|
662
|
+
const targets = outgoing.get(node) || [];
|
|
663
|
+
for (const target of targets) {
|
|
664
|
+
const nextLayer = currentLayer + 1;
|
|
665
|
+
// Assign only if:
|
|
666
|
+
// - not assigned yet
|
|
667
|
+
// - or a higher layer number is found (take max)
|
|
668
|
+
if (!layerMap.has(target) || layerMap.get(target) < nextLayer) {
|
|
669
|
+
layerMap.set(target, nextLayer);
|
|
670
|
+
queue.push(target);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
// Group nodes by layer
|
|
675
|
+
const layers = new Map(); // layer -> [nodes]
|
|
676
|
+
for (const [node, layer] of layerMap.entries()) {
|
|
677
|
+
if (!layers.has(layer))
|
|
678
|
+
layers.set(layer, []);
|
|
679
|
+
layers.get(layer).push(node);
|
|
680
|
+
}
|
|
681
|
+
// Convert to sorted array of layers
|
|
682
|
+
const sortedLayers = [...layers.entries()]
|
|
683
|
+
.sort((a, b) => a[0] - b[0])
|
|
684
|
+
.map(([layer, nodes]) => ({ layer, nodes }));
|
|
685
|
+
return sortedLayers;
|
|
686
|
+
}
|
|
687
|
+
catch (error) {
|
|
688
|
+
logError("SankeyChart.tsx", "assignNodeLayers", error);
|
|
689
|
+
return [];
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
const getXandYPositionOfLables = (d) => {
|
|
693
|
+
try {
|
|
694
|
+
let returnObj = {};
|
|
695
|
+
const nodeWidth = Number(chartFormatOptions.nodes.sankeyNodeWidth);
|
|
696
|
+
const centerOffset = nodeWidth / 2;
|
|
697
|
+
switch (dataLabelPosition) {
|
|
698
|
+
case "Right":
|
|
699
|
+
returnObj["x"] = d.x1 + 6;
|
|
700
|
+
break;
|
|
701
|
+
default:
|
|
702
|
+
case "Left":
|
|
703
|
+
returnObj["x"] = d.x0 - maxNodeLabelWidth;
|
|
704
|
+
break;
|
|
705
|
+
case "Center":
|
|
706
|
+
returnObj["x"] = d.x0 + centerOffset - nodeWidth / 2;
|
|
707
|
+
break;
|
|
708
|
+
}
|
|
709
|
+
returnObj["y"] = (d.y1 + d.y0) / 2;
|
|
710
|
+
return returnObj;
|
|
711
|
+
}
|
|
712
|
+
catch (error) {
|
|
713
|
+
logError("SankeyChart.tsx", "getXandYPositionOfLables", error);
|
|
714
|
+
return { x: 0, y: 0 };
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
return (_jsxs("div", { style: { width: "100%", height: "100%" }, children: [_jsx("div", { id: "chartTooltipDiv" }), _jsx("svg", { className: "chartSVG", ref: svgRef, id: chartId, style: { width: "100%", height: "100%" } })] }));
|
|
718
|
+
};
|
|
719
|
+
export default SankeyChart;
|