pace-chart-lib 1.0.2 → 1.0.3

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.
Files changed (131) hide show
  1. package/dist/{components → Components}/Charts/ChartsWithAxis/ChartsWithAxisFunctions.d.ts +76 -38
  2. package/dist/{components → Components}/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.types.d.ts +4 -2
  3. package/dist/{components → Components}/Charts/Core/CommonFunctions.d.ts +3 -1
  4. package/dist/{components → Components}/Charts/Core/DefaultProperties.types.d.ts +2 -0
  5. package/dist/index.d.ts +1 -0
  6. package/dist/pace-chart-lib.es.js +54619 -0
  7. package/dist/pace-chart-lib.umd.js +54622 -0
  8. package/dist/vite.svg +1 -0
  9. package/package.json +1 -1
  10. package/dist/Services/ErrorLog.js +0 -3
  11. package/dist/components/Charts/ChartsWithAxis/AreaFamily/AreaChart.js +0 -496
  12. package/dist/components/Charts/ChartsWithAxis/AreaFamily/LineChart.d.ts +0 -4
  13. package/dist/components/Charts/ChartsWithAxis/AreaFamily/LineChart.js +0 -491
  14. package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackAreaChart.js +0 -517
  15. package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackLineChart.d.ts +0 -4
  16. package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackLineChart.js +0 -553
  17. package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackAreaChart.js +0 -517
  18. package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackLineChart.d.ts +0 -4
  19. package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackLineChart.js +0 -553
  20. package/dist/components/Charts/ChartsWithAxis/BarFamily/BarChart.d.ts +0 -12
  21. package/dist/components/Charts/ChartsWithAxis/BarFamily/BarChart.js +0 -9
  22. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisFunctions.js +0 -4909
  23. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.d.ts +0 -0
  24. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.js +0 -0
  25. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.types.js +0 -49
  26. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart copy.d.ts +0 -4
  27. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart copy.js +0 -486
  28. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart.js +0 -497
  29. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnHistogramChart.js +0 -418
  30. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/CustomColumnChart.js +0 -1013
  31. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LayeredColumnChart.js +0 -478
  32. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LineChart.d.ts +0 -4
  33. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LineChart.js +0 -451
  34. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackColumnChart.js +0 -533
  35. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackLineChart.js +0 -512
  36. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackColumnChart.js +0 -530
  37. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackLineChart.js +0 -512
  38. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/BarChart.d.ts +0 -12
  39. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/BarChart.js +0 -9
  40. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalBarChart.js +0 -497
  41. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalHistogramChart.js +0 -497
  42. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredColumnChart.d.ts +0 -4
  43. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredColumnChart.js +0 -479
  44. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredHorizontalBarChart.js +0 -478
  45. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/NormalizedStackHorizontalBarChart.js +0 -473
  46. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/StackHorizontalBarChart.js +0 -465
  47. package/dist/components/Charts/ChartsWithAxis/LineFamily/100%StackLineChart.d.ts +0 -0
  48. package/dist/components/Charts/ChartsWithAxis/LineFamily/100%StackLineChart.js +0 -0
  49. package/dist/components/Charts/ChartsWithAxis/LineFamily/LineChart.js +0 -451
  50. package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalisedStackLineChart.d.ts +0 -4
  51. package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalisedStackLineChart.js +0 -554
  52. package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalizedStackLineChart.d.ts +0 -4
  53. package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalizedStackLineChart.js +0 -510
  54. package/dist/components/Charts/ChartsWithAxis/LineFamily/StackLineChart.d.ts +0 -4
  55. package/dist/components/Charts/ChartsWithAxis/LineFamily/StackLineChart.js +0 -507
  56. package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/TornadoChart.js +0 -393
  57. package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/WaterfallChart.js +0 -606
  58. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxis.types.d.ts +0 -0
  59. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxis.types.js +0 -0
  60. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.js +0 -815
  61. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.d.ts +0 -0
  62. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.js +0 -0
  63. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.types.js +0 -32
  64. package/dist/components/Charts/ChartsWithoutAxis/Maps/Cordinates.js +0 -15021
  65. package/dist/components/Charts/ChartsWithoutAxis/Maps/Maps.js +0 -391
  66. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/BubbleChart.js +0 -367
  67. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/OrganizationChart.js +0 -570
  68. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ProgressChart.js +0 -212
  69. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/PyramidChart.js +0 -401
  70. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/RadialBarChart.js +0 -313
  71. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/SankeyChart.js +0 -719
  72. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ScatterChart.js +0 -807
  73. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/Speedometer.js +0 -514
  74. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/VennChart.js +0 -282
  75. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/WordCloud.js +0 -207
  76. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/DonutChart.js +0 -476
  77. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieChart.js +0 -420
  78. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieFamilyCommonFunctions.js +0 -106
  79. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieofPieChart.js +0 -507
  80. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/TreemapChart.js +0 -246
  81. package/dist/components/Charts/Core/Common.type.d.ts +0 -0
  82. package/dist/components/Charts/Core/Common.type.js +0 -0
  83. package/dist/components/Charts/Core/Common.types.js +0 -133
  84. package/dist/components/Charts/Core/CommonFunctions.js +0 -1782
  85. package/dist/components/Charts/Core/DefaultChartDataProperties.js +0 -64
  86. package/dist/components/Charts/Core/DefaultProperties.d.ts +0 -0
  87. package/dist/components/Charts/Core/DefaultProperties.js +0 -0
  88. package/dist/components/Charts/Core/DefaultProperties.type.d.ts +0 -586
  89. package/dist/components/Charts/Core/DefaultProperties.type.js +0 -585
  90. package/dist/components/Charts/Core/DefaultProperties.types.js +0 -592
  91. package/dist/index.js +0 -40
  92. /package/dist/{components → Components}/Charts/ChartsWithAxis/AreaFamily/AreaChart.d.ts +0 -0
  93. /package/dist/{components → Components}/Charts/ChartsWithAxis/AreaFamily/NormalizedStackAreaChart.d.ts +0 -0
  94. /package/dist/{components → Components}/Charts/ChartsWithAxis/AreaFamily/StackAreaChart.d.ts +0 -0
  95. /package/dist/{components → Components}/Charts/ChartsWithAxis/ChartsWithAxisTypes.types.d.ts +0 -0
  96. /package/dist/{components → Components}/Charts/ChartsWithAxis/ColumnFamily/ColumnChart.d.ts +0 -0
  97. /package/dist/{components → Components}/Charts/ChartsWithAxis/ColumnFamily/ColumnHistogramChart.d.ts +0 -0
  98. /package/dist/{components → Components}/Charts/ChartsWithAxis/ColumnFamily/CustomColumnChart.d.ts +0 -0
  99. /package/dist/{components → Components}/Charts/ChartsWithAxis/ColumnFamily/LayeredColumnChart.d.ts +0 -0
  100. /package/dist/{components → Components}/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackColumnChart.d.ts +0 -0
  101. /package/dist/{components → Components}/Charts/ChartsWithAxis/ColumnFamily/StackColumnChart.d.ts +0 -0
  102. /package/dist/{components → Components}/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalBarChart.d.ts +0 -0
  103. /package/dist/{components → Components}/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalHistogramChart.d.ts +0 -0
  104. /package/dist/{components → Components}/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredHorizontalBarChart.d.ts +0 -0
  105. /package/dist/{components → Components}/Charts/ChartsWithAxis/HorizontalBarFamily/NormalizedStackHorizontalBarChart.d.ts +0 -0
  106. /package/dist/{components → Components}/Charts/ChartsWithAxis/HorizontalBarFamily/StackHorizontalBarChart.d.ts +0 -0
  107. /package/dist/{components → Components}/Charts/ChartsWithAxis/LineFamily/LineChart.d.ts +0 -0
  108. /package/dist/{components/Charts/ChartsWithAxis/ColumnFamily → Components/Charts/ChartsWithAxis/LineFamily}/NormalizedStackLineChart.d.ts +0 -0
  109. /package/dist/{components/Charts/ChartsWithAxis/ColumnFamily → Components/Charts/ChartsWithAxis/LineFamily}/StackLineChart.d.ts +0 -0
  110. /package/dist/{components → Components}/Charts/ChartsWithAxis/MiscellaneousChartFamily/TornadoChart.d.ts +0 -0
  111. /package/dist/{components → Components}/Charts/ChartsWithAxis/MiscellaneousChartFamily/WaterfallChart.d.ts +0 -0
  112. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.d.ts +0 -0
  113. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/Maps/Cordinates.d.ts +0 -0
  114. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/Maps/Maps.d.ts +0 -0
  115. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/BubbleChart.d.ts +0 -0
  116. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/OrganizationChart.d.ts +0 -0
  117. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/ProgressChart.d.ts +0 -0
  118. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/PyramidChart.d.ts +0 -0
  119. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/RadialBarChart.d.ts +0 -0
  120. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/SankeyChart.d.ts +0 -0
  121. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/ScatterChart.d.ts +0 -0
  122. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/Speedometer.d.ts +0 -0
  123. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/VennChart.d.ts +0 -0
  124. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/WordCloud.d.ts +0 -0
  125. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/PieFamily/DonutChart.d.ts +0 -0
  126. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/PieFamily/PieChart.d.ts +0 -0
  127. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/PieFamily/PieFamilyCommonFunctions.d.ts +0 -0
  128. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/PieFamily/PieofPieChart.d.ts +0 -0
  129. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/PieFamily/TreemapChart.d.ts +0 -0
  130. /package/dist/{components → Components}/Charts/Core/Common.types.d.ts +0 -0
  131. /package/dist/{components → Components}/Charts/Core/DefaultChartDataProperties.d.ts +0 -0
@@ -1,719 +0,0 @@
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;