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