pace-chart-lib 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/dist/{components → Components}/Charts/ChartsWithAxis/ChartsWithAxisFunctions.d.ts +76 -38
  2. package/dist/{components → Components}/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.types.d.ts +4 -2
  3. package/dist/{components → Components}/Charts/Core/CommonFunctions.d.ts +3 -1
  4. package/dist/{components → Components}/Charts/Core/DefaultProperties.types.d.ts +2 -0
  5. package/dist/index.d.ts +1 -0
  6. package/dist/pace-chart-lib.es.js +54619 -0
  7. package/dist/pace-chart-lib.umd.js +54622 -0
  8. package/dist/vite.svg +1 -0
  9. package/package.json +1 -1
  10. package/dist/Services/ErrorLog.js +0 -3
  11. package/dist/components/Charts/ChartsWithAxis/AreaFamily/AreaChart.js +0 -496
  12. package/dist/components/Charts/ChartsWithAxis/AreaFamily/LineChart.d.ts +0 -4
  13. package/dist/components/Charts/ChartsWithAxis/AreaFamily/LineChart.js +0 -491
  14. package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackAreaChart.js +0 -517
  15. package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackLineChart.d.ts +0 -4
  16. package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackLineChart.js +0 -553
  17. package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackAreaChart.js +0 -517
  18. package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackLineChart.d.ts +0 -4
  19. package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackLineChart.js +0 -553
  20. package/dist/components/Charts/ChartsWithAxis/BarFamily/BarChart.d.ts +0 -12
  21. package/dist/components/Charts/ChartsWithAxis/BarFamily/BarChart.js +0 -9
  22. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisFunctions.js +0 -4909
  23. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.d.ts +0 -0
  24. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.js +0 -0
  25. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.types.js +0 -49
  26. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart copy.d.ts +0 -4
  27. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart copy.js +0 -486
  28. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart.js +0 -497
  29. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnHistogramChart.js +0 -418
  30. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/CustomColumnChart.js +0 -1013
  31. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LayeredColumnChart.js +0 -478
  32. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LineChart.d.ts +0 -4
  33. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LineChart.js +0 -451
  34. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackColumnChart.js +0 -533
  35. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackLineChart.js +0 -512
  36. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackColumnChart.js +0 -530
  37. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackLineChart.js +0 -512
  38. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/BarChart.d.ts +0 -12
  39. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/BarChart.js +0 -9
  40. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalBarChart.js +0 -497
  41. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalHistogramChart.js +0 -497
  42. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredColumnChart.d.ts +0 -4
  43. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredColumnChart.js +0 -479
  44. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredHorizontalBarChart.js +0 -478
  45. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/NormalizedStackHorizontalBarChart.js +0 -473
  46. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/StackHorizontalBarChart.js +0 -465
  47. package/dist/components/Charts/ChartsWithAxis/LineFamily/100%StackLineChart.d.ts +0 -0
  48. package/dist/components/Charts/ChartsWithAxis/LineFamily/100%StackLineChart.js +0 -0
  49. package/dist/components/Charts/ChartsWithAxis/LineFamily/LineChart.js +0 -451
  50. package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalisedStackLineChart.d.ts +0 -4
  51. package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalisedStackLineChart.js +0 -554
  52. package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalizedStackLineChart.d.ts +0 -4
  53. package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalizedStackLineChart.js +0 -510
  54. package/dist/components/Charts/ChartsWithAxis/LineFamily/StackLineChart.d.ts +0 -4
  55. package/dist/components/Charts/ChartsWithAxis/LineFamily/StackLineChart.js +0 -507
  56. package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/TornadoChart.js +0 -393
  57. package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/WaterfallChart.js +0 -606
  58. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxis.types.d.ts +0 -0
  59. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxis.types.js +0 -0
  60. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.js +0 -815
  61. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.d.ts +0 -0
  62. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.js +0 -0
  63. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.types.js +0 -32
  64. package/dist/components/Charts/ChartsWithoutAxis/Maps/Cordinates.js +0 -15021
  65. package/dist/components/Charts/ChartsWithoutAxis/Maps/Maps.js +0 -391
  66. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/BubbleChart.js +0 -367
  67. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/OrganizationChart.js +0 -570
  68. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ProgressChart.js +0 -212
  69. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/PyramidChart.js +0 -401
  70. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/RadialBarChart.js +0 -313
  71. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/SankeyChart.js +0 -719
  72. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ScatterChart.js +0 -807
  73. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/Speedometer.js +0 -514
  74. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/VennChart.js +0 -282
  75. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/WordCloud.js +0 -207
  76. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/DonutChart.js +0 -476
  77. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieChart.js +0 -420
  78. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieFamilyCommonFunctions.js +0 -106
  79. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieofPieChart.js +0 -507
  80. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/TreemapChart.js +0 -246
  81. package/dist/components/Charts/Core/Common.type.d.ts +0 -0
  82. package/dist/components/Charts/Core/Common.type.js +0 -0
  83. package/dist/components/Charts/Core/Common.types.js +0 -133
  84. package/dist/components/Charts/Core/CommonFunctions.js +0 -1782
  85. package/dist/components/Charts/Core/DefaultChartDataProperties.js +0 -64
  86. package/dist/components/Charts/Core/DefaultProperties.d.ts +0 -0
  87. package/dist/components/Charts/Core/DefaultProperties.js +0 -0
  88. package/dist/components/Charts/Core/DefaultProperties.type.d.ts +0 -586
  89. package/dist/components/Charts/Core/DefaultProperties.type.js +0 -585
  90. package/dist/components/Charts/Core/DefaultProperties.types.js +0 -592
  91. package/dist/index.js +0 -40
  92. /package/dist/{components → Components}/Charts/ChartsWithAxis/AreaFamily/AreaChart.d.ts +0 -0
  93. /package/dist/{components → Components}/Charts/ChartsWithAxis/AreaFamily/NormalizedStackAreaChart.d.ts +0 -0
  94. /package/dist/{components → Components}/Charts/ChartsWithAxis/AreaFamily/StackAreaChart.d.ts +0 -0
  95. /package/dist/{components → Components}/Charts/ChartsWithAxis/ChartsWithAxisTypes.types.d.ts +0 -0
  96. /package/dist/{components → Components}/Charts/ChartsWithAxis/ColumnFamily/ColumnChart.d.ts +0 -0
  97. /package/dist/{components → Components}/Charts/ChartsWithAxis/ColumnFamily/ColumnHistogramChart.d.ts +0 -0
  98. /package/dist/{components → Components}/Charts/ChartsWithAxis/ColumnFamily/CustomColumnChart.d.ts +0 -0
  99. /package/dist/{components → Components}/Charts/ChartsWithAxis/ColumnFamily/LayeredColumnChart.d.ts +0 -0
  100. /package/dist/{components → Components}/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackColumnChart.d.ts +0 -0
  101. /package/dist/{components → Components}/Charts/ChartsWithAxis/ColumnFamily/StackColumnChart.d.ts +0 -0
  102. /package/dist/{components → Components}/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalBarChart.d.ts +0 -0
  103. /package/dist/{components → Components}/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalHistogramChart.d.ts +0 -0
  104. /package/dist/{components → Components}/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredHorizontalBarChart.d.ts +0 -0
  105. /package/dist/{components → Components}/Charts/ChartsWithAxis/HorizontalBarFamily/NormalizedStackHorizontalBarChart.d.ts +0 -0
  106. /package/dist/{components → Components}/Charts/ChartsWithAxis/HorizontalBarFamily/StackHorizontalBarChart.d.ts +0 -0
  107. /package/dist/{components → Components}/Charts/ChartsWithAxis/LineFamily/LineChart.d.ts +0 -0
  108. /package/dist/{components/Charts/ChartsWithAxis/ColumnFamily → Components/Charts/ChartsWithAxis/LineFamily}/NormalizedStackLineChart.d.ts +0 -0
  109. /package/dist/{components/Charts/ChartsWithAxis/ColumnFamily → Components/Charts/ChartsWithAxis/LineFamily}/StackLineChart.d.ts +0 -0
  110. /package/dist/{components → Components}/Charts/ChartsWithAxis/MiscellaneousChartFamily/TornadoChart.d.ts +0 -0
  111. /package/dist/{components → Components}/Charts/ChartsWithAxis/MiscellaneousChartFamily/WaterfallChart.d.ts +0 -0
  112. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.d.ts +0 -0
  113. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/Maps/Cordinates.d.ts +0 -0
  114. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/Maps/Maps.d.ts +0 -0
  115. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/BubbleChart.d.ts +0 -0
  116. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/OrganizationChart.d.ts +0 -0
  117. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/ProgressChart.d.ts +0 -0
  118. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/PyramidChart.d.ts +0 -0
  119. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/RadialBarChart.d.ts +0 -0
  120. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/SankeyChart.d.ts +0 -0
  121. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/ScatterChart.d.ts +0 -0
  122. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/Speedometer.d.ts +0 -0
  123. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/VennChart.d.ts +0 -0
  124. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/OtherCharts/WordCloud.d.ts +0 -0
  125. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/PieFamily/DonutChart.d.ts +0 -0
  126. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/PieFamily/PieChart.d.ts +0 -0
  127. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/PieFamily/PieFamilyCommonFunctions.d.ts +0 -0
  128. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/PieFamily/PieofPieChart.d.ts +0 -0
  129. /package/dist/{components → Components}/Charts/ChartsWithoutAxis/PieFamily/TreemapChart.d.ts +0 -0
  130. /package/dist/{components → Components}/Charts/Core/Common.types.d.ts +0 -0
  131. /package/dist/{components → Components}/Charts/Core/DefaultChartDataProperties.d.ts +0 -0
