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