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.
Files changed (150) hide show
  1. package/README.md +10 -10
  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,212 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import { fontStyleOptions, } from "../../Core/Common.types";
4
+ import { chartMargins } from "../../Core/DefaultProperties.types";
5
+ import * as d3 from "d3";
6
+ import { calculateLegendsMaxPossibleWidth, convertStringToNumber, drawChartTitle, firstFunctionBeforeRender, generalizedChartData, getNumberWithFormatFunction, hideTooltipOnMouseOut, initChartArea, initLegendListWithTotalValueAllowance, initSvg, marginCalculationsForChartsWithoutAxis, showTooltipOnMouseMove, } from "../../Core/CommonFunctions";
7
+ import { drawTotalValue } from "../PieFamily/PieFamilyCommonFunctions";
8
+ import { logError } from "../../../../Services/ErrorLog";
9
+ const fileName = "ProgressChart.tsx";
10
+ const ProgressChart = ({ data, formatOptions, chartId, }) => {
11
+ const svgRef = useRef(); // Reference to the SVG element
12
+ const seriesData = generalizedChartData(data); // Data for the chart
13
+ let chartFormatOptions; // Chart format options
14
+ let width; // svg total width
15
+ let height; // svg total height
16
+ let chartTitleHeight = 40; // Height of the chart title
17
+ let margins = chartMargins; // Margins for the chart
18
+ let maxLegendDimensions = [0, 0]; // to calculate margins [width, height]
19
+ let innerHeight; // Height of the chart excluding margins
20
+ let innerWidth; // Width of the chart excluding margins
21
+ let totalValue; // Total value of the progress chart
22
+ let chartAreaTagG; // Group element for the chart area
23
+ let svg; // D3 selection of the SVG element
24
+ let legendListWidth; // Width of the legend list
25
+ let radius; // Radius of the pie chart
26
+ let innerRadius; // Inner radius of the pie chart
27
+ useEffect(() => {
28
+ drawChart();
29
+ }, [formatOptions]);
30
+ const drawChart = () => {
31
+ // Skipped try-catch as per instruction
32
+ ({ chartFormatOptions, svg, width, height } = firstFunctionBeforeRender(svgRef, formatOptions));
33
+ maxLegendDimensions = calculateLegendsMaxPossibleWidth(chartFormatOptions, seriesData);
34
+ ({ margins, innerHeight, innerWidth, legendListWidth, chartTitleHeight } =
35
+ marginCalculationsForChartsWithoutAxis(chartFormatOptions, width, height, maxLegendDimensions, margins));
36
+ setRadiusAndInnerRadius();
37
+ initSvg(svgRef, width, height, chartFormatOptions); // Initialize SVG with width, height and background color
38
+ chartAreaTagG = initChartArea(svg, margins);
39
+ drawChartTitle(svgRef, chartTitleHeight, width, chartFormatOptions);
40
+ initLegendListWithTotalValueAllowance(chartFormatOptions, svg, seriesData, width, height, legendListWidth, chartTitleHeight, chartId, margins);
41
+ initProgressChartData();
42
+ drawProgressChart();
43
+ drawTotalValue(chartFormatOptions, totalValue, chartTitleHeight, svg, width, height);
44
+ };
45
+ const setRadiusAndInnerRadius = () => {
46
+ try {
47
+ radius = Math.min(innerHeight * 0.45, innerWidth * 0.45);
48
+ innerRadius = Math.min((convertStringToNumber(chartFormatOptions.plotArea.innerRadius) / 100) *
49
+ radius, radius);
50
+ }
51
+ catch (error) {
52
+ logError(fileName, "setRadiusAndInnerRadius", error);
53
+ }
54
+ };
55
+ const initProgressChartData = () => {
56
+ try {
57
+ data = data.sort((a, b) => b.data[0].value - a.data[0].value); // Sort data by value in descending order this will allow me to draw arcs in correct order
58
+ totalValue = data[0].data[0].value + data[1].data[0].value;
59
+ }
60
+ catch (error) {
61
+ logError(fileName, "initProgressChartData", error);
62
+ }
63
+ };
64
+ const drawProgressChart = () => {
65
+ try {
66
+ let maxValue = data[0].data[0].value;
67
+ let progressValue = data[1].data[0].value;
68
+ let completeAngle = Math.PI * 2; // 360 degrees in radians
69
+ let progressAngle = (progressValue / maxValue) * Math.PI * 2;
70
+ let valuefontStyle = chartFormatOptions.plotArea.dataLabelValueFontStyle;
71
+ const arc = d3
72
+ .arc()
73
+ .innerRadius(innerRadius)
74
+ .outerRadius(radius)
75
+ .startAngle(0)
76
+ .cornerRadius(convertStringToNumber(chartFormatOptions.plotArea.cornerRadius));
77
+ // Create a complete arc
78
+ chartAreaTagG
79
+ .append("path")
80
+ .attr("class", "secondary-circle")
81
+ .attr("fill", data[0].properties.color)
82
+ .attr("fill-opacity", chartFormatOptions.plotArea.opacityforProgressScale)
83
+ .attr("d", arc({ endAngle: completeAngle }))
84
+ .on("mousemove", (d) => {
85
+ try {
86
+ showTooltipOnMouseMove([
87
+ {
88
+ key: data[0].properties.alias,
89
+ value: chartFormatOptions.toolTip.toolTipNumberFormatProgress ==
90
+ ",.0%"
91
+ ? "100 %"
92
+ : getNumberWithFormatFunction("None", chartFormatOptions.toolTip
93
+ .toolTipNumberFormatProgress, chartFormatOptions.toolTip.toolTipDecimalPrecision)(maxValue),
94
+ },
95
+ ], chartFormatOptions);
96
+ }
97
+ catch (error) {
98
+ logError(fileName, "drawProgressChart.onMouseMove.secondary-circle", error);
99
+ }
100
+ })
101
+ .on("mouseout", () => {
102
+ try {
103
+ hideTooltipOnMouseOut();
104
+ }
105
+ catch (error) {
106
+ logError(fileName, "drawProgressChart.onMouseOut.secondary-circle", error);
107
+ }
108
+ })
109
+ .attr("transform", getTransformString());
110
+ // Create the progress arc
111
+ chartAreaTagG
112
+ .append("path")
113
+ .attr("class", "progress-circle")
114
+ .attr("fill", data[1].properties.color)
115
+ .attr("fill-opacity", chartFormatOptions.plotArea.opacityforProgressGoal)
116
+ .attr("d", arc({ endAngle: progressAngle }))
117
+ .on("mousemove", (d) => {
118
+ try {
119
+ showTooltipOnMouseMove([
120
+ {
121
+ key: data[1].properties.alias,
122
+ value: chartFormatOptions.toolTip.toolTipNumberFormatProgress ==
123
+ ",.0%"
124
+ ? Math.round((progressValue / maxValue) * 100) + "%"
125
+ : getNumberWithFormatFunction("None", chartFormatOptions.toolTip.toolTipDecimalPrecision, chartFormatOptions.toolTip.toolTipNumberFormatProgress)(maxValue),
126
+ },
127
+ {
128
+ key: data[0].properties.alias,
129
+ value: chartFormatOptions.toolTip.toolTipNumberFormatProgress ==
130
+ ",.0%"
131
+ ? "100 %"
132
+ : getNumberWithFormatFunction("None", chartFormatOptions.toolTip.toolTipDecimalPrecision, chartFormatOptions.toolTip.toolTipNumberFormatProgress)(progressValue),
133
+ },
134
+ ], chartFormatOptions);
135
+ }
136
+ catch (error) {
137
+ logError(fileName, "drawProgressChart.onMouseMove.progress-circle", error);
138
+ }
139
+ })
140
+ .on("mouseout", () => {
141
+ try {
142
+ hideTooltipOnMouseOut();
143
+ }
144
+ catch (error) {
145
+ logError(fileName, "drawProgressChart.onMouseOut.progress-circle", error);
146
+ }
147
+ })
148
+ .attr("transform", "translate(" + innerWidth / 2 + "," + innerHeight / 2 + ")")
149
+ .transition()
150
+ .duration(1000)
151
+ .attrTween("d", function (d) {
152
+ try {
153
+ const interpolate = d3.interpolate(0, progressAngle);
154
+ return function (t) {
155
+ try {
156
+ return arc({ endAngle: interpolate(t) });
157
+ }
158
+ catch (error) {
159
+ logError(fileName, "drawProgressChart.attrTween.inner", error);
160
+ return "";
161
+ }
162
+ };
163
+ }
164
+ catch (error) {
165
+ logError(fileName, "drawProgressChart.attrTween", error);
166
+ return () => "";
167
+ }
168
+ });
169
+ // Add text to display progress value
170
+ chartAreaTagG
171
+ .append("text")
172
+ .attr("transform", getTransformString())
173
+ .attr("dy", "0.35em")
174
+ .attr("text-anchor", "middle")
175
+ .attr("visibility", chartFormatOptions.plotArea.dataLabels ? "visible" : "hidden")
176
+ .attr("fill", chartFormatOptions.plotArea.dataLabelValueColor !== "#ffffff"
177
+ ? chartFormatOptions.plotArea.dataLabelValueColor
178
+ : "none")
179
+ .attr("font-style", valuefontStyle.includes(fontStyleOptions.italic)
180
+ ? fontStyleOptions.italic
181
+ : "")
182
+ .attr("text-decoration", valuefontStyle.includes(fontStyleOptions.underline)
183
+ ? fontStyleOptions.underline
184
+ : "")
185
+ .attr("font-weight", valuefontStyle.includes(fontStyleOptions.bold)
186
+ ? fontStyleOptions.bold
187
+ : "")
188
+ .attr("font-family", chartFormatOptions.plotArea.dataLabelValueFontFamily)
189
+ .attr("font-size", chartFormatOptions.plotArea.dataLabelValueFontSize)
190
+ .text(() => {
191
+ return chartFormatOptions.plotArea.dataLabelNumberFormatProgress ==
192
+ ",.0%"
193
+ ? Math.round((progressValue / maxValue) * 100) + "%"
194
+ : getNumberWithFormatFunction(chartFormatOptions.plotArea.dataLabelDecimalPrecision, chartFormatOptions.plotArea.dataLabelNumberFormatProgress, chartFormatOptions.plotArea.plotAreaDisplayUnits)(progressValue);
195
+ });
196
+ }
197
+ catch (error) {
198
+ logError(fileName, "drawProgressChart", error);
199
+ }
200
+ };
201
+ const getTransformString = () => {
202
+ try {
203
+ return "translate(" + innerWidth / 2 + "," + innerHeight / 2 + ")";
204
+ }
205
+ catch (error) {
206
+ logError(fileName, "getTransformString", error);
207
+ return "";
208
+ }
209
+ };
210
+ 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%" } })] }));
211
+ };
212
+ export default ProgressChart;
@@ -0,0 +1,3 @@
1
+ import { IChartProps } from "../ChartsWithoutAxisTypes.types";
2
+ declare const PyramidChart: React.FC<IChartProps>;
3
+ export default PyramidChart;
@@ -0,0 +1,401 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import * as d3 from "d3";
3
+ import * as d3Annotation from "d3-svg-annotation";
4
+ import { useEffect, useRef } from "react";
5
+ import { AnnotationTypeMap, ConnectedStyle, ConnecterCurve, dataLabelPositionType, fontStyleOptions, staticDataLabelPositions, } from "../../Core/Common.types";
6
+ import { calculateLegendsMaxPossibleWidth, convertStringToNumber, drawChartTitle, firstFunctionBeforeRender, generalizedChartData, getNumberWithFormatFunction, hideTooltipOnMouseOut, initLegendListWithTotalValueAllowance, initSvg, marginCalculationsForChartsWithoutAxis, showTooltipOnMouseMove, } from "../../Core/CommonFunctions";
7
+ import { chartMargins } from "../../Core/DefaultProperties.types";
8
+ import { logError } from "../../../../Services/ErrorLog";
9
+ const fileName = "PyramidChart.tsx";
10
+ const PyramidChart = ({ data, formatOptions, chartId, }) => {
11
+ const svgRef = useRef();
12
+ const seriesData = generalizedChartData(data);
13
+ let chartFormatOptions;
14
+ let svg;
15
+ let width;
16
+ let height;
17
+ let chartTitleHeight = 40;
18
+ let margins = chartMargins;
19
+ let maxLegendDimensions = [0, 0];
20
+ let innerHeight;
21
+ let innerWidth;
22
+ let pyramidSide;
23
+ let pyramidHeight;
24
+ let stackHeightArray = [0];
25
+ let chartAreaTagG;
26
+ let pyramidTotalValue;
27
+ let legendListWidth;
28
+ let annotationsList;
29
+ useEffect(() => {
30
+ drawChart();
31
+ }, [formatOptions]);
32
+ const drawChart = () => {
33
+ ({ chartFormatOptions, svg, width, height } = firstFunctionBeforeRender(svgRef, formatOptions));
34
+ maxLegendDimensions = calculateLegendsMaxPossibleWidth(chartFormatOptions, seriesData);
35
+ ({ margins, innerHeight, innerWidth, legendListWidth, chartTitleHeight } =
36
+ marginCalculationsForChartsWithoutAxis(chartFormatOptions, width, height, maxLegendDimensions, margins));
37
+ initPyramidSideCalculations();
38
+ initSvg(svgRef, width, height, chartFormatOptions);
39
+ chartAreaTagG = initChartArea();
40
+ drawChartTitle(svgRef, chartTitleHeight, width, chartFormatOptions);
41
+ initLegendListWithTotalValueAllowance(chartFormatOptions, svg, seriesData, width, height, legendListWidth, chartTitleHeight, chartId, margins, false);
42
+ initPyramidData();
43
+ drawPyramidChart();
44
+ prepareNewAnnotationsList();
45
+ pyramidAnnotations([]);
46
+ };
47
+ const initPyramidSideCalculations = () => {
48
+ try {
49
+ pyramidSide = Math.min(innerHeight, innerWidth);
50
+ pyramidHeight = 0.866 * pyramidSide;
51
+ }
52
+ catch (error) {
53
+ logError(fileName, "initPyramidSideCalculations", error);
54
+ }
55
+ };
56
+ const initChartArea = () => {
57
+ try {
58
+ return svg
59
+ .append("g")
60
+ .attr("transform", `translate(${margins.left},${margins.top + (innerHeight - pyramidHeight) / 2})`);
61
+ }
62
+ catch (error) {
63
+ logError(fileName, "initChartArea", error);
64
+ return null;
65
+ }
66
+ };
67
+ const initPyramidData = () => {
68
+ try {
69
+ data = data.sort((a, b) => {
70
+ const firstValue = a.data[0].value;
71
+ const secondValue = b.data[0].value;
72
+ return !chartFormatOptions.plotArea.flipPyramid
73
+ ? firstValue - secondValue
74
+ : secondValue - firstValue;
75
+ });
76
+ pyramidTotalValue = d3.sum(data, (d) => Math.abs(d.data[0].value));
77
+ stackHeightArray = [0];
78
+ data.forEach((d, i) => {
79
+ const height = (Math.abs(d.data[0].value) / pyramidTotalValue) * pyramidHeight;
80
+ stackHeightArray.push(stackHeightArray[i] + height);
81
+ });
82
+ }
83
+ catch (error) {
84
+ logError(fileName, "initPyramidData", error);
85
+ }
86
+ };
87
+ const drawPyramidChart = () => {
88
+ try {
89
+ data.forEach((d, i) => {
90
+ try {
91
+ const yTop = stackHeightArray[i];
92
+ const yBottom = stackHeightArray[i + 1];
93
+ let inversionConstant = chartFormatOptions.plotArea.flipPyramid
94
+ ? 1
95
+ : 0;
96
+ const topWidth = pyramidSide *
97
+ (inversionConstant - stackHeightArray[i] / pyramidHeight);
98
+ const bottomWidth = pyramidSide *
99
+ (inversionConstant - stackHeightArray[i + 1] / pyramidHeight);
100
+ const centerX = innerWidth / 2;
101
+ const pyramidContainer = chartAreaTagG
102
+ .append("g")
103
+ .attr("id", "PyramidChart")
104
+ .attr("class", "parentGroup");
105
+ pyramidContainer
106
+ .append("polygon")
107
+ .attr("class", "segment")
108
+ .attr("hoverId", d.legend)
109
+ .attr("points", `
110
+ ${centerX - topWidth / 2},${yTop}
111
+ ${centerX + topWidth / 2},${yTop}
112
+ ${centerX + bottomWidth / 2},${yBottom}
113
+ ${centerX - bottomWidth / 2},${yBottom}
114
+ `)
115
+ .attr("fill", d.properties.color || "#4cb2ff")
116
+ .on("mousemove", function () {
117
+ try {
118
+ showTooltipOnMouseMove([
119
+ {
120
+ key: d.legend,
121
+ value: chartFormatOptions.toolTip.toolTipNumberFormat == ",.0%"
122
+ ? d.data[0].value
123
+ ? (Math.abs(d.data[0].value / pyramidTotalValue) *
124
+ 100).toFixed(convertStringToNumber(chartFormatOptions.toolTip
125
+ .toolTipDecimalPrecision)) + "%"
126
+ : ""
127
+ : getNumberWithFormatFunction("None", chartFormatOptions.toolTip.toolTipNumberFormat, chartFormatOptions.toolTip.toolTipDecimalPrecision)(d.data[0].value),
128
+ },
129
+ ], chartFormatOptions);
130
+ d3.select(this)
131
+ .style("opacity", 0.8)
132
+ .style("stroke", chartFormatOptions.chartArea.chartAreaColor)
133
+ .style("stroke-width", "3px");
134
+ }
135
+ catch (error) {
136
+ logError(fileName, "drawPyramidChart.onMouseMove", error);
137
+ }
138
+ })
139
+ .on("mouseout", function () {
140
+ try {
141
+ hideTooltipOnMouseOut();
142
+ d3.select(this)
143
+ .style("opacity", 1)
144
+ .style("stroke", "unset")
145
+ .style("stroke-width", "unset");
146
+ }
147
+ catch (error) {
148
+ logError(fileName, "drawPyramidChart.onMouseOut", error);
149
+ }
150
+ });
151
+ }
152
+ catch (error) {
153
+ logError(fileName, "drawPyramidChart.forEach", error);
154
+ }
155
+ });
156
+ }
157
+ catch (error) {
158
+ logError(fileName, "drawPyramidChart", error);
159
+ }
160
+ };
161
+ // Already has try/catch, just add logError in catch
162
+ const pyramidAnnotations = (oldAnnotationList) => {
163
+ try {
164
+ const self = this;
165
+ let AnnotationType = chartFormatOptions.annotation.annotationType ?? "1";
166
+ if (chartFormatOptions.annotation.annotationVisibility) {
167
+ let Disable = [AnnotationType == "1" ? "connector" : ""];
168
+ let makeAnnotations = d3Annotation.annotation();
169
+ let ConnectorType = chartFormatOptions.annotation.connectorType
170
+ ? chartFormatOptions.annotation.connectorType.toLowerCase()
171
+ : "None";
172
+ let AnnotationsList = annotationsList;
173
+ let finalAnnotationList = annotationsList;
174
+ makeAnnotations
175
+ .editMode(chartFormatOptions.annotation.annotationDraggable)
176
+ .accessors({
177
+ x: function () {
178
+ return innerWidth * 0.5;
179
+ },
180
+ y: function (d, i) {
181
+ return d.y;
182
+ },
183
+ })
184
+ .on("dragend", function (annotation) {
185
+ try {
186
+ annotations
187
+ .selectAll(".connector")
188
+ .attr("hoverId", (d) => d.data.legend)
189
+ .style("stroke", chartFormatOptions.annotation.connectorColor || "#ccc")
190
+ .attr("stroke-dasharray", ConnectedStyle[chartFormatOptions.annotation.connectorStyle]);
191
+ annotations
192
+ .selectAll(`.connector-${ConnectorType}`)
193
+ .attr("fill", chartFormatOptions.annotation.connectorColor || "#ccc")
194
+ .style("stroke", chartFormatOptions.annotation.connectorColor || "#ccc");
195
+ annotations
196
+ .selectAll(".note-line")
197
+ .attr("hoverId", (d) => d.data.currentLegend)
198
+ .style("stroke", chartFormatOptions.annotation.connectorColor || "#ccc")
199
+ .attr("stroke-dasharray", ConnectedStyle[chartFormatOptions.annotation.connectorStyle])
200
+ .filter((d) => d._dx == 0 && d._dy == 0)
201
+ .remove();
202
+ annotations
203
+ .selectAll(".annotation-note-label")
204
+ .filter((d) => d.data && d.data.isVisible)
205
+ .style("display", "block");
206
+ annotations
207
+ .selectAll(".annotation-note-title")
208
+ .filter((d) => d.data && d.data.isVisible)
209
+ .style("display", "block");
210
+ }
211
+ catch (error) {
212
+ logError(fileName, "pyramidAnnotations.onDragEnd", error);
213
+ }
214
+ })
215
+ .notePadding(0)
216
+ .annotations(finalAnnotationList);
217
+ let annotations = chartAreaTagG
218
+ .append("g")
219
+ .attr("class", "annotation-group parentGroup")
220
+ .call(makeAnnotations);
221
+ annotations.selectAll("rect").style("visibility", "hidden");
222
+ annotations.selectAll(".annotation-subject").remove();
223
+ annotations
224
+ .selectAll(".connector")
225
+ .style("stroke", chartFormatOptions.annotation.connectorColor || "#ccc")
226
+ .attr("stroke-dasharray", ConnectedStyle[chartFormatOptions.annotation.connectorStyle]);
227
+ annotations
228
+ .selectAll(`.connector-${ConnectorType}`)
229
+ .attr("fill", chartFormatOptions.annotation.connectorColor || "#ccc")
230
+ .style("stroke", chartFormatOptions.annotation.connectorColor || "#ccc");
231
+ annotations
232
+ .selectAll(".note-line")
233
+ .style("stroke", chartFormatOptions.annotation.connectorColor || "#ccc")
234
+ .attr("stroke-dasharray", ConnectedStyle[chartFormatOptions.annotation.connectorStyle])
235
+ .filter((d) => d._dx == 0 && d._dy == 0)
236
+ .remove();
237
+ annotations
238
+ .selectAll(".connector-end")
239
+ .filter((d) => d.connector.end == "dot" && d._dx == 0 && d._dy == 0)
240
+ .remove();
241
+ annotations
242
+ .selectAll(".annotation-note-label")
243
+ .filter((d) => d.data && !d.data.isVisible)
244
+ .style("display", "none");
245
+ annotations
246
+ .selectAll(".annotation-note-title")
247
+ .filter((d) => d.data && !d.data.isVisible)
248
+ .style("display", "none");
249
+ chartFormatOptions.annotation.annotationType ==
250
+ dataLabelPositionType.automatic &&
251
+ annotations
252
+ .selectAll(".annotation-note-content")
253
+ .attr("transform", function () {
254
+ const transform = d3.select(this).attr("transform");
255
+ const translateValues = transform.match(/translate\(([^,]+),([^,]+)\)/);
256
+ if (translateValues) {
257
+ const currentX = parseFloat(translateValues[1]);
258
+ return `translate(${currentX}, 0)`;
259
+ }
260
+ });
261
+ annotations
262
+ .selectAll(".annotation-note-label")
263
+ .attr("y", "15")
264
+ .attr("text-anchor", "middle");
265
+ annotations
266
+ .selectAll(".annotation-note-title")
267
+ .attr("text-anchor", "middle");
268
+ annotations
269
+ .selectAll(".annotation-note-content")
270
+ .attr("transform", `translate(0,-28)`);
271
+ !chartFormatOptions.plotArea.dataLabelName &&
272
+ annotations.selectAll("tspan").attr("dy", "0");
273
+ chartFormatOptions.plotArea.dataLabelName &&
274
+ annotations
275
+ .selectAll(".annotation-note-title")
276
+ .attr("hoverId", (d) => d.data.legend)
277
+ .style("font-size", (d) => d.data.labelFontSize)
278
+ .attr("font-family", (d) => d.data.labelFontFamily)
279
+ .style("font-style", (d) => d.data.labelFontStyle.includes(fontStyleOptions.italic)
280
+ ? fontStyleOptions.italic
281
+ : "")
282
+ .style("text-decoration", (d) => d.data.labelFontStyle.includes(fontStyleOptions.underline)
283
+ ? fontStyleOptions.underline
284
+ : "")
285
+ .style("font-weight", (d) => d.data.labelFontStyle.includes(fontStyleOptions.bold)
286
+ ? fontStyleOptions.bold
287
+ : "300")
288
+ .style("fill", (d) => d.data.labelFontColor);
289
+ chartFormatOptions.plotArea.dataLabelValue &&
290
+ annotations
291
+ .selectAll(".annotation-note-label")
292
+ .attr("hoverId", (d) => d.data.legend)
293
+ .style("font-size", (d) => d.data.valueFontSize)
294
+ .attr("font-family", (d) => d.data.valueFontFamily)
295
+ .style("font-style", (d) => d.data.valueFontStyle.includes(fontStyleOptions.italic)
296
+ ? fontStyleOptions.italic
297
+ : "")
298
+ .style("text-decoration", (d) => d.data.valueFontStyle.includes(fontStyleOptions.underline)
299
+ ? fontStyleOptions.underline
300
+ : "")
301
+ .style("font-weight", (d) => d.data.valueFontStyle.includes(fontStyleOptions.bold)
302
+ ? fontStyleOptions.bold
303
+ : "300")
304
+ .style("fill", (d) => d.data.valueFontColor);
305
+ }
306
+ }
307
+ catch (e) {
308
+ logError(fileName, "pyramidAnnotations", e);
309
+ }
310
+ };
311
+ const prepareNewAnnotationsList = () => {
312
+ try {
313
+ let annotationType = chartFormatOptions.annotation.annotationType ?? "1";
314
+ let connectorType = chartFormatOptions.annotation.connectorType
315
+ ? chartFormatOptions.annotation.connectorType.toLowerCase()
316
+ : "none";
317
+ annotationsList = [];
318
+ data.forEach((d, i) => {
319
+ try {
320
+ let singleAnnotation = {
321
+ note: {
322
+ title: chartFormatOptions.plotArea.dataLabelName
323
+ ? d.properties.alias
324
+ : "",
325
+ label: chartFormatOptions.plotArea.dataLabelNumberFormat == ",.0%"
326
+ ? (Math.abs(d.data[0].value / pyramidTotalValue) * 100).toFixed(convertStringToNumber(chartFormatOptions.plotArea.dataLabelDecimalPrecision)) + "%"
327
+ : chartFormatOptions.plotArea.dataLabelValue
328
+ ? d.data[0].value >= 1000000000 &&
329
+ chartFormatOptions.annotation.annotationNumberFormat ===
330
+ ".2s"
331
+ ? Math.round(d.data[0].value / 1000000000) + "B"
332
+ : getNumberWithFormatFunction(chartFormatOptions.annotation.annotationDisplayUnits, chartFormatOptions.plotArea.dataLabelNumberFormat, chartFormatOptions.plotArea.dataLabelDecimalPrecision)(d.data[0].value)
333
+ : "",
334
+ align: "middle",
335
+ },
336
+ data: {
337
+ x: innerWidth / 2,
338
+ y: getYCordinate(d, i, d.properties.dataLabelPosition),
339
+ isVisible: true,
340
+ dimension: d.legend,
341
+ legend: d.legend,
342
+ measure: d.data[0].value,
343
+ labelFontFamily: d.properties.labelFont,
344
+ labelFontSize: d.properties.labelFontSize,
345
+ labelFontColor: d.properties.labelFontColor,
346
+ labelFontStyle: d.properties.labelFontStyle,
347
+ valueFontFamily: d.properties.valueFont,
348
+ valueFontSize: d.properties.valueFontSize,
349
+ valueFontColor: d.properties.valueFontColor,
350
+ valueFontStyle: d.properties.valueFontStyle,
351
+ },
352
+ dx: 0,
353
+ dy: 0,
354
+ connector: {
355
+ end: connectorType,
356
+ curve: ConnecterCurve[chartFormatOptions.annotation.connectorCurve],
357
+ },
358
+ subject: {
359
+ height: 15,
360
+ width: 15,
361
+ },
362
+ type: AnnotationTypeMap[annotationType],
363
+ color: chartFormatOptions.plotArea.dataLabelNameColor != "#000000"
364
+ ? chartFormatOptions.plotArea.dataLabelNameColor
365
+ : "#000000",
366
+ height: width,
367
+ width: width,
368
+ index: i,
369
+ };
370
+ annotationsList.push(singleAnnotation);
371
+ }
372
+ catch (error) {
373
+ logError(fileName, "prepareNewAnnotationsList.forEach", error);
374
+ }
375
+ });
376
+ }
377
+ catch (error) {
378
+ logError(fileName, "prepareNewAnnotationsList", error);
379
+ }
380
+ };
381
+ const getYCordinate = (d, i, labelPosition) => {
382
+ try {
383
+ switch (labelPosition) {
384
+ case staticDataLabelPositions.top:
385
+ return stackHeightArray[i] + 30;
386
+ case staticDataLabelPositions.middle:
387
+ return (stackHeightArray[i] + stackHeightArray[i + 1]) / 2 + 15;
388
+ case staticDataLabelPositions.bottom:
389
+ return stackHeightArray[i + 1];
390
+ default:
391
+ return stackHeightArray[i] + 30;
392
+ }
393
+ }
394
+ catch (error) {
395
+ logError(fileName, "getYCordinate", error);
396
+ return 0;
397
+ }
398
+ };
399
+ 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%" } })] }));
400
+ };
401
+ export default PyramidChart;
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ import { IChartProps } from "../ChartsWithoutAxisTypes.types";
3
+ declare const RadialBarChart: React.FC<IChartProps>;
4
+ export default RadialBarChart;