@@ -1,530 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- //#region Imports
3
- import * as d3 from "d3";
4
- import * as d3Annotation from "d3-svg-annotation";
5
- import { useEffect, useRef } from "react";
6
- import { logError } from "../../../../Services/ErrorLog";
7
- import { staticLegendShape } from "../../Core/Common.types";
8
- import { drawLegends, generalizedChartData, hideTooltipOnMouseOut, showTooltipOnMouseMove, } from "../../Core/CommonFunctions";
9
- import { addDataTable, customYscaleLabelFormatting, dataTablePreCalculation, drawSeriesLabels, firstFunctionBeforeRender, getNumberWithFormat, getStackedData, initChartArea, initPlotArea, initSvg, initXaxis, initYaxis, marginCalculation, prepareDataForSeriesLabel, responsiveXaxisLabel, responsiveYaxisLabel, setChartTitle, setDateFormats, setXaxistitle, stacklineAnnotations, yAxistitle, yAxistitleRight, } from "../ChartsWithAxisFunctions";
10
- import { actualChartTypes, } from "../ChartsWithAxisTypes.types";
11
- const StackColumnChart = ({ isDateType, formatOptions, data, }) => {
12
- // adding variables as per requirement
13
- const chartId = crypto.randomUUID();
14
- let columnWidth = 0; // coz line chart
15
- const chartType = actualChartTypes.stackColumn;
16
- const svgRef = useRef();
17
- const seriesData = generalizedChartData(data.ChartData, data.DimensionList);
18
- const dimensionList = data.DimensionList;
19
- const barChart = false;
20
- const isSecondaryAxisDrawn = false;
21
- let isPrimaryAxisDrawn = true;
22
- let customYaxisMinValue = parseFloat(formatOptions.yAxisLabel.yAxisMinText);
23
- let customYaxisMaxValue = parseFloat(formatOptions.yAxisLabel.yAxisMaxText);
24
- let secondaryCustomYaxisMinValue = parseFloat(formatOptions.secondaryYAxisLabel.secondaryYAxisMinText);
25
- let secondaryCustomYaxisMaxValue = parseFloat(formatOptions.secondaryYAxisLabel.secondaryYAxisMaxText);
26
- let margin;
27
- let yLabel;
28
- let xLabel;
29
- let yTitle;
30
- let xTitle;
31
- let dimensionHeightWidthArray;
32
- let chartTitleHeight;
33
- let secondaryAxisTitleWidth;
34
- let legendMargin;
35
- let secondaryYLabel;
36
- let maxNumberForPrimaryAxis;
37
- let maxNumberForSecondaryAxis;
38
- let innerWidth;
39
- let innerHeight;
40
- let width;
41
- let height;
42
- let totalHeight;
43
- let totalWidth;
44
- let dataTable;
45
- let dataTableHeight;
46
- let svg;
47
- let gTag;
48
- let yScaleLeft;
49
- let yScaleRight;
50
- let xScale;
51
- let seriesLabels;
52
- let calculatedRange;
53
- let seriesLabelWidth;
54
- let yAxisLeft;
55
- let xAxis;
56
- let yAxisRight;
57
- let filteredDimension;
58
- let filteredData = [];
59
- let scrollPosition = 0;
60
- const visibleBars = 2;
61
- let stackLineData = [];
62
- let stackChartData = [];
63
- const isNormalizedChart = false;
64
- let chartJSON = {
65
- dimensionList: dimensionList,
66
- chartType: chartType,
67
- chartData: [],
68
- formatOptions: formatOptions,
69
- legendList: [],
70
- secondaryAxisDrawn: false,
71
- yMaxLeft: 0,
72
- yMaxRight: 0,
73
- yMinLeft: 0,
74
- yMinRight: 0,
75
- hideZeroValues: false,
76
- formattedDimensionListMap: new Map(),
77
- };
78
- //#region UseEffect
79
- useEffect(() => {
80
- try {
81
- createStackColumnChart();
82
- }
83
- catch (error) {
84
- logError("StackStackColumnchart", "createStackColumnChart", error);
85
- }
86
- }, [formatOptions]);
87
- //#endregion
88
- const createStackColumnChart = () => {
89
- ({ formatOptions, svg, width, height } = firstFunctionBeforeRender(svgRef, formatOptions));
90
- preProcessChartData(); // preaparing data related to chart creation
91
- // Applies custom Y-axis label formatting and calculates the necessary margin based on axis extremes.
92
- ({ maxNumberForPrimaryAxis, maxNumberForSecondaryAxis } =
93
- customYscaleLabelFormatting(
94
- // for calculating primary/secondary axis max number so that we can calculate margin accordinglt
95
- formatOptions, chartJSON.yMinLeft, chartJSON.yMaxLeft, chartJSON.yMinRight, chartJSON.yMaxRight));
96
- ({
97
- margin,
98
- yLabel,
99
- xLabel,
100
- yTitle,
101
- xTitle,
102
- dimensionHeightWidthArray,
103
- chartTitleHeight,
104
- secondaryAxisTitleWidth,
105
- legendMargin,
106
- secondaryYLabel,
107
- } = marginCalculation(
108
- // for all margin related calculations
109
- width, height, maxNumberForPrimaryAxis, maxNumberForSecondaryAxis, chartJSON.yMaxLeft, formatOptions, chartJSON.legendList, chartJSON.dimensionList, chartJSON.yMaxRight, isSecondaryAxisDrawn, isNormalizedChart, isDateType));
110
- setSVGContainer(margin); // for innerWidth/height static width/height
111
- ({ dataTable, dataTableHeight } = dataTablePreCalculation(
112
- // calculations for data tables
113
- formatOptions, yLabel, yTitle, seriesData, chartJSON.dimensionList));
114
- initSvg(
115
- // for svg creation
116
- svg, width, height, formatOptions);
117
- //d3.select(svgRef.current, width, height);
118
- gTag = initChartArea(svg, margin); // creating chart area
119
- initPlotArea(gTag, formatOptions, dataTableHeight, innerWidth, innerHeight, chartType);
120
- initScale();
121
- initAxis();
122
- initYaxis(gTag, formatOptions, dataTableHeight, yLabel, yAxisLeft, innerHeight);
123
- horizontalScrollBar(seriesData, height, svg, margin, innerWidth);
124
- if (formatOptions.dataTableProperties &&
125
- formatOptions.dataTableProperties.dataTable) {
126
- if (formatOptions.xAxisLabel.xAxisPosition != "1") {
127
- formatOptions.xAxisLabel.xAxisLabelVisibility = false;
128
- }
129
- addDataTable(formatOptions.plotArea.fitChart, svg, gTag, dataTable, columnWidth, yScaleLeft, xScale, undefined, undefined, undefined, dataTableHeight, chartType, formatOptions, yLabel, yTitle, chartJSON.dimensionList, innerWidth, calculatedRange, chartJSON.formattedDimensionListMap, chartId, margin, innerHeight);
130
- }
131
- setXaxistitle(formatOptions, barChart, svg, margin, xLabel, height, xTitle, chartJSON.chartType, yLabel, innerWidth, innerHeight);
132
- yAxistitle(innerHeight, formatOptions, dataTableHeight, barChart, svg, margin, yTitle, yLabel);
133
- yAxistitleRight(svg, isSecondaryAxisDrawn, margin, formatOptions, dataTableHeight, innerHeight, innerWidth, secondaryYLabel, secondaryAxisTitleWidth); // to be added later
134
- setChartTitle(svg, formatOptions, width, chartTitleHeight);
135
- drawLegends(height, svg, dimensionHeightWidthArray, chartTitleHeight, width, legendMargin, formatOptions, seriesData, chartId, staticLegendShape.rectangle);
136
- };
137
- const preProcessChartData = () => {
138
- const allChartData = [];
139
- const legendList = [];
140
- seriesData.forEach((series, index) => {
141
- // Prefix legend
142
- const prefixedLegend = `${index}~$~${series.properties.legend}`;
143
- series.properties.legend = prefixedLegend;
144
- legendList.push(prefixedLegend);
145
- // Flatten data & collect dimensions
146
- for (const point of series.data) {
147
- allChartData.push(point);
148
- }
149
- });
150
- // Assign computed values
151
- chartJSON.chartData = allChartData;
152
- chartJSON.legendList = legendList;
153
- // getting unique x values as dimension list
154
- filteredData = JSON.parse(JSON.stringify(seriesData));
155
- let tempStackLineData = getStackedData(chartJSON.dimensionList, seriesData, isNormalizedChart);
156
- if (!formatOptions.plotArea.fitChart) {
157
- filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
158
- filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
159
- }
160
- else {
161
- filteredDimension = chartJSON.dimensionList;
162
- }
163
- const allStackDataChart = d3
164
- .stack()
165
- .keys(chartJSON.legendList)
166
- .offset(d3.stackOffsetDiverging)(tempStackLineData);
167
- createStackLineData();
168
- // Compute min and max from stacked data in one loop
169
- let yMinLeft = Infinity;
170
- let yMaxLeft = -Infinity;
171
- for (const series of allStackDataChart) {
172
- for (const [start, end] of series) {
173
- yMinLeft = Math.min(yMinLeft, start);
174
- yMaxLeft = Math.max(yMaxLeft, end);
175
- }
176
- }
177
- chartJSON.yMinLeft = yMinLeft > 0 ? 0 : yMinLeft;
178
- chartJSON.yMaxLeft = yMaxLeft;
179
- let formatedDimensionList = isDateType
180
- ? setDateFormats(formatOptions.xAxisLabel.xAxisNumberFormat, chartJSON.dimensionList).map((d) => d)
181
- : chartJSON.dimensionList;
182
- chartJSON.dimensionList.forEach((d, i) => {
183
- chartJSON.formattedDimensionListMap.set(d, formatedDimensionList[i]);
184
- });
185
- if (formatOptions.plotArea.hideZeroValues) {
186
- chartJSON.hideZeroValues = true;
187
- }
188
- // let secondaryAxisMinValue = 0;
189
- // let secondaryAxisMaxValue = 0;
190
- // if (isSecondaryAxisDrawn) {
191
- // seriesData?.forEach((data) => {
192
- // if (data.properties.axis == "Secondary") {
193
- // // isSecondaryAxisDrawn = true;
194
- // if (
195
- // secondaryAxisMinValue >
196
- // d3.min(data.data, (d: TDataPoint) => d.value)
197
- // ) {
198
- // secondaryAxisMinValue = d3.min(
199
- // data.data,
200
- // (d: TDataPoint) => d.value
201
- // );
202
- // }
203
- // if (
204
- // secondaryAxisMaxValue <
205
- // d3.max(data.data, (d: TDataPoint) => d.value)
206
- // ) {
207
- // secondaryAxisMaxValue = d3.max(
208
- // data.data,
209
- // (d: TDataPoint) => d.value
210
- // );
211
- // }
212
- // }
213
- // });
214
- // chartJSON.yMinRight = secondaryAxisMinValue;
215
- // chartJSON.yMaxRight = secondaryAxisMaxValue;
216
- // }
217
- };
218
- const initScale = () => {
219
- // rounding the ymin & ymax
220
- let yAxisLabelArray = responsiveYaxisLabel(customYaxisMaxValue ? customYaxisMaxValue : chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue).yAxisLabelArray;
221
- chartJSON.yMaxLeft = yAxisLabelArray[yAxisLabelArray.length - 1];
222
- chartJSON.yMinLeft = yAxisLabelArray[0];
223
- if (isPrimaryAxisDrawn) {
224
- yScaleLeft = d3
225
- .scaleLinear()
226
- .domain([
227
- chartJSON.yMinLeft >= 0 ?
228
- customYaxisMinValue !== undefined &&
229
- !Number.isNaN(customYaxisMinValue)
230
- ? customYaxisMinValue : 0
231
- : chartJSON.yMinLeft < 0
232
- ? chartJSON.yMinLeft * 1.1
233
- : chartJSON.yMinLeft * 0.9,
234
- chartJSON.yMaxLeft <= 0
235
- ? 0
236
- : customYaxisMaxValue !== undefined &&
237
- !Number.isNaN(customYaxisMaxValue)
238
- ? customYaxisMaxValue
239
- : chartJSON.yMaxLeft * 1.1,
240
- ])
241
- .range([
242
- dataTableHeight > 0 ? innerHeight - dataTableHeight : innerHeight,
243
- 0,
244
- ]);
245
- }
246
- if (isSecondaryAxisDrawn) {
247
- yScaleRight = d3
248
- .scaleLinear()
249
- .domain([
250
- chartJSON.yMinRight >= 0
251
- ? (secondaryCustomYaxisMinValue ||
252
- secondaryCustomYaxisMinValue == 0) &&
253
- !Number.isNaN(secondaryCustomYaxisMinValue)
254
- ? secondaryCustomYaxisMinValue
255
- : 0
256
- : (secondaryCustomYaxisMinValue ||
257
- secondaryCustomYaxisMinValue == 0) &&
258
- !Number.isNaN(secondaryCustomYaxisMinValue)
259
- ? secondaryCustomYaxisMinValue
260
- : chartJSON.yMinRight * 1.1,
261
- chartJSON.yMaxRight <= 0
262
- ? secondaryCustomYaxisMaxValue
263
- ? secondaryCustomYaxisMaxValue
264
- : 0
265
- : secondaryCustomYaxisMaxValue
266
- ? secondaryCustomYaxisMaxValue
267
- : chartJSON.yMaxRight * 1.1,
268
- ])
269
- .range([
270
- dataTableHeight > 0 ? innerHeight - dataTableHeight : innerHeight,
271
- 0,
272
- ]);
273
- }
274
- calculatedRange = [0, innerWidth];
275
- if (formatOptions.seriesLabel.seriesLabelVisibility) {
276
- let labelObj = prepareDataForSeriesLabel(innerWidth, yScaleLeft, formatOptions, filteredData, undefined, isSecondaryAxisDrawn, true);
277
- seriesLabels = labelObj.labelArray;
278
- formatOptions.seriesLabel.seriesLabelPosition == "Right" &&
279
- (seriesLabelWidth = labelObj.heightWidth[0]);
280
- formatOptions.seriesLabel.seriesLabelPosition == "Right"
281
- ? (calculatedRange = [0, innerWidth - labelObj.heightWidth[0]])
282
- : (calculatedRange = [labelObj.heightWidth[0], innerWidth]);
283
- }
284
- getXScale();
285
- };
286
- const getXScale = () => {
287
- columnWidth =
288
- (0.51 +
289
- (0.61 * (100 - parseFloat(formatOptions.plotArea.plotAreaGapWidth))) /
290
- 100) *
291
- (innerWidth / filteredDimension.length);
292
- xScale = d3
293
- .scaleBand()
294
- .domain(filteredDimension)
295
- .range(calculatedRange)
296
- .padding((0.3 * parseFloat(formatOptions.plotArea.plotAreaGapWidth)) / 100);
297
- };
298
- const initAxis = () => {
299
- getXAxis();
300
- if (isPrimaryAxisDrawn) {
301
- yAxisLeft = d3
302
- .axisLeft(yScaleLeft)
303
- .tickFormat((d) => getNumberWithFormat(d, formatOptions.yAxisLabel.yAxisDisplayUnits, formatOptions.yAxisLabel.yAxisNumberFormat, formatOptions.yAxisLabel.yAxisLabelDecimalPrecision))
304
- .tickSize(formatOptions.plotArea.gridLinesVisibility
305
- ? formatOptions.plotArea.gridLinesHorizontal
306
- ? -innerWidth + (seriesLabelWidth ? seriesLabelWidth : 0)
307
- : 0
308
- : 0)
309
- .tickValues(responsiveYaxisLabel(customYaxisMaxValue ? customYaxisMaxValue : chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue).yAxisLabelArray)
310
- .ticks(responsiveYaxisLabel(customYaxisMaxValue ? customYaxisMaxValue : chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue).customTickValue ??
311
- (dataTableHeight > 0
312
- ? (innerHeight - dataTableHeight) / 30
313
- : innerHeight / 30))
314
- .tickSizeOuter(0);
315
- }
316
- };
317
- const getXAxis = () => {
318
- xAxis = d3
319
- .axisBottom(xScale)
320
- .tickSize(formatOptions.plotArea.gridLinesVisibility
321
- ? formatOptions.plotArea.gridLinesVertical
322
- ? formatOptions.plotArea.gridLinesVertical
323
- ? -(dataTableHeight > 0
324
- ? innerHeight - dataTableHeight
325
- : innerHeight)
326
- : parseFloat(formatOptions.plotArea.ticksHeight) *
327
- ((dataTableHeight > 0
328
- ? innerHeight - dataTableHeight
329
- : innerHeight) /
330
- 100) *
331
- (formatOptions.xAxisLabel.xAxisPosition == "1" ? 1 : -1)
332
- : 0
333
- : 0)
334
- .tickSizeOuter(0)
335
- .tickValues(responsiveXaxisLabel(filteredDimension, innerWidth));
336
- };
337
- const getChartType = (lineData) => {
338
- lineData.forEach((lData) => {
339
- lData.data.forEach((cData) => {
340
- cData.hideZero = lData.properties.hideZeroValues;
341
- cData.axis = lData.properties.axis;
342
- });
343
- });
344
- // Bind dummy data to ensure a single group is created
345
- // lineData.forEach((data) => {
346
- // Step 1: Outer group for the whole chart
347
- // Create parent group for columns
348
- let columns = gTag.selectAll(".parentGroup").data([stackChartData.reverse()]);
349
- columns = columns
350
- .enter()
351
- .append("g")
352
- .attr("class", "columns parentGroup")
353
- .merge(columns);
354
- // JOIN: one group per stack series
355
- let columnGroups = columns.selectAll(".column-group").data((d) => d);
356
- // ENTER
357
- let columnGroupsEnter = columnGroups
358
- .enter()
359
- .append("g")
360
- .attr("class", (d) => "column-group " + d.key.replace(/ /g, "-"))
361
- .attr("hoverId", (d) => d.key.includes("~$~")
362
- ? d.key.split("~$~")[1].replace(/ /g, "-")
363
- : d.key.replace(/ /g, "-"));
364
- columnGroups = columnGroupsEnter.merge(columnGroups);
365
- // JOIN rects inside each series
366
- let rects = columnGroups.selectAll("rect").data((d) => d);
367
- // ENTER
368
- rects
369
- .enter()
370
- .append("rect")
371
- .merge(rects)
372
- .attr("x", (d) => xScale(d.data.dimension))
373
- .attr("y", (d) => yScaleLeft(d[1]))
374
- .attr("height", (d) => Math.max(0, yScaleLeft(d[0]) - yScaleLeft(d[1])))
375
- .attr("width", xScale.bandwidth())
376
- .attr("fill", (d, i, nodes) => {
377
- // `nodes[i]` gives access to parent node so we can infer which group (series) we're in
378
- const groupIndex = Array.from(columnGroups.nodes()).indexOf(nodes[i].parentNode);
379
- return seriesData[groupIndex]?.properties?.color || "gray";
380
- })
381
- .attr("stroke", (d, i, nodes) => {
382
- const groupIndex = Array.from(columnGroups.nodes()).indexOf(nodes[i].parentNode);
383
- const props = seriesData[groupIndex]?.properties;
384
- return props?.stackBorderStyle === 0
385
- ? "none"
386
- : formatOptions.column.stackBorderVisibility
387
- ? props.stackBorderColor
388
- : "none";
389
- })
390
- .attr("stroke-dasharray", (d, i, nodes) => {
391
- const groupIndex = Array.from(columnGroups.nodes()).indexOf(nodes[i].parentNode);
392
- return seriesData[groupIndex]?.properties.stackBorderStyle === 2
393
- ? "5,3"
394
- : "0";
395
- })
396
- .attr("stroke-width", (d, i, nodes) => {
397
- const groupIndex = Array.from(columnGroups.nodes()).indexOf(nodes[i].parentNode);
398
- return ((seriesData[groupIndex]?.properties.stackBorderWidth || 0) + "px");
399
- })
400
- // EXIT
401
- // columnGroups.exit().remove();
402
- .on("mousemove", (event, d) => {
403
- showTooltipOnMouseMove([
404
- {
405
- key: formatOptions.xAxisTitle.xAxisTitleText.includes("~$~")
406
- ? formatOptions.xAxisTitle.xAxisTitleText.split("~$~")[1]
407
- : formatOptions.xAxisTitle.xAxisTitleText,
408
- value: chartJSON.formattedDimensionListMap.get(d.data.dimension),
409
- },
410
- {
411
- key: formatOptions.yAxisTitle.yAxisTitleText || d.value,
412
- value: getNumberWithFormat(d.data[d.key], formatOptions.toolTip.toolTipDisplayUnits, formatOptions.toolTip.toolTipNumberFormat, formatOptions.toolTip.toolTipDecimalPrecision),
413
- },
414
- {
415
- key: "Legend",
416
- value: d.key.includes("~$~") ? d.key.split("~$~")[1] : d.key,
417
- },
418
- ], formatOptions, event);
419
- })
420
- .on("mouseout", hideTooltipOnMouseOut);
421
- // EXIT: remove old groups
422
- columnGroups.exit().remove();
423
- // });
424
- };
425
- const setSVGContainer = (margin) => {
426
- innerWidth = width - margin.left - margin.right;
427
- innerHeight = height - margin.bottom - margin.top;
428
- };
429
- const horizontalScrollBar = (seriesData, height, svg, margin, innerWidth) => {
430
- if (!formatOptions.plotArea.fitChart) {
431
- // Scrollbar parameters
432
- const scrollMax = seriesData[0].data.length - visibleBars;
433
- // Scrollbar track & handle
434
- const scrollbarY = height - 20;
435
- filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
436
- getXScale();
437
- filteredData = JSON.parse(JSON.stringify(seriesData));
438
- filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
439
- createStackLineData();
440
- getXAxis();
441
- svg
442
- .append("rect")
443
- .attr("x", margin.left)
444
- .attr("y", scrollbarY)
445
- .attr("width", innerWidth)
446
- .attr("height", 8)
447
- .attr("fill", "#ddd")
448
- .attr("rx", 4);
449
- const handleWidth = (innerWidth * visibleBars) / chartJSON.dimensionList.length;
450
- const handle = svg
451
- .append("rect")
452
- .attr("x", margin.left)
453
- .attr("y", scrollbarY)
454
- .attr("width", handleWidth)
455
- .attr("height", 8)
456
- .attr("fill", "#999")
457
- .attr("rx", 4)
458
- .style("cursor", "ew-resize")
459
- .call(d3.drag().on("drag", (event) => {
460
- let x = Math.min(Math.max(event.x, margin.left), margin.left + innerWidth - handleWidth);
461
- handle.attr("x", x);
462
- scrollPosition = Math.round(((x - margin.left) / (innerWidth - handleWidth)) * scrollMax);
463
- filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
464
- getXScale();
465
- filteredData = JSON.parse(JSON.stringify(seriesData));
466
- filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
467
- createStackLineData();
468
- getXAxis();
469
- drawLineChart();
470
- }));
471
- svg.on("wheel", (event) => {
472
- event.preventDefault();
473
- const scrollDelta = Math.abs(event.deltaX) > Math.abs(event.deltaY)
474
- ? event.deltaX
475
- : event.deltaY;
476
- scrollPosition += scrollDelta > 0 ? 1 : -1;
477
- scrollPosition = Math.max(0, Math.min(scrollPosition, scrollMax));
478
- const x = margin.left +
479
- ((innerWidth - handleWidth) * scrollPosition) / scrollMax;
480
- handle.attr("x", x);
481
- getXScale();
482
- filteredData = JSON.parse(JSON.stringify(seriesData));
483
- filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
484
- createStackLineData();
485
- getXAxis();
486
- drawLineChart();
487
- });
488
- }
489
- drawLineChart();
490
- };
491
- const drawLineChart = () => {
492
- // filteredData.forEach((data) => getChartType([data]));
493
- getChartType(filteredData);
494
- initXaxis(gTag, chartJSON, xLabel, formatOptions, dataTableHeight, yScaleLeft, xAxis, dimensionHeightWidthArray, height, columnWidth, isDateType, innerWidth, innerHeight, filteredDimension);
495
- stacklineAnnotations(stackChartData, xScale, yScaleLeft, yScaleRight, // need to pass secondary axis scale if secondary axis is drawn
496
- margin, d3Annotation, [], //this.labelExcludeList,
497
- [], //this.individualLabelColor,
498
- [], //this.attributes.Id ? formatOptions.plotArea.dataLabelsCoordinates : this.parentReference.objService.tempAnnotationArray
499
- formatOptions, chartType, height, width, innerWidth, filteredDimension, innerHeight, chartId, svg, dataTableHeight);
500
- let newSeriesLabelArray = prepareDataForSeriesLabel(innerWidth, yScaleLeft, formatOptions, filteredData, undefined, isSecondaryAxisDrawn, true).labelArray;
501
- // adding series labels ( appending legends at the end of line : by default) in plot area
502
- drawSeriesLabels(formatOptions, gTag, newSeriesLabelArray);
503
- };
504
- const createStackLineData = () => {
505
- let stackLineData = getStackedData(filteredDimension, filteredData, isNormalizedChart);
506
- // }
507
- stackChartData = d3
508
- .stack()
509
- .keys(chartJSON.legendList)
510
- .offset(d3.stackOffsetDiverging)(stackLineData);
511
- filteredData.forEach((data, index) => data.data.forEach((axisData, position) => {
512
- axisData["0"] = stackChartData[index][position][0];
513
- axisData["1"] = stackChartData[index][position][1];
514
- }));
515
- //Appending Extra key for tooltip color
516
- let seriesColor = formatOptions.annotation.annotationSetLabelColor;
517
- stackChartData.forEach((K, j) => K.forEach((d) => {
518
- d["key"] = K.key;
519
- K["color"] = JSON.parse(JSON.stringify(seriesData[j].properties.color));
520
- d.data.labelPosition = seriesData[j].properties.dataLabelPosition;
521
- d.data["labelColor"] =
522
- seriesColor == "2"
523
- ? JSON.parse(JSON.stringify(seriesData[j].properties.color))
524
- : seriesData[j].properties.labelColor;
525
- d["hideZero"] = JSON.parse(JSON.stringify(seriesData[j].properties.hideZeroValues));
526
- }));
527
- };
528
- 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%" } })] }));
529
- };
530
- export default StackColumnChart;