pace-chart-lib 0.0.6 → 0.0.8

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 (150) hide show
  1. package/README.md +10 -54
  2. package/dist/Components1/Charts/ChartsWithAxis/ChartsWithAxisFunctions.d.ts +46 -0
  3. package/dist/Components1/Charts/ChartsWithAxis/ChartsWithAxisFunctions.js +2285 -0
  4. package/dist/Components1/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.d.ts +169 -0
  5. package/dist/Components1/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.js +47 -0
  6. package/dist/Components1/Charts/ChartsWithAxis/LineFamily/LineChart.d.ts +4 -0
  7. package/dist/Components1/Charts/ChartsWithAxis/LineFamily/LineChart.js +403 -0
  8. package/dist/Components1/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.d.ts +0 -0
  9. package/dist/Components1/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.js +0 -0
  10. package/dist/Components1/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.d.ts +0 -0
  11. package/dist/Components1/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.js +0 -0
  12. package/dist/Components1/Charts/Core/Common.type.d.ts +8 -0
  13. package/dist/Components1/Charts/Core/Common.type.js +9 -0
  14. package/dist/Components1/Charts/Core/CommonFunctions.d.ts +12 -0
  15. package/dist/Components1/Charts/Core/CommonFunctions.js +512 -0
  16. package/dist/Components1/Charts/Core/DefaultProperties.d.ts +586 -0
  17. package/dist/Components1/Charts/Core/DefaultProperties.js +585 -0
  18. package/dist/Services/ErrorLog.d.ts +1 -0
  19. package/dist/Services/ErrorLog.js +3 -0
  20. package/dist/components/Charts/ChartsWithAxis/AreaFamily/AreaChart.d.ts +4 -0
  21. package/dist/components/Charts/ChartsWithAxis/AreaFamily/AreaChart.js +497 -0
  22. package/dist/components/Charts/ChartsWithAxis/AreaFamily/LineChart.d.ts +4 -0
  23. package/dist/components/Charts/ChartsWithAxis/AreaFamily/LineChart.js +491 -0
  24. package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackAreaChart.d.ts +4 -0
  25. package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackAreaChart.js +520 -0
  26. package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackLineChart.d.ts +4 -0
  27. package/dist/components/Charts/ChartsWithAxis/AreaFamily/NormalizedStackLineChart.js +553 -0
  28. package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackAreaChart.d.ts +4 -0
  29. package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackAreaChart.js +519 -0
  30. package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackLineChart.d.ts +4 -0
  31. package/dist/components/Charts/ChartsWithAxis/AreaFamily/StackLineChart.js +553 -0
  32. package/dist/components/Charts/ChartsWithAxis/BarFamily/BarChart.d.ts +12 -0
  33. package/dist/components/Charts/ChartsWithAxis/BarFamily/BarChart.js +9 -0
  34. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisFunctions.d.ts +623 -0
  35. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisFunctions.js +4897 -0
  36. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.d.ts +0 -0
  37. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.type.js +0 -0
  38. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.types.d.ts +173 -0
  39. package/dist/components/Charts/ChartsWithAxis/ChartsWithAxisTypes.types.js +49 -0
  40. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart copy.d.ts +4 -0
  41. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart copy.js +486 -0
  42. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart.d.ts +4 -0
  43. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnChart.js +498 -0
  44. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnHistogramChart.d.ts +4 -0
  45. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/ColumnHistogramChart.js +417 -0
  46. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/CustomColumnChart.d.ts +4 -0
  47. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/CustomColumnChart.js +1014 -0
  48. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LayeredColumnChart.d.ts +4 -0
  49. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LayeredColumnChart.js +479 -0
  50. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LineChart.d.ts +4 -0
  51. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/LineChart.js +451 -0
  52. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackColumnChart.d.ts +4 -0
  53. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackColumnChart.js +535 -0
  54. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackLineChart.d.ts +4 -0
  55. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/NormalizedStackLineChart.js +512 -0
  56. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackColumnChart.d.ts +4 -0
  57. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackColumnChart.js +532 -0
  58. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackLineChart.d.ts +4 -0
  59. package/dist/components/Charts/ChartsWithAxis/ColumnFamily/StackLineChart.js +512 -0
  60. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/BarChart.d.ts +12 -0
  61. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/BarChart.js +9 -0
  62. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalBarChart.d.ts +4 -0
  63. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalBarChart.js +498 -0
  64. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalHistogramChart.d.ts +4 -0
  65. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/HorizontalHistogramChart.js +498 -0
  66. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredColumnChart.d.ts +4 -0
  67. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredColumnChart.js +479 -0
  68. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredHorizontalBarChart.d.ts +4 -0
  69. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/LayeredHorizontalBarChart.js +479 -0
  70. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/NormalizedStackHorizontalBarChart.d.ts +4 -0
  71. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/NormalizedStackHorizontalBarChart.js +474 -0
  72. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/StackHorizontalBarChart.d.ts +4 -0
  73. package/dist/components/Charts/ChartsWithAxis/HorizontalBarFamily/StackHorizontalBarChart.js +464 -0
  74. package/dist/components/Charts/ChartsWithAxis/LineFamily/100%StackLineChart.d.ts +0 -0
  75. package/dist/components/Charts/ChartsWithAxis/LineFamily/100%StackLineChart.js +0 -0
  76. package/dist/components/Charts/ChartsWithAxis/LineFamily/LineChart.d.ts +4 -0
  77. package/dist/components/Charts/ChartsWithAxis/LineFamily/LineChart.js +452 -0
  78. package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalisedStackLineChart.d.ts +4 -0
  79. package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalisedStackLineChart.js +554 -0
  80. package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalizedStackLineChart.d.ts +4 -0
  81. package/dist/components/Charts/ChartsWithAxis/LineFamily/NormalizedStackLineChart.js +513 -0
  82. package/dist/components/Charts/ChartsWithAxis/LineFamily/StackLineChart.d.ts +4 -0
  83. package/dist/components/Charts/ChartsWithAxis/LineFamily/StackLineChart.js +508 -0
  84. package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/TornadoChart.d.ts +4 -0
  85. package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/TornadoChart.js +395 -0
  86. package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/WaterfallChart.d.ts +4 -0
  87. package/dist/components/Charts/ChartsWithAxis/MiscellaneousChartFamily/WaterfallChart.js +608 -0
  88. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxis.types.d.ts +0 -0
  89. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxis.types.js +0 -0
  90. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.d.ts +92 -0
  91. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisFunctions.js +815 -0
  92. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.d.ts +0 -0
  93. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.type.js +0 -0
  94. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.types.d.ts +108 -0
  95. package/dist/components/Charts/ChartsWithoutAxis/ChartsWithoutAxisTypes.types.js +32 -0
  96. package/dist/components/Charts/ChartsWithoutAxis/Maps/Cordinates.d.ts +26 -0
  97. package/dist/components/Charts/ChartsWithoutAxis/Maps/Cordinates.js +15021 -0
  98. package/dist/components/Charts/ChartsWithoutAxis/Maps/Maps.d.ts +4 -0
  99. package/dist/components/Charts/ChartsWithoutAxis/Maps/Maps.js +391 -0
  100. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/BubbleChart.d.ts +4 -0
  101. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/BubbleChart.js +367 -0
  102. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/OrganizationChart.d.ts +4 -0
  103. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/OrganizationChart.js +569 -0
  104. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ProgressChart.d.ts +3 -0
  105. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ProgressChart.js +212 -0
  106. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/PyramidChart.d.ts +3 -0
  107. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/PyramidChart.js +401 -0
  108. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/RadialBarChart.d.ts +4 -0
  109. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/RadialBarChart.js +313 -0
  110. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/SankeyChart.d.ts +4 -0
  111. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/SankeyChart.js +719 -0
  112. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ScatterChart.d.ts +4 -0
  113. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/ScatterChart.js +807 -0
  114. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/Speedometer.d.ts +3 -0
  115. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/Speedometer.js +514 -0
  116. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/VennChart.d.ts +4 -0
  117. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/VennChart.js +282 -0
  118. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/WordCloud.d.ts +4 -0
  119. package/dist/components/Charts/ChartsWithoutAxis/OtherCharts/WordCloud.js +207 -0
  120. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/DonutChart.d.ts +4 -0
  121. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/DonutChart.js +476 -0
  122. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieChart.d.ts +4 -0
  123. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieChart.js +420 -0
  124. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieFamilyCommonFunctions.d.ts +10 -0
  125. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieFamilyCommonFunctions.js +106 -0
  126. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieofPieChart.d.ts +3 -0
  127. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/PieofPieChart.js +507 -0
  128. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/TreemapChart.d.ts +3 -0
  129. package/dist/components/Charts/ChartsWithoutAxis/PieFamily/TreemapChart.js +246 -0
  130. package/dist/components/Charts/Core/Common.type.d.ts +0 -0
  131. package/dist/components/Charts/Core/Common.type.js +0 -0
  132. package/dist/components/Charts/Core/Common.types.d.ts +369 -0
  133. package/dist/components/Charts/Core/Common.types.js +133 -0
  134. package/dist/components/Charts/Core/CommonFunctions.d.ts +236 -0
  135. package/dist/components/Charts/Core/CommonFunctions.js +1778 -0
  136. package/dist/components/Charts/Core/DefaultChartDataProperties.d.ts +65 -0
  137. package/dist/components/Charts/Core/DefaultChartDataProperties.js +64 -0
  138. package/dist/components/Charts/Core/DefaultProperties.d.ts +0 -0
  139. package/dist/components/Charts/Core/DefaultProperties.js +0 -0
  140. package/dist/components/Charts/Core/DefaultProperties.type.d.ts +586 -0
  141. package/dist/components/Charts/Core/DefaultProperties.type.js +585 -0
  142. package/dist/components/Charts/Core/DefaultProperties.types.d.ts +592 -0
  143. package/dist/components/Charts/Core/DefaultProperties.types.js +592 -0
  144. package/dist/index.d.ts +34 -2
  145. package/dist/index.js +40 -2
  146. package/package.json +40 -29
  147. package/dist/components/charts/linechart/LineChart.d.ts +0 -12
  148. package/dist/components/charts/linechart/LineChart.js +0 -5
  149. /package/dist/{components/charts/barchart → Components1/Charts/ChartsWithAxis/BarFamily}/BarChart.d.ts +0 -0
  150. /package/dist/{components/charts/barchart → Components1/Charts/ChartsWithAxis/BarFamily}/BarChart.js +0 -0
