pace-chart-lib 1.0.2 → 1.0.4

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,465 +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 { drawLegends, generalizedChartData, hideTooltipOnMouseOut, showTooltipOnMouseMove, } from "../../Core/CommonFunctions";
8
- import { addDataTable, customYscaleLabelFormatting, dataTablePreCalculation, firstFunctionBeforeRender, getNumberWithFormat, getStackedData, initChartArea, initPlotArea, initSvg, initXaxisBar, initYaxisBar, marginCalculation, prepareDataForSeriesLabel, responsiveXaxisLabel, responsiveYaxisLabel, setChartTitle, setDateFormats, setXaxistitle, stacklineAnnotations, yAxistitle, } from "../ChartsWithAxisFunctions";
9
- import { actualChartTypes, } from "../ChartsWithAxisTypes.types";
10
- import { staticLegendShape } from "../../Core/Common.types";
11
- const StackHorizontalChart = ({ isDateType, formatOptions, data, yAxisObj, xAxisObj, chartId, formatOptions, }) => {
12
- // adding variables as per requirement
13
- let columnWidth = 0; // coz line chart
14
- const chartType = actualChartTypes.stackBar;
15
- const svgRef = useRef();
16
- const seriesData = generalizedChartData(data.ChartData, data.DimensionList);
17
- const dimensionList = data.DimensionList;
18
- const barChart = true;
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 width;
40
- let height;
41
- let dataTable;
42
- let dataTableHeight;
43
- let svg;
44
- let gTag;
45
- let xScaleBottom;
46
- let yScale;
47
- let seriesLabels;
48
- let calculatedRange;
49
- let seriesLabelWidth;
50
- let xAxisBottom;
51
- let yAxis;
52
- let filteredDimension;
53
- let filteredData = [];
54
- let scrollPosition = 0;
55
- const visibleBars = 2;
56
- let stackLineData = [];
57
- let stackChartData = [];
58
- const isNormalizedChart = false;
59
- let chartJSON = {
60
- dimensionList: dimensionList,
61
- chartType: chartType,
62
- chartData: [],
63
- formatOptions: formatOptions,
64
- legendList: [],
65
- secondaryAxisDrawn: false,
66
- yMaxLeft: 0,
67
- yMaxRight: 0,
68
- yMinLeft: 0,
69
- yMinRight: 0,
70
- hideZeroValues: false,
71
- formattedDimensionListMap: new Map(),
72
- };
73
- //#region UseEffect
74
- useEffect(() => {
75
- try {
76
- createStackHorizontalBarChart();
77
- }
78
- catch (error) {
79
- logError("StackStackHorizontalBarchart", "createStackHorizontalBarChart", error);
80
- }
81
- }, [formatOptions]);
82
- //#endregion
83
- const createStackHorizontalBarChart = () => {
84
- ({ formatOptions, svg, width, height } = firstFunctionBeforeRender(svgRef, formatOptions));
85
- preProcessChartData(); // preaparing data related to chart creation
86
- // Applies custom Y-axis label formatting and calculates the necessary margin based on axis extremes.
87
- ({ maxNumberForPrimaryAxis, maxNumberForSecondaryAxis } =
88
- customYscaleLabelFormatting(
89
- // for calculating primary/secondary axis max number so that we can calculate margin accordinglt
90
- formatOptions, chartJSON.yMinLeft, chartJSON.yMaxLeft, chartJSON.yMinRight, chartJSON.yMaxRight));
91
- ({
92
- margin,
93
- yLabel,
94
- xLabel,
95
- yTitle,
96
- xTitle,
97
- dimensionHeightWidthArray,
98
- chartTitleHeight,
99
- secondaryAxisTitleWidth,
100
- legendMargin,
101
- secondaryYLabel,
102
- } = marginCalculation(
103
- // for all margin related calculations
104
- width, height, maxNumberForPrimaryAxis, maxNumberForSecondaryAxis, chartJSON.yMaxLeft, formatOptions, chartJSON.legendList, chartJSON.dimensionList, chartJSON.yMaxRight, isSecondaryAxisDrawn, isNormalizedChart, xAxisObj[0], barChart));
105
- setSVGContainer(margin); // for innerWidth/height static width/height
106
- ({ dataTable, dataTableHeight } = dataTablePreCalculation(
107
- // calculations for data tables
108
- formatOptions, yLabel, yTitle, seriesData, chartJSON.dimensionList));
109
- initSvg(
110
- // for svg creation
111
- svg, width, height, formatOptions);
112
- //d3.select(svgRef.current, width, height);
113
- gTag = initChartArea(svg, margin); // creating chart area
114
- initPlotArea(gTag, formatOptions, dataTableHeight, innerWidth, innerHeight, chartType);
115
- initScale();
116
- initAxis();
117
- initYaxisBar(formatOptions, gTag, xLabel, innerHeight, innerWidth, yAxis, undefined, xScaleBottom, chartJSON.yMaxLeft, filteredDimension, chartType, xAxisObj[0], width, dimensionHeightWidthArray, columnWidth);
118
- horizontalScrollBar(seriesData, height, svg, margin, innerWidth);
119
- if (formatOptions.dataTableProperties &&
120
- formatOptions.dataTableProperties.dataTable) {
121
- if (formatOptions.xAxisLabel.xAxisPosition != "1") {
122
- formatOptions.xAxisLabel.xAxisLabelVisibility = false;
123
- }
124
- addDataTable(formatOptions.plotArea.fitChart, svg, gTag, dataTable, columnWidth, xScaleBottom, undefined, undefined, undefined, undefined, dataTableHeight, chartType, formatOptions, yLabel, yTitle, chartJSON.dimensionList, innerWidth, calculatedRange, chartJSON.formattedDimensionListMap, chartId, margin, innerHeight);
125
- }
126
- setXaxistitle(formatOptions, barChart, svg, margin, xLabel, height, xTitle, chartJSON.chartType, yLabel, innerWidth, innerHeight);
127
- yAxistitle(innerHeight, formatOptions, dataTableHeight, barChart, svg, margin, yTitle, yLabel);
128
- setChartTitle(svg, formatOptions, width, chartTitleHeight);
129
- drawLegends(height, svg, dimensionHeightWidthArray, chartTitleHeight, width, legendMargin, formatOptions, seriesData, chartId, staticLegendShape.rectangle);
130
- };
131
- const preProcessChartData = () => {
132
- const allChartData = [];
133
- const legendList = [];
134
- seriesData.forEach((series, index) => {
135
- // Prefix legend
136
- const prefixedLegend = `${index}~$~${series.properties.legend}`;
137
- series.properties.legend = prefixedLegend;
138
- legendList.push(prefixedLegend);
139
- // Flatten data & collect dimensions
140
- for (const point of series.data) {
141
- allChartData.push(point);
142
- }
143
- });
144
- // Assign computed values
145
- chartJSON.chartData = allChartData;
146
- chartJSON.legendList = legendList;
147
- // getting unique x values as dimension list
148
- filteredData = JSON.parse(JSON.stringify(seriesData));
149
- let tempStackLineData = getStackedData(chartJSON.dimensionList, seriesData, isNormalizedChart);
150
- if (!formatOptions.plotArea.fitChart) {
151
- filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
152
- filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
153
- }
154
- else {
155
- filteredDimension = chartJSON.dimensionList;
156
- }
157
- const allStackDataChart = d3
158
- .stack()
159
- .keys(chartJSON.legendList)
160
- .offset(d3.stackOffsetDiverging)(tempStackLineData);
161
- createStackLineData();
162
- // Compute min and max from stacked data in one loop
163
- let yMinLeft = Infinity;
164
- let yMaxLeft = -Infinity;
165
- for (const series of allStackDataChart) {
166
- for (const [start, end] of series) {
167
- yMinLeft = Math.min(yMinLeft, start);
168
- yMaxLeft = Math.max(yMaxLeft, end);
169
- }
170
- }
171
- chartJSON.yMinLeft = yMinLeft > 0 ? 0 : yMinLeft;
172
- chartJSON.yMaxLeft = yMaxLeft;
173
- let xAxisObject = xAxisObj[0];
174
- let formatedDimensionList = (xAxisObject.groupBy == "NA" || xAxisObject.groupBy == undefined) &&
175
- xAxisObject.dataType === "DATE"
176
- ? setDateFormats(formatOptions.xAxisLabel.xAxisNumberFormat, chartJSON.dimensionList).map((d) => d)
177
- : chartJSON.dimensionList;
178
- chartJSON.dimensionList.forEach((d, i) => {
179
- chartJSON.formattedDimensionListMap.set(d, formatedDimensionList[i]);
180
- });
181
- if (formatOptions.plotArea.hideZeroValues) {
182
- chartJSON.hideZeroValues = true;
183
- }
184
- };
185
- const initScale = () => {
186
- // rounding the ymin & ymax
187
- let yAxisLabelArray = responsiveYaxisLabel(chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue, barChart, innerWidth).yAxisLabelArray;
188
- chartJSON.yMaxLeft = yAxisLabelArray[yAxisLabelArray.length - 1];
189
- chartJSON.yMinLeft = yAxisLabelArray[0];
190
- if (isPrimaryAxisDrawn) {
191
- xScaleBottom = d3
192
- .scaleLinear()
193
- .domain([
194
- chartJSON.yMinLeft >= 0 ?
195
- customYaxisMinValue !== undefined &&
196
- !Number.isNaN(customYaxisMinValue)
197
- ? customYaxisMinValue : 0
198
- : chartJSON.yMinLeft < 0
199
- ? chartJSON.yMinLeft * 1.1
200
- : chartJSON.yMinLeft * 0.9,
201
- chartJSON.yMaxLeft <= 0
202
- ? 0
203
- : customYaxisMaxValue !== undefined &&
204
- !Number.isNaN(customYaxisMaxValue)
205
- ? customYaxisMaxValue
206
- : chartJSON.yMaxLeft * 1.1,
207
- ])
208
- .range([0,
209
- dataTableHeight > 0 ? innerWidth - dataTableHeight : innerWidth,
210
- ]);
211
- }
212
- calculatedRange = [innerHeight, 0];
213
- if (formatOptions.seriesLabel.seriesLabelVisibility) {
214
- let labelObj = prepareDataForSeriesLabel(innerWidth, xScaleBottom, formatOptions, filteredData, undefined, isSecondaryAxisDrawn, true);
215
- seriesLabels = labelObj.labelArray;
216
- formatOptions.seriesLabel.seriesLabelPosition == "Right" &&
217
- (seriesLabelWidth = labelObj.heightWidth[0]);
218
- formatOptions.seriesLabel.seriesLabelPosition == "Right"
219
- ? (calculatedRange = [0, innerHeight - labelObj.heightWidth[0]])
220
- : (calculatedRange = [labelObj.heightWidth[0], innerHeight]);
221
- }
222
- getYScale();
223
- };
224
- const getYScale = () => {
225
- columnWidth =
226
- (0.51 +
227
- (0.61 * (100 - parseFloat(formatOptions.plotArea.plotAreaGapWidth))) /
228
- 100) *
229
- (innerHeight / filteredDimension.length);
230
- yScale = d3
231
- .scaleBand()
232
- .domain(filteredDimension)
233
- .range(calculatedRange)
234
- .padding((0.3 * parseFloat(formatOptions.plotArea.plotAreaGapWidth)) / 100);
235
- };
236
- const initAxis = () => {
237
- getYAxis();
238
- if (isPrimaryAxisDrawn) {
239
- xAxisBottom = d3
240
- .axisBottom(xScaleBottom)
241
- .tickFormat((d) => getNumberWithFormat(d, formatOptions.yAxisLabel.yAxisDisplayUnits, formatOptions.yAxisLabel.yAxisNumberFormat, formatOptions.yAxisLabel.yAxisLabelDecimalPrecision))
242
- .tickSize(formatOptions.plotArea.gridLinesVisibility
243
- ? formatOptions.plotArea.gridLinesHorizontal
244
- ? -innerHeight + (seriesLabelWidth ? seriesLabelWidth : 0)
245
- : 0
246
- : 0)
247
- .tickValues(responsiveYaxisLabel(customYaxisMaxValue ? customYaxisMaxValue : chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue, barChart, innerWidth).yAxisLabelArray)
248
- .ticks(responsiveYaxisLabel(customYaxisMaxValue ? customYaxisMaxValue : chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue, barChart, innerWidth).customTickValue ??
249
- (dataTableHeight > 0
250
- ? (innerHeight - dataTableHeight) / 30
251
- : innerHeight / 30))
252
- .tickSizeOuter(0);
253
- }
254
- };
255
- const getYAxis = () => {
256
- yAxis = d3
257
- .axisLeft(yScale)
258
- .tickSize(formatOptions.plotArea.gridLinesVisibility
259
- ? formatOptions.plotArea.gridLinesVertical
260
- ? formatOptions.plotArea.gridLinesVertical
261
- ? -(dataTableHeight > 0
262
- ? innerHeight - dataTableHeight
263
- : innerHeight)
264
- : parseFloat(formatOptions.plotArea.ticksHeight) *
265
- ((dataTableHeight > 0
266
- ? innerHeight - dataTableHeight
267
- : innerHeight) /
268
- 100) *
269
- (formatOptions.xAxisLabel.xAxisPosition == "1" ? 1 : -1)
270
- : 0
271
- : 0)
272
- .tickSizeOuter(0)
273
- .tickValues(responsiveXaxisLabel(filteredDimension, innerHeight));
274
- };
275
- const getChartType = (lineData) => {
276
- lineData.forEach((lData) => {
277
- lData.data.forEach((cData) => {
278
- cData.hideZero = lData.properties.hideZeroValues;
279
- cData.axis = lData.properties.axis;
280
- });
281
- });
282
- // Bind dummy data to ensure a single group is created
283
- // lineData.forEach((data) => {
284
- // Step 1: Outer group for the whole chart
285
- // Create parent group for columns
286
- let columns = gTag.selectAll(".parentGroup").data([stackChartData.reverse()]);
287
- columns = columns
288
- .enter()
289
- .append("g")
290
- .attr("class", "columns parentGroup")
291
- .merge(columns);
292
- // JOIN: one group per stack series
293
- let columnGroups = columns.selectAll(".column-group").data((d) => d);
294
- // ENTER
295
- let columnGroupsEnter = columnGroups
296
- .enter()
297
- .append("g")
298
- .attr("class", (d) => "column-group " + d.key.replace(/ /g, "-"))
299
- .attr("hoverId", (d) => d.key.includes("~$~")
300
- ? d.key.split("~$~")[1].replace(/ /g, "-")
301
- : d.key.replace(/ /g, "-"));
302
- columnGroups = columnGroupsEnter.merge(columnGroups);
303
- // JOIN rects inside each series
304
- let rects = columnGroups.selectAll("rect").data((d) => d);
305
- // ENTER
306
- rects
307
- .enter()
308
- .append("rect")
309
- .merge(rects)
310
- .attr("y", (d) => yScale(d.data.dimension))
311
- .attr("x", (d) => xScaleBottom(d[0]))
312
- .attr("width", (d) => Math.max(0, xScaleBottom(d[1]) - xScaleBottom(d[0])))
313
- .attr("height", yScale.bandwidth())
314
- .attr("fill", (d, i, nodes) => {
315
- // `nodes[i]` gives access to parent node so we can infer which group (series) we're in
316
- const groupIndex = Array.from(columnGroups.nodes()).indexOf(nodes[i].parentNode);
317
- return seriesData[groupIndex]?.properties?.color || "gray";
318
- })
319
- .attr("stroke", (d, i, nodes) => {
320
- const groupIndex = Array.from(columnGroups.nodes()).indexOf(nodes[i].parentNode);
321
- const props = seriesData[groupIndex]?.properties;
322
- return props?.stackBorderStyle === 0
323
- ? "none"
324
- : formatOptions.column.stackBorderVisibility
325
- ? props.stackBorderColor
326
- : "none";
327
- })
328
- .attr("stroke-dasharray", (d, i, nodes) => {
329
- const groupIndex = Array.from(columnGroups.nodes()).indexOf(nodes[i].parentNode);
330
- return seriesData[groupIndex]?.properties.stackBorderStyle === 2
331
- ? "5,3"
332
- : "0";
333
- })
334
- .attr("stroke-width", (d, i, nodes) => {
335
- const groupIndex = Array.from(columnGroups.nodes()).indexOf(nodes[i].parentNode);
336
- return ((seriesData[groupIndex]?.properties.stackBorderWidth || 0) + "px");
337
- })
338
- // EXIT
339
- // columnGroups.exit().remove();
340
- .on("mousemove", (event, d) => {
341
- showTooltipOnMouseMove([
342
- {
343
- key: formatOptions.xAxisTitle.xAxisTitleText.includes("~$~")
344
- ? formatOptions.xAxisTitle.xAxisTitleText.split("~$~")[1]
345
- : formatOptions.xAxisTitle.xAxisTitleText,
346
- value: chartJSON.formattedDimensionListMap.get(d.data.dimension),
347
- },
348
- {
349
- key: formatOptions.yAxisTitle.yAxisTitleText || d.value,
350
- value: getNumberWithFormat(d.data[d.key], formatOptions.toolTip.toolTipDisplayUnits, formatOptions.toolTip.toolTipNumberFormat, formatOptions.toolTip.toolTipDecimalPrecision),
351
- },
352
- {
353
- key: "Legend",
354
- value: d.key.includes("~$~") ? d.key.split("~$~")[1] : d.key,
355
- },
356
- ], formatOptions, event);
357
- })
358
- .on("mouseout", hideTooltipOnMouseOut);
359
- // EXIT: remove old groups
360
- columnGroups.exit().remove();
361
- // });
362
- };
363
- const setSVGContainer = (margin) => {
364
- innerWidth = width - margin.left - margin.right;
365
- innerHeight = height - margin.bottom - margin.top;
366
- };
367
- const horizontalScrollBar = (seriesData, height, svg, margin, innerWidth) => {
368
- if (!formatOptions.plotArea.fitChart) {
369
- // Scrollbar parameters
370
- const scrollMax = seriesData[0].data.length - visibleBars;
371
- // Scrollbar track & handle
372
- const scrollbarY = height - 20;
373
- filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
374
- getYScale();
375
- filteredData = JSON.parse(JSON.stringify(seriesData));
376
- filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
377
- createStackLineData();
378
- getYAxis();
379
- svg
380
- .append("rect")
381
- .attr("x", margin.left)
382
- .attr("y", scrollbarY)
383
- .attr("width", innerWidth)
384
- .attr("height", 8)
385
- .attr("fill", "#ddd")
386
- .attr("rx", 4);
387
- const handleWidth = (innerWidth * visibleBars) / chartJSON.dimensionList.length;
388
- const handle = svg
389
- .append("rect")
390
- .attr("x", margin.left)
391
- .attr("y", scrollbarY)
392
- .attr("width", handleWidth)
393
- .attr("height", 8)
394
- .attr("fill", "#999")
395
- .attr("rx", 4)
396
- .style("cursor", "ew-resize")
397
- .call(d3.drag().on("drag", (event) => {
398
- let x = Math.min(Math.max(event.x, margin.left), margin.left + innerWidth - handleWidth);
399
- handle.attr("x", x);
400
- scrollPosition = Math.round(((x - margin.left) / (innerWidth - handleWidth)) * scrollMax);
401
- filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
402
- getYScale();
403
- filteredData = JSON.parse(JSON.stringify(seriesData));
404
- filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
405
- createStackLineData();
406
- getYAxis();
407
- drawLineChart();
408
- }));
409
- svg.on("wheel", (event) => {
410
- event.preventDefault();
411
- const scrollDelta = Math.abs(event.deltaX) > Math.abs(event.deltaY)
412
- ? event.deltaX
413
- : event.deltaY;
414
- scrollPosition += scrollDelta > 0 ? 1 : -1;
415
- scrollPosition = Math.max(0, Math.min(scrollPosition, scrollMax));
416
- const x = margin.left +
417
- ((innerWidth - handleWidth) * scrollPosition) / scrollMax;
418
- handle.attr("x", x);
419
- getYScale();
420
- filteredData = JSON.parse(JSON.stringify(seriesData));
421
- filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
422
- createStackLineData();
423
- getYAxis();
424
- drawLineChart();
425
- });
426
- }
427
- drawLineChart();
428
- };
429
- const drawLineChart = () => {
430
- // filteredData.forEach((data) => getChartType([data]));
431
- getChartType(filteredData);
432
- initXaxisBar(formatOptions, gTag, yLabel, innerHeight, innerWidth, xAxisBottom);
433
- stacklineAnnotations(stackChartData, yScale, xScaleBottom, undefined, // need to pass secondary axis scale if secondary axis is drawn
434
- margin, d3Annotation, [], //this.labelExcludeList,
435
- [], //this.individualLabelColor,
436
- [], //this.attributes.Id ? formatOptions.plotArea.dataLabelsCoordinates : this.parentReference.objService.tempAnnotationArray
437
- formatOptions, chartType, height, width, innerWidth, filteredDimension, innerHeight, chartId, svg, dataTableHeight, barChart);
438
- };
439
- const createStackLineData = () => {
440
- let stackLineData = getStackedData(filteredDimension, filteredData, isNormalizedChart);
441
- // }
442
- stackChartData = d3
443
- .stack()
444
- .keys(chartJSON.legendList)
445
- .offset(d3.stackOffsetDiverging)(stackLineData);
446
- filteredData.forEach((data, index) => data.data.forEach((axisData, position) => {
447
- axisData["0"] = stackChartData[index][position][0];
448
- axisData["1"] = stackChartData[index][position][1];
449
- }));
450
- //Appending Extra key for tooltip color
451
- let seriesColor = formatOptions.annotation.annotationSetLabelColor;
452
- stackChartData.forEach((K, j) => K.forEach((d) => {
453
- d["key"] = K.key;
454
- K["color"] = JSON.parse(JSON.stringify(seriesData[j].properties.color));
455
- d.data.labelPosition = seriesData[j].properties.dataLabelPosition;
456
- d.data["labelColor"] =
457
- seriesColor == "2"
458
- ? JSON.parse(JSON.stringify(seriesData[j].properties.color))
459
- : seriesData[j].properties.labelColor;
460
- d["hideZero"] = JSON.parse(JSON.stringify(seriesData[j].properties.hideZeroValues));
461
- }));
462
- };
463
- 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%" } })] }));
464
- };
465
- export default StackHorizontalChart;