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,512 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ //#region Imports
3
+ import * as d3 from "d3";
4
+ import * as d3Annotation from "d3-svg-annotation";
5
+ import { useEffect, useRef } from "react";
6
+ import { logError } from "../../../../Services/ErrorLog";
7
+ import { drawLegends, lineMarkers } from "../../Core/CommonFunctions";
8
+ import { addDataTable, dataTablePreCalculation, drawSeriesLabels, firstFunctionBeforeRender, getCurveType, getStackedData, initChartArea, initPlotArea, initSvg, initXaxis, initYaxis, marginCalculation, prepareDataForSeriesLabel, responsiveXaxisLabel, setChartTitle, setDateFormats, setXaxistitle, stacklineAnnotations, yAxistitle, yAxistitleRight, } from "../ChartsWithAxisFunctions";
9
+ import { actualChartTypes, } from "../ChartsWithAxisTypes.types";
10
+ const NormalisedStackLineChart = ({ title, width, height, data, yAxisObj, xAxisObj, chartId, formatOptions, }) => {
11
+ // adding variables as per requirement
12
+ const barWidth = 0; // coz line chart
13
+ const chartType = actualChartTypes.stackLine100;
14
+ const svgRef = useRef();
15
+ const seriesData = data;
16
+ const barChart = false;
17
+ const chartsWithXScrollFlag = true;
18
+ const chartsWithYScrollFlag = false;
19
+ const isSecondaryAxisDrawn = false;
20
+ let isPrimaryAxisDrawn = true;
21
+ let customYaxisMinValue = parseFloat(formatOptions.yAxisLabel.yAxisMinText);
22
+ let customYaxisMaxValue = parseFloat(formatOptions.yAxisLabel.yAxisMaxText);
23
+ let secondaryCustomYaxisMinValue = parseFloat(formatOptions.secondaryYAxisLabel.secondaryYAxisMinText);
24
+ let secondaryCustomYaxisMaxValue = parseFloat(formatOptions.secondaryYAxisLabel.secondaryYAxisMaxText);
25
+ let margin;
26
+ let yLabel;
27
+ let xLabel;
28
+ let yTitle;
29
+ let xTitle;
30
+ let dimensionHeightWidthArray;
31
+ let chartTitleHeight;
32
+ let secondaryAxisTitleWidth;
33
+ let legendMargin;
34
+ let secondaryYLabel;
35
+ let maxNumberForPrimaryAxis;
36
+ let maxNumberForSecondaryAxis;
37
+ let innerWidth;
38
+ let innerHeight;
39
+ let totalHeight;
40
+ let totalWidth;
41
+ let dataTable;
42
+ let dataTableHeight;
43
+ let svg;
44
+ let gTag;
45
+ let yScaleLeft;
46
+ let yScaleRight;
47
+ let xScale;
48
+ let seriesLabels;
49
+ let calculatedRange;
50
+ let seriesLabelWidth;
51
+ let yAxisLeft;
52
+ let xAxis;
53
+ let yAxisRight;
54
+ let filteredDimension;
55
+ let filteredData;
56
+ let scrollPosition = 0;
57
+ const visibleBars = 2;
58
+ let stackLineData = [];
59
+ let stackChartData = [];
60
+ const isNormalizedChart = true;
61
+ let chartJSON = {
62
+ dimensionList: [],
63
+ chartType: chartType,
64
+ chartData: [],
65
+ formatOptions: formatOptions,
66
+ legendList: [],
67
+ secondaryAxisDrawn: false,
68
+ yMaxLeft: 0,
69
+ yMaxRight: 0,
70
+ yMinLeft: 0,
71
+ yMinRight: 0,
72
+ hideZeroValues: false,
73
+ formattedDimensionListMap: new Map(),
74
+ };
75
+ //#region UseEffect
76
+ useEffect(() => {
77
+ try {
78
+ createLineChart();
79
+ }
80
+ catch (error) {
81
+ logError("NormalizedLinechart", "createLineChart", error);
82
+ }
83
+ }, []);
84
+ //#endregion
85
+ const createLineChart = () => {
86
+ ({ formatOptions, svg, width, height } = firstFunctionBeforeRender(svgRef, formatOptions));
87
+ preProcessChartData(); // preaparing data related to chart creation
88
+ // Applies custom Y-axis label formatting and calculates the necessary margin based on axis extremes.
89
+ // const resultCustomYscaleLabelFormatting = customYscaleLabelFormatting(
90
+ // // for calculating primary/secondary axis max number so that we can calculate margin accordinglt
91
+ // formatOptions,
92
+ // chartJSON.yMinLeft,
93
+ // chartJSON.yMaxLeft,
94
+ // chartJSON.yMinRight,
95
+ // chartJSON.yMaxRight
96
+ // );
97
+ // maxNumberForPrimaryAxis =
98
+ // resultCustomYscaleLabelFormatting.maxNumberForPrimaryAxis;
99
+ // maxNumberForSecondaryAxis =
100
+ // resultCustomYscaleLabelFormatting.maxNumberForSecondaryAxis;
101
+ ({
102
+ margin,
103
+ yLabel,
104
+ xLabel,
105
+ yTitle,
106
+ xTitle,
107
+ dimensionHeightWidthArray,
108
+ chartTitleHeight,
109
+ secondaryAxisTitleWidth,
110
+ legendMargin,
111
+ secondaryYLabel,
112
+ } = marginCalculation(
113
+ // for all margin related calculations
114
+ width, height, maxNumberForPrimaryAxis, maxNumberForSecondaryAxis, chartJSON.yMaxLeft, formatOptions, chartJSON.legendList, chartJSON.dimensionList, chartJSON.yMaxRight, isSecondaryAxisDrawn, isNormalizedChart));
115
+ setSVGContainer(margin); // for innerWidth/height static width/height
116
+ ({ dataTable, dataTableHeight } = dataTablePreCalculation(
117
+ // calculations for data tables
118
+ formatOptions, yLabel, yTitle, seriesData, chartJSON.dimensionList));
119
+ initSvg(
120
+ // for svg creation
121
+ svg, width, height, formatOptions);
122
+ //d3.select(svgRef.current, width, height);
123
+ gTag = initChartArea(svg, margin); // creating chart area
124
+ initPlotArea(gTag, formatOptions, dataTableHeight, innerWidth, innerHeight, chartType);
125
+ initScale();
126
+ initAxis();
127
+ initYaxis(gTag, formatOptions, dataTableHeight, yLabel, yAxisLeft, innerHeight);
128
+ // initYaxisRight(
129
+ // gTag,
130
+ // formatOptions,
131
+ // dataTableHeight,
132
+ // secondaryYLabel,
133
+ // yAxisRight,
134
+ // innerHeight,
135
+ // innerWidth,
136
+ // floatingTagG
137
+ // );
138
+ horizontalScrollBar(seriesData, height, svg, margin, innerWidth);
139
+ if (formatOptions.dataTableProperties &&
140
+ formatOptions.dataTableProperties.dataTable) {
141
+ if (formatOptions.xAxisLabel.xAxisPosition != 1)
142
+ formatOptions.xAxisLabel.xAxisLabelVisibility = false;
143
+ addDataTable(formatOptions.plotArea.fitChart, svg, gTag, dataTable, barWidth, yScaleLeft, xScale, undefined, undefined, undefined, dataTableHeight, "Line", formatOptions, yLabel, yTitle, chartJSON.dimensionList, innerWidth, calculatedRange, chartJSON.formattedDimensionListMap, chartId, margin, innerHeight);
144
+ }
145
+ setXaxistitle(formatOptions, barChart, svg, margin, xLabel, height, xTitle, chartJSON.chartType, yLabel, innerWidth, innerHeight);
146
+ yAxistitle(innerHeight, formatOptions, dataTableHeight, barChart, svg, margin, yTitle, yLabel);
147
+ yAxistitleRight(svg, isSecondaryAxisDrawn, margin, formatOptions, dataTableHeight, innerHeight, innerWidth, secondaryYLabel, secondaryAxisTitleWidth); // to be added later
148
+ setChartTitle(svg, formatOptions, width, chartTitleHeight);
149
+ drawLegends(height, svg, dimensionHeightWidthArray, chartTitleHeight, width, legendMargin, formatOptions, seriesData, chartId);
150
+ };
151
+ const preProcessChartData = () => {
152
+ const allChartData = [];
153
+ const dimensionSet = new Set();
154
+ const legendList = [];
155
+ seriesData.forEach((series, index) => {
156
+ // Prefix the legend
157
+ const prefixedLegend = `${index}~$~${series.properties.legend}`;
158
+ series.properties.legend = prefixedLegend;
159
+ legendList.push(prefixedLegend);
160
+ // Flatten data and collect unique dimensions
161
+ for (const point of series.data) {
162
+ allChartData.push(point);
163
+ dimensionSet.add(point.dimension);
164
+ }
165
+ });
166
+ // Assign the flattened and deduplicated results
167
+ chartJSON.chartData = allChartData;
168
+ chartJSON.dimensionList = Array.from(dimensionSet);
169
+ chartJSON.legendList = legendList;
170
+ // Deep clone the updated seriesData
171
+ filteredData = JSON.parse(JSON.stringify(seriesData));
172
+ // Optional scroll logic (currently disabled)
173
+ if (false /* or formatOptions.scrollChart.scrollX */) {
174
+ filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
175
+ filteredData.forEach((series) => {
176
+ series.data = series.data.filter((d) => filteredDimension.includes(d.dimension));
177
+ });
178
+ }
179
+ else {
180
+ filteredDimension = chartJSON.dimensionList;
181
+ }
182
+ // Optional zero hiding flag
183
+ if (formatOptions.plotArea.hideZeroValues) {
184
+ chartJSON.hideZeroValues = true;
185
+ }
186
+ // Prepare stacked data
187
+ const tempStackLineData = getStackedData(chartJSON.dimensionList, seriesData, isNormalizedChart);
188
+ const allStackDataChart = d3
189
+ .stack()
190
+ .keys(chartJSON.legendList)
191
+ .offset(d3.stackOffsetDiverging)(tempStackLineData);
192
+ createStackLineData();
193
+ // Get min value from stack (you manually set yMaxLeft = 1)
194
+ let yMinLeft = Infinity;
195
+ for (const series of allStackDataChart) {
196
+ for (const [start] of series) {
197
+ yMinLeft = Math.min(yMinLeft, start);
198
+ }
199
+ }
200
+ chartJSON.yMinLeft = yMinLeft;
201
+ chartJSON.yMaxLeft = 1; // as per your original override
202
+ // Format dimensions
203
+ const xAxisObject = xAxisObj[0];
204
+ const formatedDimesionList = (xAxisObject.groupBy === "NA" || xAxisObject.groupBy === undefined) &&
205
+ xAxisObject.dataType === "DATE"
206
+ ? setDateFormats(formatOptions.xAxisLabel.xAxisNumberFormat, chartJSON.dimensionList).map((d) => d[0])
207
+ : chartJSON.dimensionList;
208
+ // Assign formatted dimension list map (cleanest one-liner)
209
+ chartJSON.formattedDimensionListMap = new Map(chartJSON.dimensionList.map((d, i) => [d, formatedDimesionList[i]]));
210
+ // let secondaryAxisMinValue = 0;
211
+ // let secondaryAxisMaxValue = 0;
212
+ // if (isSecondaryAxisDrawn) {
213
+ // seriesData?.forEach((data) => {
214
+ // if (data.properties.axis == "Secondary") {
215
+ // // isSecondaryAxisDrawn = true;
216
+ // if (
217
+ // secondaryAxisMinValue >
218
+ // d3.min(data.data, (d: TDataPoint) => d.value)
219
+ // ) {
220
+ // secondaryAxisMinValue = d3.min(
221
+ // data.data,
222
+ // (d: TDataPoint) => d.value
223
+ // );
224
+ // }
225
+ // if (
226
+ // secondaryAxisMaxValue <
227
+ // d3.max(data.data, (d: TDataPoint) => d.value)
228
+ // ) {
229
+ // secondaryAxisMaxValue = d3.max(
230
+ // data.data,
231
+ // (d: TDataPoint) => d.value
232
+ // );
233
+ // }
234
+ // }
235
+ // });
236
+ // chartJSON.yMinRight = secondaryAxisMinValue;
237
+ // chartJSON.yMaxRight = secondaryAxisMaxValue;
238
+ // }
239
+ };
240
+ const initScale = () => {
241
+ if (isPrimaryAxisDrawn) {
242
+ yScaleLeft = d3
243
+ .scaleLinear()
244
+ .domain([chartJSON.yMinLeft < 0 ? -1 : 0, 1])
245
+ .range([
246
+ dataTableHeight > 0 ? innerHeight - dataTableHeight : innerHeight,
247
+ 0,
248
+ ]);
249
+ }
250
+ if (isSecondaryAxisDrawn) {
251
+ yScaleRight = d3
252
+ .scaleLinear()
253
+ .domain([
254
+ chartJSON.yMinRight >= 0
255
+ ? (secondaryCustomYaxisMinValue ||
256
+ secondaryCustomYaxisMinValue == 0) &&
257
+ !Number.isNaN(secondaryCustomYaxisMinValue)
258
+ ? secondaryCustomYaxisMinValue
259
+ : 0
260
+ : (secondaryCustomYaxisMinValue ||
261
+ secondaryCustomYaxisMinValue == 0) &&
262
+ !Number.isNaN(secondaryCustomYaxisMinValue)
263
+ ? secondaryCustomYaxisMinValue
264
+ : chartJSON.yMinRight * 1.1,
265
+ chartJSON.yMaxRight <= 0
266
+ ? secondaryCustomYaxisMaxValue
267
+ ? secondaryCustomYaxisMaxValue
268
+ : 0
269
+ : secondaryCustomYaxisMaxValue
270
+ ? secondaryCustomYaxisMaxValue
271
+ : chartJSON.yMaxRight * 1.1,
272
+ ])
273
+ .range([
274
+ dataTableHeight > 0 ? innerHeight - dataTableHeight : innerHeight,
275
+ 0,
276
+ ]);
277
+ }
278
+ calculatedRange = [0, innerWidth];
279
+ if (formatOptions.seriesLabel.seriesLabelVisibility) {
280
+ let labelObj = prepareDataForSeriesLabel(innerWidth, yScaleLeft, formatOptions, filteredData, undefined, isSecondaryAxisDrawn, true);
281
+ seriesLabels = labelObj.labelArray;
282
+ formatOptions.seriesLabel.seriesLabelPosition == "Right" &&
283
+ (seriesLabelWidth = labelObj.heightWidth[0]);
284
+ formatOptions.seriesLabel.seriesLabelPosition == "Right"
285
+ ? (calculatedRange = [0, innerWidth - labelObj.heightWidth[0]])
286
+ : (calculatedRange = [labelObj.heightWidth[0], innerWidth]);
287
+ }
288
+ getXScale();
289
+ };
290
+ const getXScale = () => {
291
+ xScale = d3
292
+ .scalePoint()
293
+ .domain(filteredDimension)
294
+ .range(calculatedRange)
295
+ .padding(0.5);
296
+ };
297
+ const initAxis = () => {
298
+ getXAxis();
299
+ if (isPrimaryAxisDrawn) {
300
+ yAxisLeft = d3
301
+ .axisLeft(yScaleLeft)
302
+ // .tickFormat((d: number) => //tick format will be always % line 544 with 0 precision
303
+ // getNumberWithFormat(
304
+ // d,
305
+ // formatOptions.yAxisLabel.yAxisDisplayUnits,
306
+ // formatOptions.yAxisLabel.yAxisNumberFormat,
307
+ // formatOptions.yAxisLabel.yAxisLabelDecimalPrecision
308
+ // )
309
+ // )
310
+ .tickSize(formatOptions.plotArea.gridLinesVisibility
311
+ ? formatOptions.plotArea.gridLinesHorizontal
312
+ ? -innerWidth + (seriesLabelWidth ? seriesLabelWidth : 0)
313
+ : 0
314
+ : 0)
315
+ .ticks(dataTableHeight > 0
316
+ ? (innerHeight - dataTableHeight) / 30
317
+ : innerHeight / 30, "%")
318
+ .tickSizeOuter(0);
319
+ }
320
+ };
321
+ const getXAxis = () => {
322
+ xAxis = d3
323
+ .axisBottom(xScale)
324
+ .tickSize(formatOptions.plotArea.gridLinesVisibility
325
+ ? formatOptions.plotArea.gridLinesVeritcal
326
+ ? formatOptions.plotArea.gridLinesVeritcal
327
+ ? -(dataTableHeight > 0
328
+ ? innerHeight - dataTableHeight
329
+ : innerHeight)
330
+ : formatOptions.plotArea.ticksHeight *
331
+ ((dataTableHeight > 0
332
+ ? innerHeight - dataTableHeight
333
+ : innerHeight) /
334
+ 100) *
335
+ (formatOptions.xAxisLabel.xAxisPosition == 1 ? 1 : -1)
336
+ : 0
337
+ : 0)
338
+ .tickSizeOuter(0)
339
+ .tickValues(responsiveXaxisLabel(filteredDimension, innerWidth));
340
+ };
341
+ const getChartType = (lineData) => {
342
+ stackChartData.forEach((data, i) => data.forEach((item, position) => {
343
+ lineData[i].data[position][0] = item[0] =
344
+ item.data.Total === 0 ? 0 : item[0] / item.data.Total;
345
+ lineData[i].data[position][1] = item[1] =
346
+ item.data.Total === 0 ? 0 : item[1] / item.data.Total;
347
+ }));
348
+ lineData.forEach((lData) => {
349
+ lData.data.forEach((cData) => {
350
+ cData.hideZero = lData.properties.hideZeroValues;
351
+ cData.axis = lData.properties.axis;
352
+ });
353
+ });
354
+ const lineGenerator = d3
355
+ .line()
356
+ .x((d) => xScale(d.data.dimension)
357
+ ? xScale(d.data.dimension)
358
+ : null)
359
+ .y((d) => (d[1] > 0 ? yScaleLeft(d[1]) : yScaleLeft(d[0])))
360
+ // .defined((d) => (d.hideZero ? Boolean(d.value) : true))
361
+ .curve(getCurveType(formatOptions));
362
+ //Lines
363
+ // Bind dummy data to ensure a single group is created
364
+ let lines = gTag.selectAll(".parentGroup").data([stackChartData]);
365
+ lines = lines
366
+ .enter()
367
+ .append("g")
368
+ .attr("class", "lines parentGroup")
369
+ .merge(lines);
370
+ // JOIN: one group per line
371
+ let lineGroups = lines.selectAll(".line-group").data((d) => d);
372
+ // ENTER: create group for each new line
373
+ let lineGroupsEnter = lineGroups
374
+ .enter()
375
+ .append("g")
376
+ .attr("class", (d) => "line-group " + d.key.replace(/ /g, "-"));
377
+ // .attr("class", (d) => d.key.replace(/ /g, "-"));
378
+ lineGroupsEnter
379
+ .attr("hoverId", (d) => d.key.includes("~$~")
380
+ ? d.key.split("~$~")[1].replace(/ /g, "-")
381
+ : d.key.replace(/ /g, "-"))
382
+ .append("path")
383
+ .attr("class", "line")
384
+ .attr("fill", "none");
385
+ // ENTER + UPDATE
386
+ lineGroupsEnter
387
+ .merge(lineGroups)
388
+ .select("path")
389
+ .attr("d", (d, i) => lineGenerator(d))
390
+ .attr("stroke", (d) => (d.color !== "#ffffff" ? d.color : "none"))
391
+ // .style("visibility", (d,i) => (this.individualLegendStyle[i].hideZero && d[i].data[d.key] === 0) ? "hidden" : "visible")
392
+ .attr("stroke-dasharray", (d, i) => seriesData[i].properties.lineStyle === "dotted"
393
+ ? "0,3"
394
+ : seriesData[i].properties.lineStyle === "dashed"
395
+ ? "20,10,5,5,5,10"
396
+ : "")
397
+ .attr("stroke-linecap", (d, i) => seriesData[i].properties.lineStyle === "dotted" ? "round" : "")
398
+ .attr("stroke-width", (d, i) => seriesData[i].properties.lineStyle !== "None"
399
+ ? seriesData[i].properties.lineWidth
400
+ : "0");
401
+ // EXIT: remove old groups
402
+ lineGroups.exit().remove();
403
+ //Markers
404
+ lineMarkers(lines, lineData, chartType, xScale, yScaleLeft, yScaleRight, null, formatOptions, chartJSON, secondaryCustomYaxisMaxValue, secondaryCustomYaxisMinValue, customYaxisMinValue, customYaxisMaxValue);
405
+ };
406
+ const setSVGContainer = (margin) => {
407
+ innerWidth = width - margin.left - margin.right;
408
+ innerHeight = height - margin.bottom - margin.top;
409
+ };
410
+ const horizontalScrollBar = (seriesData, height, svg, margin, innerWidth) => {
411
+ // if (formatOptions.scrollChart.scrollX) {
412
+ if (false) {
413
+ // Scrollbar parameters
414
+ const scrollMax = seriesData[0].data.length - visibleBars;
415
+ // Scrollbar track & handle
416
+ const scrollbarY = height - 20;
417
+ filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
418
+ getXScale();
419
+ filteredData = JSON.parse(JSON.stringify(seriesData));
420
+ filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
421
+ createStackLineData();
422
+ getXAxis();
423
+ svg
424
+ .append("rect")
425
+ .attr("x", margin.left)
426
+ .attr("y", scrollbarY)
427
+ .attr("width", innerWidth)
428
+ .attr("height", 8)
429
+ .attr("fill", "#ddd")
430
+ .attr("rx", 4);
431
+ const handleWidth = (innerWidth * visibleBars) / seriesData.length;
432
+ const handle = svg
433
+ .append("rect")
434
+ .attr("x", margin.left)
435
+ .attr("y", scrollbarY)
436
+ .attr("width", handleWidth)
437
+ .attr("height", 8)
438
+ .attr("fill", "#999")
439
+ .attr("rx", 4)
440
+ .style("cursor", "ew-resize")
441
+ .call(d3.drag().on("drag", (event) => {
442
+ let x = Math.min(Math.max(event.x, margin.left), margin.left + innerWidth - handleWidth);
443
+ handle.attr("x", x);
444
+ scrollPosition = Math.round(((x - margin.left) / (innerWidth - handleWidth)) * scrollMax);
445
+ filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
446
+ getXScale();
447
+ filteredData = JSON.parse(JSON.stringify(seriesData));
448
+ filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
449
+ createStackLineData();
450
+ getXAxis();
451
+ drawLineChart();
452
+ }));
453
+ svg.on("wheel", (event) => {
454
+ event.preventDefault();
455
+ const scrollDelta = Math.abs(event.deltaX) > Math.abs(event.deltaY)
456
+ ? event.deltaX
457
+ : event.deltaY;
458
+ scrollPosition += scrollDelta > 0 ? 1 : -1;
459
+ scrollPosition = Math.max(0, Math.min(scrollPosition, scrollMax));
460
+ const x = margin.left +
461
+ ((innerWidth - handleWidth) * scrollPosition) / scrollMax;
462
+ handle.attr("x", x);
463
+ getXScale();
464
+ filteredData = JSON.parse(JSON.stringify(seriesData));
465
+ filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
466
+ createStackLineData();
467
+ getXAxis();
468
+ drawLineChart();
469
+ });
470
+ }
471
+ drawLineChart();
472
+ };
473
+ const drawLineChart = () => {
474
+ // filteredData.forEach((data) => getChartType([data]));
475
+ getChartType(filteredData);
476
+ initXaxis(gTag, chartJSON, xLabel, formatOptions, xAxisObj[0], dataTableHeight, yScaleLeft, xAxis, dimensionHeightWidthArray, height, barWidth, xAxisObj[0].dataType, innerWidth, innerHeight, filteredDimension);
477
+ stacklineAnnotations(stackChartData, xScale, yScaleLeft, yScaleRight, // need to pass secondary axis scale if secondary axis is drawn
478
+ margin, d3Annotation, [], //this.labelExcludeList,
479
+ [], //this.individualLabelColor,
480
+ [], //this.attributes.Id ? formatOptions.plotArea.dataLabelsCoordinates : this.parentReference.objService.tempAnnotationArray
481
+ formatOptions, chartType, height, width, innerWidth, filteredDimension, innerHeight, chartId, svg, dataTableHeight);
482
+ let newSeriesLabelArray = prepareDataForSeriesLabel(innerWidth, yScaleLeft, formatOptions, filteredData, undefined, isSecondaryAxisDrawn, true).labelArray;
483
+ // adding series labels ( appending legends at the end of line : by default) in plot area
484
+ drawSeriesLabels(formatOptions, gTag, newSeriesLabelArray);
485
+ };
486
+ const createStackLineData = () => {
487
+ let stackLineData = getStackedData(filteredDimension, filteredData, isNormalizedChart);
488
+ // }
489
+ stackChartData = d3
490
+ .stack()
491
+ .keys(chartJSON.legendList)
492
+ .offset(d3.stackOffsetDiverging)(stackLineData);
493
+ filteredData.forEach((data, index) => data.data.forEach((axisData, position) => {
494
+ axisData["0"] = stackChartData[index][position][0];
495
+ axisData["1"] = stackChartData[index][position][1];
496
+ }));
497
+ //Appending Extra key for tooltip color
498
+ let seriesColor = formatOptions.annotation.annotationSetLabelColor;
499
+ stackChartData.forEach((K, j) => K.forEach((d) => {
500
+ d["key"] = K.key;
501
+ K["color"] = JSON.parse(JSON.stringify(seriesData[j].properties.color));
502
+ d.data.labelPosition = seriesData[j].properties.dataLabelPosition;
503
+ d.data["labelColor"] =
504
+ seriesColor == 2
505
+ ? JSON.parse(JSON.stringify(seriesData[j].properties.color))
506
+ : seriesData[j].properties.labelColor;
507
+ d["hideZero"] = JSON.parse(JSON.stringify(seriesData[j].properties.hideZeroValues));
508
+ }));
509
+ };
510
+ return (_jsxs("div", { children: [_jsx("div", { id: "chartTooltipDiv" }), _jsx("svg", { className: "chartSVG", ref: svgRef, id: chartId, width: width, height: height })] }));
511
+ };
512
+ export default NormalisedStackLineChart;
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ import { type TChartProps } from "../ChartsWithAxisTypes.types";
3
+ declare const StackColumnChart: React.FC<TChartProps>;
4
+ export default StackColumnChart;