pace-chart-lib 0.0.6 → 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.
Files changed (150) hide show
  1. package/README.md +10 -54
  2. package/dist/Components1/Charts/ChartsWithAxis/ChartsWithAxisFunctions.d.ts +46 -0
  3. package/dist/Components1/Charts/ChartsWithAxis/ChartsWithAxisFunctions.js +2285 -0
  4. package/dist/Components1/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.d.ts +169 -0
  5. package/dist/Components1/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.js +47 -0
  6. package/dist/Components1/Charts/ChartsWithAxis/LineFamily/LineChart.d.ts +4 -0
  7. package/dist/Components1/Charts/ChartsWithAxis/LineFamily/LineChart.js +403 -0
  8. package/dist/Components1/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.d.ts +0 -0
  9. package/dist/Components1/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.js +0 -0
  10. package/dist/Components1/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.d.ts +0 -0
  11. package/dist/Components1/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.js +0 -0
  12. package/dist/Components1/Charts/Core/Common.type.d.ts +8 -0
  13. package/dist/Components1/Charts/Core/Common.type.js +9 -0
  14. package/dist/Components1/Charts/Core/CommonFunctions.d.ts +12 -0
  15. package/dist/Components1/Charts/Core/CommonFunctions.js +512 -0
  16. package/dist/Components1/Charts/Core/DefaultProperties.d.ts +586 -0
  17. package/dist/Components1/Charts/Core/DefaultProperties.js +585 -0
  18. package/dist/Services/ErrorLog.d.ts +1 -0
  19. package/dist/Services/ErrorLog.js +3 -0
  20. package/dist/components/Charts/ChartsWithAxis/AreaFamily/AreaChart.d.ts +4 -0
  21. package/dist/components/Charts/ChartsWithAxis/AreaFamily/AreaChart.js +497 -0
  22. package/dist/components/Charts/ChartsWithAxis/AreaFamily/LineChart.d.ts +4 -0
  23. package/dist/components/Charts/ChartsWithAxis/AreaFamily/LineChart.js +491 -0
  24. package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackAreaChart.d.ts +4 -0
  25. package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackAreaChart.js +520 -0
  26. package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackLineChart.d.ts +4 -0
  27. package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackLineChart.js +553 -0
  28. package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackAreaChart.d.ts +4 -0
  29. package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackAreaChart.js +519 -0
  30. package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackLineChart.d.ts +4 -0
  31. package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackLineChart.js +553 -0
  32. package/dist/components/Charts/ChartsWithAxis/BarFamily/BarChart.d.ts +12 -0
  33. package/dist/components/Charts/ChartsWithAxis/BarFamily/BarChart.js +9 -0
  34. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisFunctions.d.ts +623 -0
  35. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisFunctions.js +4897 -0
  36. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.d.ts +0 -0
  37. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.js +0 -0
  38. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.types.d.ts +173 -0
  39. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.types.js +49 -0
  40. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart copy.d.ts +4 -0
  41. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart copy.js +486 -0
  42. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart.d.ts +4 -0
  43. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart.js +498 -0
  44. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnHistogramChart.d.ts +4 -0
  45. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnHistogramChart.js +417 -0
  46. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/CustomColumnChart.d.ts +4 -0
  47. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/CustomColumnChart.js +1014 -0
  48. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LayeredColumnChart.d.ts +4 -0
  49. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LayeredColumnChart.js +479 -0
  50. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LineChart.d.ts +4 -0
  51. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LineChart.js +451 -0
  52. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackColumnChart.d.ts +4 -0
  53. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackColumnChart.js +535 -0
  54. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackLineChart.d.ts +4 -0
  55. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackLineChart.js +512 -0
  56. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackColumnChart.d.ts +4 -0
  57. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackColumnChart.js +532 -0
  58. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackLineChart.d.ts +4 -0
  59. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackLineChart.js +512 -0
  60. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/BarChart.d.ts +12 -0
  61. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/BarChart.js +9 -0
  62. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalBarChart.d.ts +4 -0
  63. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalBarChart.js +498 -0
  64. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalHistogramChart.d.ts +4 -0
  65. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalHistogramChart.js +498 -0
  66. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredColumnChart.d.ts +4 -0
  67. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredColumnChart.js +479 -0
  68. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredHorizontalBarChart.d.ts +4 -0
  69. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredHorizontalBarChart.js +479 -0
  70. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/NormalizedStackHorizontalBarChart.d.ts +4 -0
  71. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/NormalizedStackHorizontalBarChart.js +474 -0
  72. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/StackHorizontalBarChart.d.ts +4 -0
  73. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/StackHorizontalBarChart.js +464 -0
  74. package/dist/components/Charts/ChartsWithAxis/LineFamily/100%StackLineChart.d.ts +0 -0
  75. package/dist/components/Charts/ChartsWithAxis/LineFamily/100%StackLineChart.js +0 -0
  76. package/dist/components/Charts/ChartsWithAxis/LineFamily/LineChart.d.ts +4 -0
  77. package/dist/components/Charts/ChartsWithAxis/LineFamily/LineChart.js +452 -0
  78. package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalisedStackLineChart.d.ts +4 -0
  79. package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalisedStackLineChart.js +554 -0
  80. package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalizedStackLineChart.d.ts +4 -0
  81. package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalizedStackLineChart.js +513 -0
  82. package/dist/components/Charts/ChartsWithAxis/LineFamily/StackLineChart.d.ts +4 -0
  83. package/dist/components/Charts/ChartsWithAxis/LineFamily/StackLineChart.js +508 -0
  84. package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/TornadoChart.d.ts +4 -0
  85. package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/TornadoChart.js +395 -0
  86. package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/WaterfallChart.d.ts +4 -0
  87. package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/WaterfallChart.js +608 -0
  88. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxis.types.d.ts +0 -0
  89. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxis.types.js +0 -0
  90. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.d.ts +92 -0
  91. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.js +815 -0
  92. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.d.ts +0 -0
  93. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.js +0 -0
  94. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.types.d.ts +108 -0
  95. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.types.js +32 -0
  96. package/dist/components/Charts/ChartsWithoutAxis/Maps/Cordinates.d.ts +26 -0
  97. package/dist/components/Charts/ChartsWithoutAxis/Maps/Cordinates.js +15021 -0
  98. package/dist/components/Charts/ChartsWithoutAxis/Maps/Maps.d.ts +4 -0
  99. package/dist/components/Charts/ChartsWithoutAxis/Maps/Maps.js +391 -0
  100. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/BubbleChart.d.ts +4 -0
  101. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/BubbleChart.js +367 -0
  102. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/OrganizationChart.d.ts +4 -0
  103. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/OrganizationChart.js +569 -0
  104. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ProgressChart.d.ts +3 -0
  105. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ProgressChart.js +212 -0
  106. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/PyramidChart.d.ts +3 -0
  107. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/PyramidChart.js +401 -0
  108. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/RadialBarChart.d.ts +4 -0
  109. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/RadialBarChart.js +313 -0
  110. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/SankeyChart.d.ts +4 -0
  111. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/SankeyChart.js +719 -0
  112. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ScatterChart.d.ts +4 -0
  113. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ScatterChart.js +807 -0
  114. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/Speedometer.d.ts +3 -0
  115. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/Speedometer.js +514 -0
  116. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/VennChart.d.ts +4 -0
  117. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/VennChart.js +282 -0
  118. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/WordCloud.d.ts +4 -0
  119. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/WordCloud.js +207 -0
  120. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/DonutChart.d.ts +4 -0
  121. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/DonutChart.js +476 -0
  122. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieChart.d.ts +4 -0
  123. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieChart.js +420 -0
  124. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieFamilyCommonFunctions.d.ts +10 -0
  125. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieFamilyCommonFunctions.js +106 -0
  126. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieofPieChart.d.ts +3 -0
  127. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieofPieChart.js +507 -0
  128. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/TreemapChart.d.ts +3 -0
  129. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/TreemapChart.js +246 -0
  130. package/dist/components/Charts/Core/Common.type.d.ts +0 -0
  131. package/dist/components/Charts/Core/Common.type.js +0 -0
  132. package/dist/components/Charts/Core/Common.types.d.ts +369 -0
  133. package/dist/components/Charts/Core/Common.types.js +133 -0
  134. package/dist/components/Charts/Core/CommonFunctions.d.ts +236 -0
  135. package/dist/components/Charts/Core/CommonFunctions.js +1778 -0
  136. package/dist/components/Charts/Core/DefaultChartDataProperties.d.ts +65 -0
  137. package/dist/components/Charts/Core/DefaultChartDataProperties.js +64 -0
  138. package/dist/components/Charts/Core/DefaultProperties.d.ts +0 -0
  139. package/dist/components/Charts/Core/DefaultProperties.js +0 -0
  140. package/dist/components/Charts/Core/DefaultProperties.type.d.ts +586 -0
  141. package/dist/components/Charts/Core/DefaultProperties.type.js +585 -0
  142. package/dist/components/Charts/Core/DefaultProperties.types.d.ts +592 -0
  143. package/dist/components/Charts/Core/DefaultProperties.types.js +592 -0
  144. package/dist/index.d.ts +34 -2
  145. package/dist/index.js +40 -2
  146. package/package.json +40 -29
  147. package/dist/components/charts/linechart/LineChart.d.ts +0 -12
  148. package/dist/components/charts/linechart/LineChart.js +0 -5
  149. /package/dist/{components/charts/barchart → Components1/Charts/ChartsWithAxis/BarFamily}/BarChart.d.ts +0 -0
  150. /package/dist/{components/charts/barchart → Components1/Charts/ChartsWithAxis/BarFamily}/BarChart.js +0 -0
