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