@@ -0,0 +1,497 @@
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, customYscaleLabelFormatting, dataTablePreCalculation, drawSeriesLabels, firstFunctionBeforeRender, getCurveType, getNumberWithFormat, initChartArea, initPlotArea, initSvg, initXaxis, initYaxis,
10
+ // initYaxisRight,
11
+ commonAnnotations, marginCalculation, prepareDataForSeriesLabel, responsiveXaxisLabel, responsiveYaxisLabel, setChartTitle, setDateFormats, setXaxistitle, yAxistitle, yAxistitleRight, } from "../ChartsWithAxisFunctions";
12
+ import { actualChartTypes, } from "../ChartsWithAxisTypes.types";
13
+ const AreaChart = ({ title, data, yAxisObj, xAxisObj, chartId, formatOptions, }) => {
14
+ // adding variables as per requirement
15
+ const barWidth = 0; // coz line chart
16
+ const chartType = actualChartTypes.area;
17
+ const svgRef = useRef();
18
+ const seriesData = generalizedChartData(data.ChartData, data.DimensionList);
19
+ const dimensionList = data.DimensionList;
20
+ const barChart = false;
21
+ const isSecondaryAxisDrawn = false;
22
+ const isNormalizedChart = false;
23
+ let isPrimaryAxisDrawn = true;
24
+ let customYaxisMinValue = parseFloat(formatOptions.yAxisLabel.yAxisMinText);
25
+ let customYaxisMaxValue = parseFloat(formatOptions.yAxisLabel.yAxisMaxText);
26
+ let secondaryCustomYaxisMinValue = parseFloat(formatOptions.secondaryYAxisLabel.secondaryYAxisMinText);
27
+ let secondaryCustomYaxisMaxValue = parseFloat(formatOptions.secondaryYAxisLabel.secondaryYAxisMaxText);
28
+ let margin;
29
+ let yLabel;
30
+ let xLabel;
31
+ let yTitle;
32
+ let xTitle;
33
+ let dimensionHeightWidthArray;
34
+ let chartTitleHeight;
35
+ let secondaryAxisTitleWidth;
36
+ let legendMargin;
37
+ let secondaryYLabel;
38
+ let maxNumberForPrimaryAxis;
39
+ let maxNumberForSecondaryAxis;
40
+ let innerWidth;
41
+ let innerHeight;
42
+ let width;
43
+ let height;
44
+ let dataTable;
45
+ let dataTableHeight;
46
+ let svg;
47
+ let gTag;
48
+ let yScaleLeft;
49
+ // let yScaleRight: any;
50
+ let xScale;
51
+ let seriesLabels;
52
+ let calculatedRange;
53
+ let seriesLabelWidth;
54
+ let yAxisLeft;
55
+ let xAxis;
56
+ let yAxisRight;
57
+ let filteredDimension;
58
+ let filteredData = [];
59
+ let scrollPosition = 0;
60
+ const visibleBars = 2;
61
+ let chartJSON = {
62
+ dimensionList: 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
+ createAreaChart();
79
+ }
80
+ catch (error) {
81
+ logError("Linechart", "createLineChart", error);
82
+ }
83
+ }, [formatOptions]);
84
+ //#endregion
85
+ const createAreaChart = () => {
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
+ ({ maxNumberForPrimaryAxis, maxNumberForSecondaryAxis } =
90
+ customYscaleLabelFormatting(
91
+ // for calculating primary/secondary axis max number so that we can calculate margin accordinglt
92
+ formatOptions, chartJSON.yMinLeft, chartJSON.yMaxLeft, chartJSON.yMinRight, chartJSON.yMaxRight));
93
+ ({
94
+ margin,
95
+ yLabel,
96
+ xLabel,
97
+ yTitle,
98
+ xTitle,
99
+ dimensionHeightWidthArray,
100
+ chartTitleHeight,
101
+ secondaryAxisTitleWidth,
102
+ legendMargin,
103
+ secondaryYLabel,
104
+ } = marginCalculation(
105
+ // for all margin related calculations
106
+ width, height, maxNumberForPrimaryAxis, maxNumberForSecondaryAxis, chartJSON.yMaxLeft, formatOptions, chartJSON.legendList, chartJSON.dimensionList, chartJSON.yMaxRight, isSecondaryAxisDrawn, isNormalizedChart));
107
+ setSVGContainer(margin); // for innerWidth/height static width/height
108
+ ({ dataTable, dataTableHeight } = dataTablePreCalculation(
109
+ // calculations for data tables
110
+ formatOptions, yLabel, yTitle, seriesData, chartJSON.dimensionList));
111
+ initSvg(
112
+ // for svg creation
113
+ svg, width, height, formatOptions);
114
+ gTag = initChartArea(svg, margin); // creating chart area
115
+ initPlotArea(gTag, formatOptions, dataTableHeight, innerWidth, innerHeight, chartType);
116
+ initScale();
117
+ initAxis();
118
+ initYaxis(gTag, formatOptions, dataTableHeight, yLabel, yAxisLeft, innerHeight);
119
+ // initYaxisRight(
120
+ // gTag,
121
+ // formatOptions,
122
+ // dataTableHeight,
123
+ // secondaryYLabel,
124
+ // yAxisRight,
125
+ // innerHeight,
126
+ // innerWidth
127
+ // );
128
+ horizontalScrollBar(seriesData, height, svg, margin, innerWidth);
129
+ if (formatOptions.dataTableProperties &&
130
+ formatOptions.dataTableProperties.dataTable) {
131
+ if (formatOptions.xAxisLabel.xAxisPosition != "1")
132
+ formatOptions.xAxisLabel.xAxisLabelVisibility = false;
133
+ addDataTable(formatOptions.plotArea.fitChart, svg, gTag, dataTable, barWidth, yScaleLeft, xScale, undefined, undefined, undefined, dataTableHeight, "Area", formatOptions, yLabel, yTitle, chartJSON.dimensionList, innerWidth, calculatedRange, chartJSON.formattedDimensionListMap, chartId, margin, innerHeight);
134
+ }
135
+ setXaxistitle(formatOptions, barChart, svg, margin, xLabel, height, xTitle, chartJSON.chartType, yLabel, innerWidth, innerHeight);
136
+ yAxistitle(innerHeight, formatOptions, dataTableHeight, barChart, svg, margin, yTitle, yLabel);
137
+ yAxistitleRight(svg, isSecondaryAxisDrawn, margin, formatOptions, dataTableHeight, innerHeight, innerWidth, secondaryYLabel, secondaryAxisTitleWidth); // to be added later
138
+ setChartTitle(svg, formatOptions, width, chartTitleHeight);
139
+ drawLegends(height, svg, dimensionHeightWidthArray, chartTitleHeight, width, legendMargin, formatOptions, seriesData, chartId, staticLegendShape.areaWithLine);
140
+ };
141
+ const preProcessChartData = () => {
142
+ const allChartData = [];
143
+ const legendList = [];
144
+ let formatedDimesionList = [];
145
+ let yMaxLeft = -Infinity;
146
+ let yMinLeft = Infinity;
147
+ let yMaxRight = -Infinity;
148
+ let yMinRight = Infinity;
149
+ seriesData.forEach((series) => {
150
+ legendList.push(series.legend);
151
+ series.data.forEach((point) => {
152
+ allChartData.push(point);
153
+ if (isSecondaryAxisDrawn && series.properties.axis === "Secondary") {
154
+ // isSecondaryAxisDrawn = true;
155
+ yMaxRight = Math.max(yMaxRight, point.value);
156
+ yMinRight = Math.min(yMinRight, point.value);
157
+ }
158
+ else {
159
+ yMaxLeft = Math.max(yMaxLeft, point.value);
160
+ yMinLeft = Math.min(yMinLeft, point.value);
161
+ }
162
+ });
163
+ });
164
+ chartJSON.chartData = allChartData;
165
+ chartJSON.legendList = legendList;
166
+ chartJSON.yMaxLeft = yMaxLeft;
167
+ chartJSON.yMinLeft = yMinLeft;
168
+ chartJSON.yMaxRight = yMaxRight;
169
+ chartJSON.yMinRight = yMinRight;
170
+ // Apply formatted dimensions
171
+ let xAxisObject = xAxisObj[0];
172
+ formatedDimesionList =
173
+ (xAxisObject.groupBy == "NA" || xAxisObject.groupBy == undefined) &&
174
+ xAxisObject.dataType === "DATE"
175
+ ? setDateFormats(formatOptions.xAxisLabel.xAxisNumberFormat, chartJSON.dimensionList).map((d) => d[0])
176
+ : chartJSON.dimensionList;
177
+ chartJSON.dimensionList.forEach((dim, i) => {
178
+ chartJSON.formattedDimensionListMap.set(dim, formatedDimesionList[i]);
179
+ });
180
+ filteredData = JSON.parse(JSON.stringify(seriesData));
181
+ if (!formatOptions.plotArea.fitChart) {
182
+ filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
183
+ }
184
+ else {
185
+ filteredDimension = chartJSON.dimensionList;
186
+ }
187
+ if (formatOptions.plotArea.hideZeroValues) {
188
+ chartJSON.hideZeroValues = true;
189
+ }
190
+ };
191
+ const initScale = () => {
192
+ // rounding the ymin & ymax
193
+ let yAxisLabelArray = responsiveYaxisLabel(customYaxisMaxValue ? customYaxisMaxValue : chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue).yAxisLabelArray;
194
+ chartJSON.yMaxLeft = yAxisLabelArray[yAxisLabelArray.length - 1];
195
+ chartJSON.yMinLeft = yAxisLabelArray[0];
196
+ if (isPrimaryAxisDrawn) {
197
+ yScaleLeft = d3
198
+ .scaleLinear()
199
+ .domain([
200
+ customYaxisMinValue !== undefined &&
201
+ !Number.isNaN(customYaxisMinValue)
202
+ ? customYaxisMinValue
203
+ : chartJSON.yMinLeft < 0
204
+ ? chartJSON.yMinLeft * 1.1
205
+ : chartJSON.yMinLeft * 0.9,
206
+ chartJSON.yMaxLeft <= 0
207
+ ? 0
208
+ : customYaxisMaxValue !== undefined &&
209
+ !Number.isNaN(customYaxisMaxValue)
210
+ ? customYaxisMaxValue
211
+ : chartJSON.yMaxLeft * 1.1,
212
+ ])
213
+ .range([
214
+ dataTableHeight > 0 ? innerHeight - dataTableHeight : innerHeight,
215
+ 0,
216
+ ]);
217
+ }
218
+ // if (isSecondaryAxisDrawn) {
219
+ // yScaleRight = d3
220
+ // .scaleLinear()
221
+ // .domain([
222
+ // chartJSON.yMinRight >= 0
223
+ // ? (secondaryCustomYaxisMinValue ||
224
+ // secondaryCustomYaxisMinValue == 0) &&
225
+ // !Number.isNaN(secondaryCustomYaxisMinValue)
226
+ // ? secondaryCustomYaxisMinValue
227
+ // : 0
228
+ // : (secondaryCustomYaxisMinValue ||
229
+ // secondaryCustomYaxisMinValue == 0) &&
230
+ // !Number.isNaN(secondaryCustomYaxisMinValue)
231
+ // ? secondaryCustomYaxisMinValue
232
+ // : chartJSON.yMinRight * 1.1,
233
+ // chartJSON.yMaxRight <= 0
234
+ // ? secondaryCustomYaxisMaxValue
235
+ // ? secondaryCustomYaxisMaxValue
236
+ // : 0
237
+ // : secondaryCustomYaxisMaxValue
238
+ // ? secondaryCustomYaxisMaxValue
239
+ // : chartJSON.yMaxRight * 1.1,
240
+ // ])
241
+ // .range([
242
+ // dataTableHeight > 0 ? innerHeight - dataTableHeight : innerHeight,
243
+ // 0,
244
+ // ]);
245
+ // }
246
+ calculatedRange = [0, innerWidth];
247
+ if (formatOptions.seriesLabel.seriesLabelVisibility) {
248
+ let labelObj = prepareDataForSeriesLabel(innerWidth, yScaleLeft, formatOptions, filteredData, undefined, isSecondaryAxisDrawn);
249
+ seriesLabels = labelObj.labelArray;
250
+ formatOptions.seriesLabel.seriesLabelPosition == "Right" &&
251
+ (seriesLabelWidth = labelObj.heightWidth[0]);
252
+ formatOptions.seriesLabel.seriesLabelPosition == "Right"
253
+ ? (calculatedRange = [0, innerWidth - labelObj.heightWidth[0]])
254
+ : (calculatedRange = [labelObj.heightWidth[0], innerWidth]);
255
+ }
256
+ getXScale();
257
+ };
258
+ const getXScale = () => {
259
+ xScale = d3
260
+ .scalePoint()
261
+ .domain(filteredDimension)
262
+ .range(calculatedRange)
263
+ .padding(0);
264
+ };
265
+ const initAxis = () => {
266
+ getXAxis();
267
+ if (isPrimaryAxisDrawn) {
268
+ yAxisLeft = d3
269
+ .axisLeft(yScaleLeft)
270
+ .tickFormat((d) => getNumberWithFormat(d, formatOptions.yAxisLabel.yAxisDisplayUnits, formatOptions.yAxisLabel.yAxisNumberFormat, formatOptions.yAxisLabel.yAxisLabelDecimalPrecision))
271
+ .tickSize(formatOptions.plotArea.gridLinesVisibility
272
+ ? formatOptions.plotArea.gridLinesHorizontal
273
+ ? -innerWidth + (seriesLabelWidth ? seriesLabelWidth : 0)
274
+ : 0
275
+ : 0)
276
+ .tickValues(responsiveYaxisLabel(customYaxisMaxValue ? customYaxisMaxValue : chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue).yAxisLabelArray)
277
+ .ticks(responsiveYaxisLabel(customYaxisMaxValue ? customYaxisMaxValue : chartJSON.yMaxLeft, chartJSON.yMinLeft, innerHeight, formatOptions, chartJSON, customYaxisMinValue, customYaxisMaxValue).customTickValue ??
278
+ (dataTableHeight > 0
279
+ ? (innerHeight - dataTableHeight) / 30
280
+ : innerHeight / 30))
281
+ .tickSizeOuter(0);
282
+ }
283
+ // if (isSecondaryAxisDrawn) {
284
+ // yAxisRight = d3
285
+ // .axisRight(yScaleRight)
286
+ // .tickFormat((d: number) =>
287
+ // getNumberWithFormat(
288
+ // d,
289
+ // formatOptions.secondaryYAxisLabel.secondaryYAxisDisplayUnits,
290
+ // formatOptions.secondaryYAxisLabel.secondaryYAxisNumberFormat,
291
+ // formatOptions.secondaryYAxisLabel
292
+ // .secondaryYAxisLabelDecimalPrecision
293
+ // )
294
+ // )
295
+ // .tickValues(
296
+ // responsiveSecondaryYaxisLabel(
297
+ // secondaryCustomYaxisMaxValue
298
+ // ? secondaryCustomYaxisMaxValue
299
+ // : chartJSON.yMaxRight,
300
+ // chartJSON.yMinRight,
301
+ // formatOptions,
302
+ // chartJSON
303
+ // ).secondaryYAxisLabelArray
304
+ // )
305
+ // .ticks(
306
+ // responsiveSecondaryYaxisLabel(
307
+ // secondaryCustomYaxisMaxValue
308
+ // ? secondaryCustomYaxisMaxValue
309
+ // : chartJSON.yMaxRight,
310
+ // chartJSON.yMinRight,
311
+ // formatOptions,
312
+ // chartJSON
313
+ // ).secondaryCustomTickValue ?? innerHeight / 30
314
+ // )
315
+ // .tickSize(
316
+ // formatOptions.plotArea.gridLinesVisibility
317
+ // ? formatOptions.plotArea.gridLinesHorizontal
318
+ // ? -innerWidth
319
+ // : 0
320
+ // : 0
321
+ // )
322
+ // .tickSizeOuter(0);
323
+ // }
324
+ };
325
+ const getXAxis = () => {
326
+ xAxis = d3
327
+ .axisBottom(xScale)
328
+ .tickSize(formatOptions.plotArea.gridLinesVisibility
329
+ ? formatOptions.plotArea.gridLinesVertical
330
+ ? formatOptions.plotArea.gridLinesVertical
331
+ ? -(dataTableHeight > 0
332
+ ? innerHeight - dataTableHeight
333
+ : innerHeight)
334
+ : parseFloat(formatOptions.plotArea.ticksHeight) *
335
+ ((dataTableHeight > 0
336
+ ? innerHeight - dataTableHeight
337
+ : innerHeight) /
338
+ 100) *
339
+ (formatOptions.xAxisLabel.xAxisPosition == "1" ? 1 : -1)
340
+ : 0
341
+ : 0)
342
+ .tickSizeOuter(0)
343
+ .tickValues(responsiveXaxisLabel(filteredDimension, innerWidth));
344
+ };
345
+ const getChartType = (lineData) => {
346
+ lineData.forEach((lData) => {
347
+ lData.data.forEach((cData) => {
348
+ cData.hideZero = lData.properties.hideZeroValues;
349
+ cData.axis = lData.properties.axis;
350
+ });
351
+ });
352
+ const areaGenerator = d3
353
+ .area()
354
+ .x((d) => xScale(d.dimension)
355
+ ? xScale(d.dimension)
356
+ : null)
357
+ .y0((d) =>
358
+ // d.axis == "Primary" ?
359
+ yScaleLeft(0)
360
+ // : yScaleRight(0)
361
+ )
362
+ .y1((d) =>
363
+ // d.axis == "Primary" ?
364
+ yScaleLeft(d.value)
365
+ // : yScaleRight((d as TDataPoint).value)
366
+ )
367
+ .defined((d) => (d.hideZero ? Boolean(d.value) : true))
368
+ .curve(getCurveType(formatOptions));
369
+ // Bind dummy data to ensure a single group is created
370
+ let areas = gTag.selectAll(".parentGroup").data([lineData]);
371
+ let focus = gTag.append("g").attr("class", "focusClass");
372
+ areas = areas
373
+ .enter()
374
+ .append("g")
375
+ .attr("class", "areas parentGroup")
376
+ .merge(areas);
377
+ // JOIN: one group per line
378
+ let areaGroups = areas.selectAll(".area-group").data((d) => d);
379
+ // ENTER: create group for each new line
380
+ let areaGroupsEnter = areaGroups
381
+ .enter()
382
+ .append("g")
383
+ .attr("class", "area-group");
384
+ // Append path to new groups
385
+ areaGroupsEnter
386
+ .attr("hoverId", (d) => d.legend.replace(/ /g, "-"))
387
+ .append("path")
388
+ .attr("class", "area")
389
+ .attr("fill", (d) => d.properties.color !== "#ffffff" ? d.properties.color : "none")
390
+ .style("fill-opacity", formatOptions.plotArea.fillOpacity);
391
+ // ENTER + UPDATE
392
+ areaGroupsEnter
393
+ .merge(areaGroups)
394
+ .select("path")
395
+ .attr("d", (d) => areaGenerator(d.data))
396
+ .attr("stroke", (d) => d.properties.areaBorderColor !== "#ffffff"
397
+ ? d.properties.areaBorderColor
398
+ : "none")
399
+ .attr("stroke-dasharray", (d) => {
400
+ switch (d.properties.lineStyle) {
401
+ case "dotted":
402
+ return "0,3";
403
+ case "dashed":
404
+ return "20,10,5,5,5,10";
405
+ default:
406
+ return "";
407
+ }
408
+ })
409
+ .attr("stroke-linecap", (d) => d.properties.lineStyle === "dotted" ? "round" : "")
410
+ .attr("stroke-width", (d) => d.properties.lineStyle !== "None" &&
411
+ formatOptions.plotArea.plotAreaHideLineAndMarkers
412
+ ? d.properties.lineWidth
413
+ : "0");
414
+ onHoverMarkerForAreaChartFamily(formatOptions, areas, focus, filteredDimension, lineData, xScale, yScaleLeft, chartType);
415
+ // EXIT: remove old groups
416
+ areaGroups.exit().remove();
417
+ //Markers
418
+ lineMarkers(areas, lineData, chartType, xScale, yScaleLeft, undefined, null, formatOptions, chartJSON, secondaryCustomYaxisMaxValue, secondaryCustomYaxisMinValue, customYaxisMinValue, customYaxisMaxValue, false);
419
+ };
420
+ const setSVGContainer = (margin) => {
421
+ innerWidth = width - margin.left - margin.right;
422
+ innerHeight = height - margin.bottom - margin.top;
423
+ };
424
+ const horizontalScrollBar = (seriesData, height, svg, margin, innerWidth) => {
425
+ if (!formatOptions.plotArea.fitChart) {
426
+ // Scrollbar parameters
427
+ const scrollMax = seriesData[0].data.length - visibleBars;
428
+ // Scrollbar track & handle
429
+ const scrollbarY = height - 20;
430
+ filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
431
+ getXScale();
432
+ filteredData = JSON.parse(JSON.stringify(seriesData));
433
+ filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
434
+ getXAxis();
435
+ svg
436
+ .append("rect")
437
+ .attr("x", margin.left)
438
+ .attr("y", scrollbarY)
439
+ .attr("width", innerWidth)
440
+ .attr("height", 8)
441
+ .attr("fill", "#ddd")
442
+ .attr("rx", 4);
443
+ const handleWidth = (innerWidth * visibleBars) / chartJSON.dimensionList.length;
444
+ const handle = svg
445
+ .append("rect")
446
+ .attr("x", margin.left)
447
+ .attr("y", scrollbarY)
448
+ .attr("width", handleWidth)
449
+ .attr("height", 8)
450
+ .attr("fill", "#999")
451
+ .attr("rx", 4)
452
+ .style("cursor", "ew-resize")
453
+ .call(d3.drag().on("drag", (event) => {
454
+ let x = Math.min(Math.max(event.x, margin.left), margin.left + innerWidth - handleWidth);
455
+ handle.attr("x", x);
456
+ scrollPosition = Math.round(((x - margin.left) / (innerWidth - handleWidth)) * scrollMax);
457
+ filteredDimension = chartJSON.dimensionList.slice(scrollPosition, scrollPosition + visibleBars);
458
+ getXScale();
459
+ filteredData = JSON.parse(JSON.stringify(seriesData));
460
+ filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
461
+ getXAxis();
462
+ drawAreaChart();
463
+ }));
464
+ svg.on("wheel", (event) => {
465
+ event.preventDefault();
466
+ const scrollDelta = Math.abs(event.deltaX) > Math.abs(event.deltaY)
467
+ ? event.deltaX
468
+ : event.deltaY;
469
+ scrollPosition += scrollDelta > 0 ? 1 : -1;
470
+ scrollPosition = Math.max(0, Math.min(scrollPosition, scrollMax));
471
+ const x = margin.left +
472
+ ((innerWidth - handleWidth) * scrollPosition) / scrollMax;
473
+ handle.attr("x", x);
474
+ getXScale();
475
+ filteredData = JSON.parse(JSON.stringify(seriesData));
476
+ filteredData.forEach((data, i) => (filteredData[i].data = data.data.filter((d) => filteredDimension.includes(d.dimension))));
477
+ getXAxis();
478
+ drawAreaChart();
479
+ });
480
+ }
481
+ drawAreaChart();
482
+ };
483
+ const drawAreaChart = () => {
484
+ getChartType(filteredData);
485
+ initXaxis(gTag, chartJSON, xLabel, formatOptions, xAxisObj[0], dataTableHeight, yScaleLeft, xAxis, dimensionHeightWidthArray, height, barWidth, xAxisObj[0].dataType, innerWidth, innerHeight, filteredDimension);
486
+ commonAnnotations(seriesData, xScale, yScaleLeft, undefined, // need to pass secondary axis scale if secondary axis is drawn
487
+ margin, d3Annotation, [], //this.labelExcludeList,
488
+ [], //this.individualLabelColor,
489
+ [], //this.attributes.Id ? formatOptions.plotArea.dataLabelsCoordinates : this.parentReference.objService.tempAnnotationArray
490
+ formatOptions, chartType, height, width, innerWidth, filteredDimension, innerHeight, chartId, svg);
491
+ let newSeriesLabelArray = prepareDataForSeriesLabel(innerWidth, yScaleLeft, formatOptions, filteredData, undefined, isSecondaryAxisDrawn).labelArray;
492
+ // adding series labels ( appending legends at the end of line : by default) in plot area
493
+ drawSeriesLabels(formatOptions, gTag, newSeriesLabelArray);
494
+ };
495
+ 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%" } })] }));
496
+ };
497
+ export default AreaChart;
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ import { type TLineChartProps } from "../ChartsWithAxisTypes.types";
3
+ declare const LineChart: React.FC<TLineChartProps>;
4
+ export default LineChart;