@@ -0,0 +1,569 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ //#region imports
3
+ import * as d3 from "d3";
4
+ import { OrgChart } from "d3-org-chart";
5
+ import { useEffect, useRef } from "react";
6
+ import { fontStyleOptions, } from "../../Core/Common.types";
7
+ import { convertStringToNumber, drawChartTitle, firstFunctionBeforeRender, getNumberWithFormatFunction, initSvg, marginCalculationsForChartsWithoutLegends, } from "../../Core/CommonFunctions";
8
+ import { chartMargins } from "../../Core/DefaultProperties.types";
9
+ import { connectorStyle, orgChartDirection, orgChartLineType, orgChartNodeType, } from "../ChartsWithoutAxisTypes.types";
10
+ import { logError } from "../../../../Services/ErrorLog";
11
+ //#endregion
12
+ const fileName = "OrganizationChart.tsx";
13
+ const OrganizationChart = ({ data, legendEntries, chartId, formatOptions, legendSequence, }) => {
14
+ //#region Variables
15
+ const svgRef = useRef(); // Reference to the SVG element
16
+ const floatingSvgRef = useRef(); // Reference to the SVG element
17
+ let chartFormatOptions; // Format options for the chart
18
+ let width; // svg total width
19
+ let height; // svg total height
20
+ let chartTitleHeight = 40; // Height of the chart title
21
+ let margins = chartMargins; // Margins for the chart
22
+ let svg; // SVG element for the chart
23
+ let idIndexMap = new Map(); // Map to store the index of each id in the data
24
+ let indexMapForStyleObject = new Map(); // Map to store the index and UID for styling purposes
25
+ let chartDirection = orgChartDirection.left; // Direction of the chart layout, default is left
26
+ let chartData = [];
27
+ let scrollWidth = 0;
28
+ let scrollHeight = 0;
29
+ //#endregion
30
+ useEffect(() => {
31
+ drawChart();
32
+ }, [chartId, data, formatOptions]);
33
+ const drawChart = () => {
34
+ ({ chartFormatOptions, svg, width, height } = firstFunctionBeforeRender(svgRef, formatOptions));
35
+ ({ margins, chartTitleHeight, innerHeight, innerWidth } =
36
+ marginCalculationsForChartsWithoutLegends(chartFormatOptions, height, width));
37
+ initSvg(svgRef, width, height, chartFormatOptions); // Initialize SVG with width, height and background color
38
+ drawChartTitle(svgRef, chartTitleHeight, width, chartFormatOptions);
39
+ dataPreparation();
40
+ scrollWidthHeightCalculation();
41
+ drawOrganizationChart(chartData);
42
+ };
43
+ const dataPreparation = () => {
44
+ try {
45
+ chartDirection =
46
+ chartFormatOptions.plotArea.chartDirection || orgChartDirection.left;
47
+ var sum = 0;
48
+ var absoluteSum = 0;
49
+ data.forEach((item) => {
50
+ sum = sum + item.value;
51
+ absoluteSum = absoluteSum + item.absoluteValue;
52
+ });
53
+ var newObj = {
54
+ id: 0,
55
+ children: data,
56
+ value: sum, // Total value of all children
57
+ absoluteValue: absoluteSum,
58
+ nodeLabel: "",
59
+ UID: "",
60
+ };
61
+ let tempData = getFlattenedData(newObj).filter((data) => data.value !== null);
62
+ createIdIndexMap(tempData); // Create a map of id to index for quick access
63
+ generateUID(tempData); // Generate unique IDs for each node based on its parent
64
+ chartData = addStyleObjectToChartData(tempData);
65
+ }
66
+ catch (error) {
67
+ logError(fileName, "dataPreparation", error);
68
+ }
69
+ };
70
+ const scrollWidthHeightCalculation = () => {
71
+ try {
72
+ if (chartFormatOptions.plotArea.fitChart) {
73
+ scrollHeight = height;
74
+ scrollWidth = width;
75
+ floatingSvgRef.current.style.width = `calc(100% - 10px)`;
76
+ floatingSvgRef.current.style.height = `calc(100% - 10px)`;
77
+ }
78
+ else {
79
+ scrollWidth = 0;
80
+ chartData.forEach((node) => {
81
+ if (node.label == legendSequence[legendSequence.length - 1]) {
82
+ scrollWidth += calculateNodeWidth(node, false);
83
+ }
84
+ });
85
+ scrollHeight =
86
+ (legendSequence.length + 1) *
87
+ convertStringToNumber(chartFormatOptions.nodes.nodeHeight) *
88
+ 10 +
89
+ (legendSequence.length + 1) * 70;
90
+ floatingSvgRef.current.style.width = `${scrollWidth}px`;
91
+ floatingSvgRef.current.style.height = `${scrollHeight}px`;
92
+ d3.select(floatingSvgRef.current)
93
+ .append("defs")
94
+ .attr("id", `defs${chartId}`)
95
+ .append("clipPath")
96
+ .attr("id", `clipPath${chartId}`)
97
+ .append("rect")
98
+ .attr("width", width - margins.left - margins.right)
99
+ .attr("height", height - margins.top - margins.bottom - 15)
100
+ .attr("transform", `translate(${margins.left},${margins.top})`); // Adjust these values as needed
101
+ // Position the clipPath relative to the SVG container
102
+ document
103
+ .querySelector("#floating-div" + chartId)
104
+ .addEventListener("scroll", updateClipPathPosition);
105
+ d3.select(floatingSvgRef.current).attr("clip-path", `url(#clipPath${chartId})`);
106
+ function updateClipPathPosition() {
107
+ let self = this;
108
+ var scrollLeft = self.scrollLeft;
109
+ var scrollTop = self.scrollTop;
110
+ d3.select(`#clipPath${chartId}`)
111
+ .select("rect")
112
+ .attr("x", scrollLeft)
113
+ .attr("y", scrollTop);
114
+ }
115
+ }
116
+ }
117
+ catch (error) {
118
+ logError(fileName, "scrollWidthHeightCalculation", error);
119
+ }
120
+ };
121
+ const generateUID = (data) => {
122
+ try {
123
+ data.forEach((nodeObject, i) => {
124
+ if (nodeObject.id != 0) {
125
+ let parentUID = data[idIndexMap.get(nodeObject.parentId)].UID;
126
+ parentUID === ""
127
+ ? (nodeObject.UID = nodeObject.nodeLabel)
128
+ : (nodeObject.UID = parentUID + "-" + nodeObject.nodeLabel);
129
+ indexMapForStyleObject.set(nodeObject.UID, i); //Maintaining map of index and UID
130
+ }
131
+ });
132
+ }
133
+ catch (error) {
134
+ logError(fileName, "generateUID", error);
135
+ }
136
+ };
137
+ const addStyleObjectToChartData = (data) => {
138
+ try {
139
+ data[0] = { ...data[0], styleObject: legendEntries[0] };
140
+ legendEntries.forEach((styleObject) => {
141
+ if (styleObject === legendEntries[0])
142
+ return;
143
+ let dataIndex = indexMapForStyleObject.get(styleObject.name);
144
+ let obj = data[dataIndex];
145
+ data[dataIndex] = { ...obj, styleObject: styleObject };
146
+ });
147
+ return data;
148
+ }
149
+ catch (error) {
150
+ logError(fileName, "addStyleObjectToChartData", error);
151
+ }
152
+ };
153
+ const createIdIndexMap = (data) => {
154
+ try {
155
+ data.forEach((object, i) => {
156
+ idIndexMap.set(object.id, i);
157
+ });
158
+ }
159
+ catch (error) {
160
+ logError(fileName, "createIdIndexMap", error);
161
+ }
162
+ };
163
+ const getFlattenedData = (dataHierarchy) => {
164
+ try {
165
+ const descendants = d3.hierarchy(dataHierarchy).descendants();
166
+ descendants.forEach((d, i) => {
167
+ d.id = d.id || "id" + i;
168
+ });
169
+ return descendants.map((d, i) => {
170
+ const copy = { ...d.data };
171
+ delete copy.children;
172
+ if (d.parent) {
173
+ copy.parentValue = d.parent.data.value || 0;
174
+ }
175
+ return { ...copy, ...{ parentId: d.parent?.data?.id } };
176
+ });
177
+ }
178
+ catch (error) {
179
+ logError(fileName, "getFlattenedData", error);
180
+ }
181
+ };
182
+ const drawOrganizationChart = (chartData) => {
183
+ try {
184
+ let lineType = chartFormatOptions.connector.lineType || "straight";
185
+ let nodeType = chartFormatOptions.nodes.nodeType || orgChartNodeType.rectangle;
186
+ let connectorVisibility = parseInt(chartFormatOptions.connector.connectorLineThickness);
187
+ let organizationalChart = new OrgChart();
188
+ organizationalChart
189
+ .container(`#floating-${chartId}`)
190
+ .svgWidth(scrollWidth)
191
+ .svgHeight(scrollHeight)
192
+ .nodeHeight((d) => calculateNodeHeight(d))
193
+ .nodeWidth((d) => calculateNodeWidth(d, true))
194
+ .layout(chartDirection)
195
+ .diagonal((s, t, m, offsets = { sy: 0 }) => {
196
+ if (chartDirection == "top" ||
197
+ chartDirection == "bottom" ||
198
+ !chartDirection) {
199
+ switch (lineType) {
200
+ case orgChartLineType.curve:
201
+ return `M ${s.x} ${s.y} C ${(s.x + t.x) / 2} ${s.y}, ${(s.x + t.x) / 2} ${t.y}, ${t.x} ${t.y}`;
202
+ case orgChartLineType.elbow:
203
+ return `M ${s.x} ${s.y} H ${s.x} V ${t.y} H ${t.x}`;
204
+ case orgChartLineType.diagonal:
205
+ return `M ${s.x} ${s.y} L ${(s.x + t.x) / 2} ${s.y} L ${(s.x + t.x) / 2} ${t.y} L ${t.x} ${t.y}`;
206
+ case orgChartLineType.s_curve:
207
+ const midY = (s.y + t.y) / 2;
208
+ return `M ${s.x},${s.y} C ${s.x},${midY} ${t.x},${midY} ${t.x},${t.y}`;
209
+ case orgChartLineType.arc:
210
+ const dx = t.x - s.x;
211
+ const dy = t.y - s.y;
212
+ const dr = Math.sqrt(dx * dx + dy * dy);
213
+ return `M ${s.x},${s.y} A ${dr},${dr} 0 0,1 ${t.x},${t.y}`;
214
+ case orgChartLineType.reverse_elbow:
215
+ if (chartDirection == orgChartDirection.bottom)
216
+ return `M ${s.x} ${s.y} V ${s.y - 20} H ${t.x} V ${t.y}`;
217
+ else if (chartDirection == orgChartDirection.top)
218
+ return `M ${s.x} ${s.y} V ${s.y + 20} H ${t.x} V ${t.y}`;
219
+ case orgChartLineType.zigzag:
220
+ if (chartDirection == orgChartDirection.top) {
221
+ const mid = (s.y + t.y) / 2;
222
+ return `M ${s.x},${s.y} L ${s.x},${mid - 10} L ${t.x},${mid + 10} L ${t.x},${t.y}`;
223
+ }
224
+ else if (chartDirection == orgChartDirection.bottom) {
225
+ const midY = (s.y + t.y) / 2;
226
+ return `
227
+ M ${s.x},${s.y}
228
+ L ${s.x},${midY + 10}
229
+ L ${t.x},${midY - 10}
230
+ L ${t.x},${t.y}
231
+ `;
232
+ }
233
+ default:
234
+ if (chartDirection == orgChartDirection.bottom) {
235
+ return `M ${s.x} ${s.y} V ${s.y + 25} H ${t.x} V ${t.y}`;
236
+ }
237
+ else if (chartDirection == "top") {
238
+ return `M ${s.x} ${s.y} V ${s.y - 25} H ${t.x} V ${t.y}`;
239
+ }
240
+ }
241
+ }
242
+ })
243
+ .hdiagonal((s, t, m, offsets = { sx: 0 }) => {
244
+ if (chartDirection === orgChartDirection.left ||
245
+ chartDirection === orgChartDirection.right) {
246
+ switch (lineType) {
247
+ case orgChartLineType.curve:
248
+ return `M ${s.x} ${s.y} C ${(s.x + t.x) / 2} ${s.y}, ${(s.x + t.x) / 2} ${t.y}, ${t.x} ${t.y}`;
249
+ case orgChartLineType.elbow:
250
+ if (chartDirection == orgChartDirection.left)
251
+ return `M ${s.x} ${s.y} H ${s.x - 50} V ${t.y} H ${t.x}`;
252
+ else if (chartDirection == orgChartDirection.right) {
253
+ return `M ${s.x} ${s.y} H ${s.x + 50} V ${t.y} H ${t.x}`;
254
+ }
255
+ case orgChartLineType.diagonal:
256
+ return `M ${s.x} ${s.y} L ${(s.x + t.x) / 2} ${s.y} L ${(s.x + t.x) / 2} ${t.y} L ${t.x} ${t.y}`;
257
+ case orgChartLineType.s_curve:
258
+ const midX = (s.x + t.x) / 2;
259
+ return `M ${s.x},${s.y} C ${midX},${s.y} ${midX},${t.y} ${t.x},${t.y}`;
260
+ case orgChartLineType.arc:
261
+ if (chartDirection == orgChartDirection.left) {
262
+ const dx = t.x - s.x;
263
+ const dy = t.y - s.y;
264
+ const dr = Math.sqrt(dx * dx + dy * dy);
265
+ return `M ${s.x},${s.y} A ${dr},${dr} 0 0,1 ${t.x},${t.y}`;
266
+ }
267
+ else if (chartDirection == orgChartDirection.right) {
268
+ const dxRight = s.x - t.x; // Inverse the dx for right orientation
269
+ const dyRight = t.y - s.y;
270
+ const drRight = Math.sqrt(dxRight * dxRight + dyRight * dyRight);
271
+ return `M ${s.x},${s.y} A ${drRight},${drRight} 0 0,0 ${t.x},${t.y}`;
272
+ }
273
+ case "reverse-elbow":
274
+ if (chartDirection == orgChartDirection.left)
275
+ return `M ${s.x} ${s.y} H ${s.x + 60} V ${t.y} H ${t.x}`;
276
+ else if (chartDirection == orgChartDirection.right)
277
+ return `M ${s.x} ${s.y} H ${s.x - 60} V ${t.y} H ${t.x}`;
278
+ case "zigzag":
279
+ if (chartDirection == orgChartDirection.left) {
280
+ const midX = (s.x + t.x) / 2;
281
+ return `
282
+ M ${s.x},${s.y}
283
+ L ${midX - 10},${s.y}
284
+ L ${midX + 10},${t.y}
285
+ L ${t.x},${t.y}
286
+ `;
287
+ }
288
+ else {
289
+ const midX = (s.x + t.x) / 2;
290
+ return `
291
+ M ${s.x},${s.y}
292
+ L ${midX + 10},${s.y}
293
+ L ${midX - 10},${t.y}
294
+ L ${t.x},${t.y}
295
+ `;
296
+ }
297
+ default:
298
+ if (chartDirection == orgChartDirection.left)
299
+ return `M ${s.x} ${s.y} H ${s.x - 25} V ${t.y} H ${t.x}`;
300
+ else
301
+ return `M ${s.x} ${s.y} H ${s.x + 25} V ${t.y} H ${t.x}`;
302
+ }
303
+ }
304
+ else {
305
+ return `M ${s.x} ${s.y} L ${t.x} ${t.y}`; // fallback for vertical
306
+ }
307
+ })
308
+ .linkUpdate(function (d) {
309
+ try {
310
+ if (connectorVisibility) {
311
+ const markerType = chartFormatOptions.plotArea.connectorType || "arrow";
312
+ const isValidMarker = ["arrow", "diamond", "dot"].includes(markerType) &&
313
+ chartFormatOptions.connector.lineType !== "reverse-elbow";
314
+ d3.select(this)
315
+ .attr("stroke-width", chartFormatOptions.connector.connectorLineThickness)
316
+ .attr("stroke-dasharray", chartFormatOptions.connector.connectorStyle ===
317
+ connectorStyle.solid
318
+ ? 0
319
+ : chartFormatOptions.connector.connectorStyle ===
320
+ connectorStyle.dotted
321
+ ? 1
322
+ : 4)
323
+ .style("stroke", chartFormatOptions.connector.connectorLineColor)
324
+ .attr("marker-start", isValidMarker ? `url(#${markerType})` : null)
325
+ .attr("marker-end", null); // always null to avoid showing marker at parent
326
+ }
327
+ else {
328
+ d3.select(this)
329
+ .attr("stroke-width", 0)
330
+ .attr("marker-start", null)
331
+ .attr("marker-end", null);
332
+ }
333
+ }
334
+ catch (error) {
335
+ logError(fileName, "drawOrganizationChart.linkUpdate", error);
336
+ }
337
+ })
338
+ .nodeContent((d, i) => {
339
+ try {
340
+ let borderRadius = `${d.data.styleObject.borderRadius}px`;
341
+ let transform = "";
342
+ let innerWrapperStart = "";
343
+ let innerWrapperEnd = "";
344
+ let clipPath = "";
345
+ let shapeStyle = "";
346
+ switch (nodeType) {
347
+ case orgChartNodeType.rounded:
348
+ borderRadius = "10px";
349
+ break;
350
+ case orgChartNodeType.pill:
351
+ borderRadius = "999px";
352
+ break;
353
+ case orgChartNodeType.extra_rounded:
354
+ borderRadius = "20px";
355
+ break;
356
+ case orgChartNodeType.squircle:
357
+ borderRadius = "25%";
358
+ break;
359
+ default:
360
+ borderRadius = "1px";
361
+ break;
362
+ }
363
+ shapeStyle = `
364
+ border-width: ${d.data.styleObject.borderWidth}px
365
+ border-style:${chartFormatOptions.nodes.nodesBorderVisibility
366
+ ? d.data.styleObject.borderStyle
367
+ : "none"}
368
+ border-color:${d.data.styleObject.borderColor};
369
+ border-radius: ${borderRadius};
370
+ `;
371
+ return `<div hoverId="${d.data.label}" style="
372
+ border-width: ${d.data.styleObject.borderWidth}px;
373
+ border-style:${chartFormatOptions.nodes.nodesBorderVisibility
374
+ ? d.data.styleObject.borderStyle
375
+ : "none"} ;
376
+ border-color:${d.data.styleObject.borderColor};
377
+ border-radius: ${borderRadius};
378
+ width: ${d.width}px;
379
+ height: ${d.height}px;
380
+ padding: 5px;
381
+ display: flex;
382
+ flex-direction: column;
383
+ justify-content: center;
384
+ align-items: center;
385
+ text-align: center;
386
+ background-color: ${d.data.styleObject.backgroundColor
387
+ ? d.data.styleObject.backgroundColor
388
+ : d.data.styleObject.Color};
389
+ z-index: 99;
390
+ transform: ${transform};
391
+ transition: unset;">
392
+
393
+ ${innerWrapperStart}
394
+
395
+ <div style="font-family:${d.data.styleObject.labelFont};
396
+ color:${d.data.styleObject.labelFontColor};
397
+ font-size:${d.data.styleObject.labelFontSize}px;
398
+ font-weight:${d.data.styleObject.labelFontStyle.includes(fontStyleOptions.bold)
399
+ ? "Bolder"
400
+ : "normal"};
401
+ font-style:${d.data.styleObject.labelFontStyle.includes(fontStyleOptions.italic)
402
+ ? fontStyleOptions.italic
403
+ : "normal"};
404
+ text-decoration:${d.data.styleObject.labelFontStyle.includes(fontStyleOptions.underline)
405
+ ? fontStyleOptions.underline
406
+ : "none"};
407
+ text-overflow: ellipsis;
408
+ overflow: hidden;
409
+ white-space: nowrap;
410
+ max-width: ${d.width}px;
411
+ padding: 5px;">
412
+ ${i === 0
413
+ ? d.data.styleObject.alias
414
+ : chartFormatOptions.nodes.nodesLabelVisibility
415
+ ? `${d.data.label} : ${getLabelText(d.data.styleObject.alias)}`
416
+ : `${getLabelText(d.data.styleObject.alias)}`}
417
+ </div>
418
+
419
+ <div style="font-family:${d.data.styleObject.valueFont};
420
+ color:${d.data.styleObject.valueFontColor};
421
+ font-weight:${d.data.styleObject.valueFontStyle.includes(fontStyleOptions.bold)
422
+ ? "Bolder"
423
+ : "normal"};
424
+ font-style:${d.data.styleObject.valueFontStyle.includes(fontStyleOptions.italic)
425
+ ? fontStyleOptions.italic
426
+ : "normal"};
427
+ text-decoration:${d.data.styleObject.valueFontStyle.includes(fontStyleOptions.underline)
428
+ ? fontStyleOptions.underline
429
+ : "none"};
430
+ font-size:${d.data.styleObject.valueFontSize}px;">
431
+ ${chartFormatOptions.nodes.dataLabelNumberFormat == ",.0%"
432
+ ? d.data.parentValue
433
+ ? Math.round((d.data.value / d.data.parentValue) * 100) + "%"
434
+ : Math.round((d.data.value / d.data.value) * 100) +
435
+ "%"
436
+ : getNumberWithFormatFunction(chartFormatOptions.nodes.nodesDisplayUnits, chartFormatOptions.nodes.dataLabelNumberFormat, chartFormatOptions.nodes.dataLabelDecimalPrecision)(d.data.value)}
437
+ <br>
438
+ ${chartFormatOptions.nodes.percentageVisibility
439
+ ? +d.data.parentValue
440
+ ? Math.round((d.data.value / d.data.parentValue) * 100) + "%"
441
+ : Math.round((d.data.value / d.data.value) * 100) +
442
+ "%"
443
+ : ""}
444
+ </div>
445
+
446
+ ${innerWrapperEnd}
447
+ </div>`;
448
+ }
449
+ catch (error) {
450
+ logError(fileName, "drawOrganizationChart.nodeContent", error);
451
+ return "";
452
+ }
453
+ })
454
+ .buttonContent(({ node, state }) => {
455
+ try {
456
+ if (connectorVisibility) {
457
+ return `
458
+ <div
459
+ style="
460
+ color: black;
461
+ height: 10px;
462
+ width: 10px;
463
+ padding: 0;
464
+ font-size: 10px;
465
+ margin: auto;
466
+ background-color: white;
467
+ display: flex;
468
+ justify-content: center;
469
+ align-items: center;
470
+ border-radius: 50%;
471
+ border: 1px solid ${node.data.styleObject.borderColor};
472
+ position: relative;
473
+ ">
474
+ <span style="font-size: 10px; position: relative; align-items: center; top:-0.15px">
475
+ ${node.children ? `-` : `+`}
476
+ </span>
477
+ ${!node.children
478
+ ? `<span style="
479
+ position: absolute;
480
+ bottom: -8px;
481
+ font-size: 7px;
482
+ font-weight: bold;
483
+ ">${node.data._directSubordinates}</span>`
484
+ : ""}
485
+ </div>`;
486
+ }
487
+ }
488
+ catch (error) {
489
+ logError(fileName, "drawOrganizationChart.buttonContent", error);
490
+ return "";
491
+ }
492
+ })
493
+ .childrenMargin((d) => 50)
494
+ .siblingsMargin((d) => 20)
495
+ .neighbourMargin((n1, n2) => 20)
496
+ .duration(0)
497
+ .setActiveNodeCentered(false)
498
+ .data(chartData)
499
+ .compact(false)
500
+ .expandAll()
501
+ .fit(false)
502
+ .render();
503
+ }
504
+ catch (error) {
505
+ logError(fileName, "drawOrganizationChart", error);
506
+ }
507
+ };
508
+ const calculateNodeHeight = (d) => {
509
+ try {
510
+ let height;
511
+ if (d.data.styleObject) {
512
+ chartFormatOptions.nodes.percentageVisibility
513
+ ? (height = d.data.styleObject.nodeHeight * 10 + 10)
514
+ : (height = d.data.styleObject.nodeHeight * 10);
515
+ return height;
516
+ }
517
+ }
518
+ catch (error) {
519
+ logError(fileName, "calculateNodeHeight", error);
520
+ }
521
+ };
522
+ const calculateNodeWidth = (d, throughOrgData) => {
523
+ try {
524
+ let data = {};
525
+ throughOrgData ? (data = d.data) : (data = d);
526
+ let width;
527
+ let staticAddition;
528
+ chartFormatOptions.nodes.nodesLabelVisibility
529
+ ? (staticAddition = 50)
530
+ : (staticAddition = 20);
531
+ if (data.styleObject) {
532
+ if (chartFormatOptions.nodes.nodesLabelOverflow) {
533
+ data.id == 0
534
+ ? (width = data.styleObject.nodeWidth * 10 + 50)
535
+ : (width = data.styleObject.nodeWidth * 10);
536
+ }
537
+ else {
538
+ width =
539
+ staticAddition +
540
+ getLabelText(data.styleObject.alias).length * 10 +
541
+ data.styleObject.labelFontSize * 5;
542
+ }
543
+ return width;
544
+ }
545
+ }
546
+ catch (error) {
547
+ logError(fileName, "calculateNodeWidth", error);
548
+ }
549
+ };
550
+ const getLabelText = (name) => {
551
+ try {
552
+ let parts = name.split("-");
553
+ let lastValue = parts[parts.length - 1];
554
+ return lastValue;
555
+ }
556
+ catch (error) {
557
+ logError(fileName, "getLabelText", error);
558
+ }
559
+ };
560
+ return (_jsxs("div", { style: { width: "100%", height: "100%", position: "relative" }, children: [_jsx("svg", { id: chartId, className: "chartSVG", style: { width: "100%", height: "100%" }, ref: svgRef }), _jsx("div", { id: `floating-div${chartId}`, className: "floatingDiv", style: {
561
+ position: "absolute",
562
+ left: 0,
563
+ top: 0,
564
+ width: "100%",
565
+ height: "100%",
566
+ overflow: "auto",
567
+ }, children: _jsx("svg", { id: `floating-${chartId}`, className: "chartSVG", ref: floatingSvgRef }) })] }));
568
+ };
569
+ export default OrganizationChart;
@@ -0,0 +1,3 @@
1
+ import { IChartProps } from "../ChartsWithoutAxisTypes.types";
2
+ declare const ProgressChart: React.FC<IChartProps>;
3
+ export default ProgressChart;