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