gifted-charts-core 0.0.24 → 0.0.26

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 (54) hide show
  1. package/package.json +6 -2
  2. package/src/BarChart/Animated2DWithGradient.d.ts +24 -0
  3. package/src/BarChart/Animated2DWithGradient.js +108 -0
  4. package/src/BarChart/RenderStackBars.d.ts +27 -0
  5. package/src/BarChart/RenderStackBars.js +99 -0
  6. package/src/BarChart/index.d.ts +175 -0
  7. package/src/BarChart/index.js +611 -0
  8. package/src/BarChart/types.d.ts +570 -0
  9. package/src/BarChart/types.js +1 -0
  10. package/src/LineChart/LineChartBiColor.d.ts +104 -0
  11. package/src/LineChart/LineChartBiColor.js +520 -0
  12. package/src/LineChart/index.d.ts +383 -0
  13. package/src/LineChart/index.js +1397 -0
  14. package/src/LineChart/index.ts +4 -3
  15. package/src/LineChart/types.d.ts +531 -0
  16. package/src/LineChart/types.js +1 -0
  17. package/src/PieChart/index.d.ts +33 -0
  18. package/src/PieChart/index.js +119 -0
  19. package/src/PieChart/main.d.ts +49 -0
  20. package/src/PieChart/main.js +185 -0
  21. package/src/PieChart/types.d.ts +85 -0
  22. package/src/PieChart/types.js +1 -0
  23. package/src/PopulationPyramid/index.d.ts +137 -0
  24. package/src/PopulationPyramid/index.js +233 -0
  25. package/src/PopulationPyramid/index.ts +70 -42
  26. package/src/PopulationPyramid/types.d.ts +235 -0
  27. package/src/PopulationPyramid/types.js +1 -0
  28. package/src/PopulationPyramid/types.ts +62 -5
  29. package/src/components/AnimatedThreeDBar/index.d.ts +12 -0
  30. package/src/components/AnimatedThreeDBar/index.js +53 -0
  31. package/src/components/BarAndLineChartsWrapper/getHorizSectionsVals.d.ts +20 -0
  32. package/src/components/BarAndLineChartsWrapper/getHorizSectionsVals.js +217 -0
  33. package/src/components/BarAndLineChartsWrapper/index.d.ts +97 -0
  34. package/src/components/BarAndLineChartsWrapper/index.js +266 -0
  35. package/src/components/BarAndLineChartsWrapper/index.ts +5 -4
  36. package/src/components/common/StripAndLabel.d.ts +7 -0
  37. package/src/components/common/StripAndLabel.js +53 -0
  38. package/src/components/common/StripAndLabel.ts +2 -2
  39. package/src/components/common/types.d.ts +31 -0
  40. package/src/components/common/types.js +1 -0
  41. package/src/components/common/types.ts +1 -0
  42. package/src/index.d.ts +37 -0
  43. package/src/index.js +32 -0
  44. package/src/index.ts +146 -0
  45. package/src/utils/constants.d.ts +248 -0
  46. package/src/utils/constants.js +299 -0
  47. package/src/utils/constants.ts +0 -4
  48. package/src/utils/index.d.ts +89 -0
  49. package/src/utils/index.js +1008 -0
  50. package/src/utils/index.ts +42 -1
  51. package/src/utils/types.d.ts +337 -0
  52. package/src/utils/types.js +16 -0
  53. package/src/utils/types.ts +6 -0
  54. package/index.ts +0 -141
@@ -0,0 +1,611 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __read = (this && this.__read) || function (o, n) {
13
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
14
+ if (!m) return o;
15
+ var i = m.call(o), r, ar = [], e;
16
+ try {
17
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
+ }
19
+ catch (error) { e = { error: error }; }
20
+ finally {
21
+ try {
22
+ if (r && !r.done && (m = i["return"])) m.call(i);
23
+ }
24
+ finally { if (e) throw e.error; }
25
+ }
26
+ return ar;
27
+ };
28
+ import { useEffect, useMemo, useState } from 'react';
29
+ import { getArrowPoints, getAxesAndRulesProps, getExtendedContainerHeightWithPadding, getLineConfigForBarChart, getMaxValue, getNoOfSections, getSecondaryDataWithOffsetIncluded, getXForLineInBar, getYForLineInBar, maxAndMinUtil, svgPath } from '../utils';
30
+ import { AxesAndRulesDefaults, BarDefaults, chartTypes, defaultLineConfig, defaultPointerConfig } from '../utils/constants';
31
+ export var useBarChart = function (props) {
32
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45;
33
+ var heightValue = props.heightValue, widthValue = props.widthValue, opacValue = props.opacValue;
34
+ var _46 = __read(useState(''), 2), points = _46[0], setPoints = _46[1];
35
+ var _47 = __read(useState(''), 2), points2 = _47[0], setPoints2 = _47[1];
36
+ var _48 = __read(useState(''), 2), arrowPoints = _48[0], setArrowPoints = _48[1];
37
+ var _49 = __read(useState(-1), 2), selectedIndex = _49[0], setSelectedIndex = _49[1];
38
+ var showLine = (_a = props.showLine) !== null && _a !== void 0 ? _a : BarDefaults.showLine;
39
+ var spacing = (_b = props.spacing) !== null && _b !== void 0 ? _b : BarDefaults.spacing;
40
+ var initialSpacing = (_c = props.initialSpacing) !== null && _c !== void 0 ? _c : spacing;
41
+ var endSpacing = (_d = props.endSpacing) !== null && _d !== void 0 ? _d : spacing;
42
+ var showFractionalValues = (_e = props.showFractionalValues) !== null && _e !== void 0 ? _e : AxesAndRulesDefaults.showFractionalValues;
43
+ var horizontal = (_f = props.horizontal) !== null && _f !== void 0 ? _f : BarDefaults.horizontal;
44
+ var rtl = (_g = props.rtl) !== null && _g !== void 0 ? _g : BarDefaults.rtl;
45
+ var yAxisAtTop = (_h = props.yAxisAtTop) !== null && _h !== void 0 ? _h : BarDefaults.yAxisAtTop;
46
+ var intactTopLabel = (_j = props.intactTopLabel) !== null && _j !== void 0 ? _j : BarDefaults.intactTopLabel;
47
+ var heightFromProps = horizontal ? props.width : props.height;
48
+ var widthFromProps = horizontal ? props.height : props.width;
49
+ var isAnimated = (_k = props.isAnimated) !== null && _k !== void 0 ? _k : BarDefaults.isAnimated;
50
+ var animationDuration = (_l = props.animationDuration) !== null && _l !== void 0 ? _l : BarDefaults.animationDuration;
51
+ var data = useMemo(function () {
52
+ if (!props.data) {
53
+ return [];
54
+ }
55
+ if (props.yAxisOffset) {
56
+ return props.data.map(function (item) {
57
+ var _a, _b;
58
+ item.value = ((_a = item.value) !== null && _a !== void 0 ? _a : 0) - ((_b = props.yAxisOffset) !== null && _b !== void 0 ? _b : 0);
59
+ return item;
60
+ });
61
+ }
62
+ return props.data;
63
+ }, [props.yAxisOffset, props.data]);
64
+ var secondaryData = getSecondaryDataWithOffsetIncluded(props.secondaryData, props.secondaryYAxis);
65
+ var lineData = useMemo(function () {
66
+ var _a;
67
+ if (!props.lineData) {
68
+ return (_a = props.stackData) !== null && _a !== void 0 ? _a : data;
69
+ }
70
+ if (props.yAxisOffset) {
71
+ return props.lineData.map(function (item) {
72
+ var _a, _b;
73
+ return (__assign(__assign({}, item), { value: ((_a = item.value) !== null && _a !== void 0 ? _a : 0) - ((_b = props.yAxisOffset) !== null && _b !== void 0 ? _b : 0) }));
74
+ });
75
+ }
76
+ return props.lineData;
77
+ }, [props.yAxisOffset, props.lineData, data, props.stackData]);
78
+ var lineData2 = props.lineData2;
79
+ var lineBehindBars = (_m = props.lineBehindBars) !== null && _m !== void 0 ? _m : BarDefaults.lineBehindBars;
80
+ defaultLineConfig.initialSpacing = initialSpacing;
81
+ defaultLineConfig.endIndex = lineData.length - 1;
82
+ defaultLineConfig.animationDuration = animationDuration;
83
+ var lineConfig = props.lineConfig
84
+ ? getLineConfigForBarChart(props.lineConfig, initialSpacing)
85
+ : defaultLineConfig;
86
+ var lineConfig2 = props.lineConfig2
87
+ ? getLineConfigForBarChart(props.lineConfig2, initialSpacing)
88
+ : defaultLineConfig;
89
+ var noOfSections = getNoOfSections(props.noOfSections, props.maxValue, props.stepValue);
90
+ var containerHeight = heightFromProps !== null && heightFromProps !== void 0 ? heightFromProps : (props.stepHeight
91
+ ? props.stepHeight * noOfSections
92
+ : AxesAndRulesDefaults.containerHeight);
93
+ var horizSections = [{ value: '0' }];
94
+ var stepHeight = (_o = props.stepHeight) !== null && _o !== void 0 ? _o : containerHeight / noOfSections;
95
+ var labelWidth = (_p = props.labelWidth) !== null && _p !== void 0 ? _p : AxesAndRulesDefaults.labelWidth;
96
+ var scrollToEnd = (_q = props.scrollToEnd) !== null && _q !== void 0 ? _q : BarDefaults.scrollToEnd;
97
+ var scrollAnimation = (_r = props.scrollAnimation) !== null && _r !== void 0 ? _r : BarDefaults.scrollAnimation;
98
+ var scrollEventThrottle = (_s = props.scrollEventThrottle) !== null && _s !== void 0 ? _s : BarDefaults.scrollEventThrottle;
99
+ var labelsExtraHeight = (_t = props.labelsExtraHeight) !== null && _t !== void 0 ? _t : AxesAndRulesDefaults.labelsExtraHeight;
100
+ var totalWidth = initialSpacing;
101
+ var maxItem = 0;
102
+ var minItem = 0;
103
+ if (props.stackData) {
104
+ props.stackData.forEach(function (stackItem) {
105
+ var _a, _b;
106
+ var stackSumMax = stackItem.stacks.reduce(function (acc, stack) { return acc + (stack.value >= 0 ? stack.value : 0); }, 0);
107
+ var stackSumMin = stackItem.stacks.reduce(function (acc, stack) { return acc + (stack.value < 0 ? stack.value : 0); }, 0);
108
+ if (stackSumMax > maxItem) {
109
+ maxItem = stackSumMax;
110
+ }
111
+ if (stackSumMin < minItem) {
112
+ minItem = stackSumMin;
113
+ }
114
+ totalWidth +=
115
+ ((_b = (_a = stackItem.stacks[0].barWidth) !== null && _a !== void 0 ? _a : props.barWidth) !== null && _b !== void 0 ? _b : BarDefaults.barWidth) + spacing;
116
+ });
117
+ }
118
+ else {
119
+ data.forEach(function (item) {
120
+ var _a, _b, _c;
121
+ if (item.value > maxItem) {
122
+ maxItem = item.value;
123
+ }
124
+ if (item.value < minItem) {
125
+ minItem = item.value;
126
+ }
127
+ totalWidth +=
128
+ ((_b = (_a = item.barWidth) !== null && _a !== void 0 ? _a : props.barWidth) !== null && _b !== void 0 ? _b : BarDefaults.barWidth) +
129
+ ((_c = item.spacing) !== null && _c !== void 0 ? _c : spacing);
130
+ });
131
+ }
132
+ var secondaryMaxItem = 0;
133
+ var secondaryMinItem = 0;
134
+ if (lineConfig.isSecondary) {
135
+ lineData.forEach(function (item) {
136
+ var _a, _b, _c, _d;
137
+ if (((_a = item.value) !== null && _a !== void 0 ? _a : 0) > secondaryMaxItem) {
138
+ secondaryMaxItem = (_b = item.value) !== null && _b !== void 0 ? _b : 0;
139
+ }
140
+ if (((_c = item.value) !== null && _c !== void 0 ? _c : 0) < secondaryMinItem) {
141
+ secondaryMinItem = (_d = item.value) !== null && _d !== void 0 ? _d : 0;
142
+ }
143
+ });
144
+ }
145
+ var maxAndMin = maxAndMinUtil(maxItem, minItem, props.roundToDigits, props.showFractionalValues);
146
+ var secondaryMaxAndMin = maxAndMinUtil(secondaryMaxItem, secondaryMinItem, props.roundToDigits, props.showFractionalValues);
147
+ var maxValue = getMaxValue(props.maxValue, props.stepValue, noOfSections, maxAndMin.maxItem);
148
+ var secondaryMaxValue = lineConfig.isSecondary
149
+ ? secondaryMaxAndMin.maxItem
150
+ : maxValue;
151
+ var mostNegativeValue = (_u = props.mostNegativeValue) !== null && _u !== void 0 ? _u : maxAndMin.minItem;
152
+ var stepValue = (_v = props.stepValue) !== null && _v !== void 0 ? _v : maxValue / noOfSections;
153
+ var noOfSectionsBelowXAxis = (_w = props.noOfSectionsBelowXAxis) !== null && _w !== void 0 ? _w : -mostNegativeValue / stepValue;
154
+ var showScrollIndicator = (_x = props.showScrollIndicator) !== null && _x !== void 0 ? _x : BarDefaults.showScrollIndicator;
155
+ var side = (_y = props.side) !== null && _y !== void 0 ? _y : BarDefaults.side;
156
+ var rotateLabel = (_z = props.rotateLabel) !== null && _z !== void 0 ? _z : AxesAndRulesDefaults.rotateLabel;
157
+ var opacity = (_0 = props.opacity) !== null && _0 !== void 0 ? _0 : BarDefaults.opacity;
158
+ var isThreeD = (_1 = props.isThreeD) !== null && _1 !== void 0 ? _1 : BarDefaults.isThreeD;
159
+ var showXAxisIndices = (_2 = props.showXAxisIndices) !== null && _2 !== void 0 ? _2 : AxesAndRulesDefaults.showXAxisIndices;
160
+ var xAxisIndicesHeight = (_3 = props.xAxisIndicesHeight) !== null && _3 !== void 0 ? _3 : AxesAndRulesDefaults.xAxisIndicesHeight;
161
+ var xAxisIndicesWidth = (_4 = props.xAxisIndicesWidth) !== null && _4 !== void 0 ? _4 : AxesAndRulesDefaults.xAxisIndicesWidth;
162
+ var xAxisIndicesColor = (_5 = props.xAxisIndicesColor) !== null && _5 !== void 0 ? _5 : AxesAndRulesDefaults.xAxisIndicesColor;
163
+ var xAxisThickness = (_6 = props.xAxisThickness) !== null && _6 !== void 0 ? _6 : AxesAndRulesDefaults.xAxisThickness;
164
+ var xAxisTextNumberOfLines = (_7 = props.xAxisTextNumberOfLines) !== null && _7 !== void 0 ? _7 : AxesAndRulesDefaults.xAxisTextNumberOfLines;
165
+ var xAxisLabelsVerticalShift = (_8 = props.xAxisLabelsVerticalShift) !== null && _8 !== void 0 ? _8 : AxesAndRulesDefaults.xAxisLabelsVerticalShift;
166
+ var horizontalRulesStyle = props.horizontalRulesStyle;
167
+ var yAxisLabelWidth = (_9 = props.yAxisLabelWidth) !== null && _9 !== void 0 ? _9 : (props.hideYAxisText
168
+ ? AxesAndRulesDefaults.yAxisEmptyLabelWidth
169
+ : AxesAndRulesDefaults.yAxisLabelWidth);
170
+ var autoShiftLabels = (_10 = props.autoShiftLabels) !== null && _10 !== void 0 ? _10 : false;
171
+ var barWidth = (_11 = props.barWidth) !== null && _11 !== void 0 ? _11 : BarDefaults.barWidth;
172
+ var barBorderColor = (_12 = props.barBorderColor) !== null && _12 !== void 0 ? _12 : BarDefaults.barBorderColor;
173
+ var extendedContainerHeight = getExtendedContainerHeightWithPadding(containerHeight, 0);
174
+ var containerHeightIncludingBelowXAxis = extendedContainerHeight + noOfSectionsBelowXAxis * stepHeight;
175
+ var _50 = __read(useState(-1), 2), pointerIndex = _50[0], setPointerIndex = _50[1];
176
+ var _51 = __read(useState(0), 2), pointerX = _51[0], setPointerX = _51[1];
177
+ var _52 = __read(useState(0), 2), pointerY = _52[0], setPointerY = _52[1];
178
+ var _53 = __read(useState(), 2), pointerItem = _53[0], setPointerItem = _53[1];
179
+ var _54 = __read(useState(0), 2), responderStartTime = _54[0], setResponderStartTime = _54[1];
180
+ var _55 = __read(useState(false), 2), responderActive = _55[0], setResponderActive = _55[1];
181
+ var pointerConfig = props.pointerConfig;
182
+ var getPointerProps = (_13 = props.getPointerProps) !== null && _13 !== void 0 ? _13 : null;
183
+ var pointerHeight = (_14 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.height) !== null && _14 !== void 0 ? _14 : defaultPointerConfig.height;
184
+ var pointerWidth = (_15 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.width) !== null && _15 !== void 0 ? _15 : defaultPointerConfig.width;
185
+ var pointerRadius = (_16 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.radius) !== null && _16 !== void 0 ? _16 : defaultPointerConfig.radius;
186
+ var pointerColor = (_17 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.pointerColor) !== null && _17 !== void 0 ? _17 : defaultPointerConfig.pointerColor;
187
+ var pointerComponent = (_18 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.pointerComponent) !== null && _18 !== void 0 ? _18 : defaultPointerConfig.pointerComponent;
188
+ var showPointerStrip = (pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.showPointerStrip) === false
189
+ ? false
190
+ : defaultPointerConfig.showPointerStrip;
191
+ var pointerStripHeight = (_19 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.pointerStripHeight) !== null && _19 !== void 0 ? _19 : defaultPointerConfig.pointerStripHeight;
192
+ var pointerStripWidth = (_20 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.pointerStripWidth) !== null && _20 !== void 0 ? _20 : defaultPointerConfig.pointerStripWidth;
193
+ var pointerStripColor = (_21 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.pointerStripColor) !== null && _21 !== void 0 ? _21 : defaultPointerConfig.pointerStripColor;
194
+ var pointerStripUptoDataPoint = (_22 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.pointerStripUptoDataPoint) !== null && _22 !== void 0 ? _22 : defaultPointerConfig.pointerStripUptoDataPoint;
195
+ var pointerLabelComponent = (_23 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.pointerLabelComponent) !== null && _23 !== void 0 ? _23 : defaultPointerConfig.pointerLabelComponent;
196
+ var stripOverPointer = (_24 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.stripOverPointer) !== null && _24 !== void 0 ? _24 : defaultPointerConfig.stripOverPointer;
197
+ var shiftPointerLabelX = (_25 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.shiftPointerLabelX) !== null && _25 !== void 0 ? _25 : defaultPointerConfig.shiftPointerLabelX;
198
+ var shiftPointerLabelY = (_26 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.shiftPointerLabelY) !== null && _26 !== void 0 ? _26 : defaultPointerConfig.shiftPointerLabelY;
199
+ var pointerLabelWidth = (_27 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.pointerLabelWidth) !== null && _27 !== void 0 ? _27 : defaultPointerConfig.pointerLabelWidth;
200
+ var pointerLabelHeight = (_28 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.pointerLabelHeight) !== null && _28 !== void 0 ? _28 : defaultPointerConfig.pointerLabelHeight;
201
+ var autoAdjustPointerLabelPosition = (_29 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.autoAdjustPointerLabelPosition) !== null && _29 !== void 0 ? _29 : defaultPointerConfig.autoAdjustPointerLabelPosition;
202
+ var pointerVanishDelay = (_30 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.pointerVanishDelay) !== null && _30 !== void 0 ? _30 : defaultPointerConfig.pointerVanishDelay;
203
+ var activatePointersOnLongPress = (_31 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.activatePointersOnLongPress) !== null && _31 !== void 0 ? _31 : defaultPointerConfig.activatePointersOnLongPress;
204
+ var activatePointersDelay = (_32 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.activatePointersDelay) !== null && _32 !== void 0 ? _32 : defaultPointerConfig.activatePointersDelay;
205
+ var initialPointerIndex = (_33 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.initialPointerIndex) !== null && _33 !== void 0 ? _33 : defaultPointerConfig.initialPointerIndex;
206
+ var initialPointerAppearDelay = (_34 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.initialPointerAppearDelay) !== null && _34 !== void 0 ? _34 : (isAnimated
207
+ ? animationDuration
208
+ : defaultPointerConfig.initialPointerAppearDelay);
209
+ var persistPointer = (_35 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.persistPointer) !== null && _35 !== void 0 ? _35 : defaultPointerConfig.persistPointer;
210
+ var hidePointer1 = (_36 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.hidePointer1) !== null && _36 !== void 0 ? _36 : defaultPointerConfig.hidePointer1;
211
+ var pointerEvents = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.pointerEvents;
212
+ var stripBehindBars = (_37 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.stripBehindBars) !== null && _37 !== void 0 ? _37 : defaultPointerConfig.stripBehindBars;
213
+ var disableScroll = (_38 = props.disableScroll) !== null && _38 !== void 0 ? _38 : (pointerConfig
214
+ ? activatePointersOnLongPress
215
+ ? !!responderActive
216
+ : true
217
+ : false);
218
+ var barInnerComponent = props.barInnerComponent;
219
+ useEffect(function () {
220
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
221
+ if (showLine) {
222
+ var pp = '';
223
+ var pp2 = '';
224
+ var firstBarWidth = (_d = (_c = (_b = ((_a = props.stackData) !== null && _a !== void 0 ? _a : data)) === null || _b === void 0 ? void 0 : _b[0].barWidth) !== null && _c !== void 0 ? _c : props.barWidth) !== null && _d !== void 0 ? _d : 30;
225
+ if (!lineConfig.curved) {
226
+ for (var i = 0; i < lineData.length; i++) {
227
+ if (i < ((_e = lineConfig.startIndex) !== null && _e !== void 0 ? _e : 0) ||
228
+ i > ((_f = lineConfig.endIndex) !== null && _f !== void 0 ? _f : 0)) {
229
+ continue;
230
+ }
231
+ var currentBarWidth = (_j = (_h = (_g = data === null || data === void 0 ? void 0 : data[i]) === null || _g === void 0 ? void 0 : _g.barWidth) !== null && _h !== void 0 ? _h : props.barWidth) !== null && _j !== void 0 ? _j : BarDefaults.barWidth;
232
+ var currentValue = props.lineData
233
+ ? props.lineData[i].value
234
+ : props.stackData
235
+ ? props.stackData[i].stacks.reduce(function (total, item) { return total + item.value; }, 0)
236
+ : data[i].value;
237
+ pp +=
238
+ 'L' +
239
+ getXForLineInBar(i, firstBarWidth, currentBarWidth, yAxisLabelWidth, lineConfig, spacing) +
240
+ ' ' +
241
+ getYForLineInBar(currentValue, lineConfig.shiftY, containerHeight, lineConfig.isSecondary ? secondaryMaxValue : maxValue) +
242
+ ' ';
243
+ }
244
+ setPoints(pp.replace('L', 'M'));
245
+ if (lineData.length > 1 && lineConfig.showArrow) {
246
+ var ppArray = pp.trim().split(' ');
247
+ var arrowTipY = parseInt(ppArray[ppArray.length - 1]);
248
+ var arrowTipX = parseInt(ppArray[ppArray.length - 2].replace('L', ''));
249
+ var y1 = parseInt(ppArray[ppArray.length - 3]);
250
+ var x1 = parseInt(ppArray[ppArray.length - 4].replace('L', ''));
251
+ var arrowPoints_1 = getArrowPoints(arrowTipX, arrowTipY, x1, y1, (_k = lineConfig.arrowConfig) === null || _k === void 0 ? void 0 : _k.length, (_l = lineConfig.arrowConfig) === null || _l === void 0 ? void 0 : _l.width, (_m = lineConfig.arrowConfig) === null || _m === void 0 ? void 0 : _m.showArrowBase);
252
+ setArrowPoints(arrowPoints_1);
253
+ }
254
+ }
255
+ else {
256
+ var p1Array = [];
257
+ for (var i = 0; i < lineData.length; i++) {
258
+ if (i < ((_o = lineConfig.startIndex) !== null && _o !== void 0 ? _o : 0) ||
259
+ i > ((_p = lineConfig.endIndex) !== null && _p !== void 0 ? _p : 0)) {
260
+ continue;
261
+ }
262
+ var currentBarWidth = (_s = (_r = (_q = data === null || data === void 0 ? void 0 : data[i]) === null || _q === void 0 ? void 0 : _q.barWidth) !== null && _r !== void 0 ? _r : props.barWidth) !== null && _s !== void 0 ? _s : BarDefaults.barWidth;
263
+ var currentValue = props.lineData
264
+ ? props.lineData[i].value
265
+ : props.stackData
266
+ ? props.stackData[i].stacks.reduce(function (total, item) { return total + item.value; }, 0)
267
+ : data[i].value;
268
+ p1Array.push([
269
+ getXForLineInBar(i, firstBarWidth, currentBarWidth, yAxisLabelWidth, lineConfig, spacing),
270
+ getYForLineInBar(currentValue, lineConfig.shiftY, containerHeight, lineConfig.isSecondary ? secondaryMaxValue : maxValue)
271
+ ]);
272
+ var xx = svgPath(p1Array, lineConfig.curveType, lineConfig.curvature);
273
+ setPoints(xx);
274
+ }
275
+ }
276
+ if (lineData2 === null || lineData2 === void 0 ? void 0 : lineData2.length) {
277
+ if (!(lineConfig2 === null || lineConfig2 === void 0 ? void 0 : lineConfig2.curved)) {
278
+ for (var i = 0; i < lineData2.length; i++) {
279
+ if (i < ((_t = lineConfig2.startIndex) !== null && _t !== void 0 ? _t : 0) ||
280
+ i > ((_u = lineConfig2.endIndex) !== null && _u !== void 0 ? _u : 0)) {
281
+ continue;
282
+ }
283
+ var currentBarWidth = (_x = (_w = (_v = data === null || data === void 0 ? void 0 : data[i]) === null || _v === void 0 ? void 0 : _v.barWidth) !== null && _w !== void 0 ? _w : props.barWidth) !== null && _x !== void 0 ? _x : BarDefaults.barWidth;
284
+ var currentValue = lineData2[i].value;
285
+ pp2 +=
286
+ 'L' +
287
+ getXForLineInBar(i, firstBarWidth, currentBarWidth, yAxisLabelWidth, lineConfig2, spacing) +
288
+ ' ' +
289
+ getYForLineInBar(currentValue, lineConfig2.shiftY, containerHeight, lineConfig2.isSecondary ? secondaryMaxValue : maxValue) +
290
+ ' ';
291
+ }
292
+ setPoints2(pp2.replace('L', 'M'));
293
+ }
294
+ else {
295
+ var p2Array = [];
296
+ for (var i = 0; i < lineData2.length; i++) {
297
+ if (i < ((_y = lineConfig2.startIndex) !== null && _y !== void 0 ? _y : 0) ||
298
+ i > ((_z = lineConfig2.endIndex) !== null && _z !== void 0 ? _z : 0)) {
299
+ continue;
300
+ }
301
+ var currentBarWidth = (_2 = (_1 = (_0 = data === null || data === void 0 ? void 0 : data[i]) === null || _0 === void 0 ? void 0 : _0.barWidth) !== null && _1 !== void 0 ? _1 : props.barWidth) !== null && _2 !== void 0 ? _2 : BarDefaults.barWidth;
302
+ var currentValue = lineData2[i].value;
303
+ p2Array.push([
304
+ getXForLineInBar(i, firstBarWidth, currentBarWidth, yAxisLabelWidth, lineConfig2, spacing),
305
+ getYForLineInBar(currentValue, lineConfig2.shiftY, containerHeight, lineConfig2.isSecondary ? secondaryMaxValue : maxValue)
306
+ ]);
307
+ var xx = svgPath(p2Array, lineConfig2.curveType, lineConfig2.curvature);
308
+ setPoints2(xx);
309
+ }
310
+ }
311
+ }
312
+ }
313
+ }, [
314
+ animationDuration,
315
+ containerHeight,
316
+ data,
317
+ lineData,
318
+ initialSpacing,
319
+ lineConfig.initialSpacing,
320
+ lineConfig.curved,
321
+ lineConfig.dataPointsWidth,
322
+ lineConfig.shiftY,
323
+ lineConfig.isAnimated,
324
+ lineConfig.delay,
325
+ lineConfig.startIndex,
326
+ lineConfig.endIndex,
327
+ maxValue,
328
+ props.barWidth,
329
+ showLine,
330
+ spacing,
331
+ yAxisLabelWidth,
332
+ lineConfig.showArrow,
333
+ (_39 = lineConfig.arrowConfig) === null || _39 === void 0 ? void 0 : _39.length,
334
+ (_40 = lineConfig.arrowConfig) === null || _40 === void 0 ? void 0 : _40.width,
335
+ (_41 = lineConfig.arrowConfig) === null || _41 === void 0 ? void 0 : _41.showArrowBase
336
+ ]);
337
+ useEffect(function () {
338
+ var _a, _b, _c, _d;
339
+ if (initialPointerIndex !== -1) {
340
+ var item_1 = (_b = ((_a = props.stackData) !== null && _a !== void 0 ? _a : data)) === null || _b === void 0 ? void 0 : _b[initialPointerIndex];
341
+ var stackItem = (_c = props.stackData) === null || _c === void 0 ? void 0 : _c[initialPointerIndex];
342
+ var stackSum = (_d = stackItem === null || stackItem === void 0 ? void 0 : stackItem.stacks) === null || _d === void 0 ? void 0 : _d.reduce(function (acc, stack) { var _a; return acc + ((_a = stack.value) !== null && _a !== void 0 ? _a : 0); }, 0);
343
+ var x_1 = initialSpacing +
344
+ (spacing + barWidth) * initialPointerIndex -
345
+ (pointerRadius !== null && pointerRadius !== void 0 ? pointerRadius : pointerWidth / 2) +
346
+ barWidth / 2;
347
+ var y_1 = containerHeight -
348
+ ((stackSum !== null && stackSum !== void 0 ? stackSum : data[initialPointerIndex].value) * containerHeight) /
349
+ maxValue -
350
+ (pointerRadius !== null && pointerRadius !== void 0 ? pointerRadius : pointerHeight / 2) +
351
+ 10;
352
+ if (initialPointerAppearDelay) {
353
+ setTimeout(function () {
354
+ setPointerConfig(initialPointerIndex, item_1, x_1, y_1);
355
+ }, initialPointerAppearDelay);
356
+ }
357
+ else {
358
+ setPointerConfig(initialPointerIndex, item_1, x_1, y_1);
359
+ }
360
+ }
361
+ }, []);
362
+ var setPointerConfig = function (initialPointerIndex, item, x, y) {
363
+ setPointerIndex(initialPointerIndex);
364
+ setPointerItem(item);
365
+ setPointerX(x);
366
+ setPointerY(y);
367
+ };
368
+ var animatedHeight = heightValue.interpolate({
369
+ inputRange: [0, 1],
370
+ outputRange: ['0%', '100%']
371
+ });
372
+ var appearingOpacity = opacValue.interpolate({
373
+ inputRange: [0, 1],
374
+ outputRange: [0, 1]
375
+ });
376
+ var animatedWidth = widthValue.interpolate({
377
+ inputRange: [0, 1],
378
+ outputRange: [0, initialSpacing + totalWidth + endSpacing]
379
+ });
380
+ var getPropsCommonForBarAndStack = function (item, index) {
381
+ var _a, _b, _c, _d, _e, _f, _g, _h;
382
+ return {
383
+ key: index,
384
+ item: item,
385
+ index: index,
386
+ containerHeight: containerHeight,
387
+ maxValue: maxValue,
388
+ spacing: (_a = item.spacing) !== null && _a !== void 0 ? _a : spacing,
389
+ propSpacing: spacing,
390
+ xAxisThickness: xAxisThickness,
391
+ barWidth: props.barWidth,
392
+ opacity: opacity,
393
+ disablePress: (_b = item.disablePress) !== null && _b !== void 0 ? _b : props.disablePress,
394
+ rotateLabel: rotateLabel,
395
+ showXAxisIndices: showXAxisIndices,
396
+ xAxisIndicesHeight: xAxisIndicesHeight,
397
+ xAxisIndicesWidth: xAxisIndicesWidth,
398
+ xAxisIndicesColor: xAxisIndicesColor,
399
+ horizontal: horizontal,
400
+ rtl: rtl,
401
+ intactTopLabel: intactTopLabel,
402
+ showValuesAsTopLabel: props.showValuesAsTopLabel,
403
+ topLabelContainerStyle: props.topLabelContainerStyle,
404
+ topLabelTextStyle: props.topLabelTextStyle,
405
+ barBorderWidth: props.barBorderWidth,
406
+ barBorderColor: barBorderColor,
407
+ barBorderRadius: props.barBorderRadius,
408
+ barBorderTopLeftRadius: props.barBorderTopLeftRadius,
409
+ barBorderTopRightRadius: props.barBorderTopRightRadius,
410
+ barBorderBottomLeftRadius: props.barBorderBottomLeftRadius,
411
+ barBorderBottomRightRadius: props.barBorderBottomRightRadius,
412
+ barInnerComponent: barInnerComponent,
413
+ color: props.color,
414
+ showGradient: props.showGradient,
415
+ gradientColor: props.gradientColor,
416
+ barBackgroundPattern: props.barBackgroundPattern,
417
+ patternId: props.patternId,
418
+ onPress: props.onPress,
419
+ onLongPress: props.onLongPress,
420
+ onPressOut: props.onPressOut,
421
+ focusBarOnPress: props.focusBarOnPress,
422
+ focusedBarConfig: props.focusedBarConfig,
423
+ xAxisTextNumberOfLines: xAxisTextNumberOfLines,
424
+ xAxisLabelsHeight: props.xAxisLabelsHeight,
425
+ xAxisLabelsVerticalShift: xAxisLabelsVerticalShift,
426
+ renderTooltip: props.renderTooltip,
427
+ leftShiftForTooltip: (_c = props.leftShiftForTooltip) !== null && _c !== void 0 ? _c : 0,
428
+ initialSpacing: initialSpacing,
429
+ selectedIndex: selectedIndex,
430
+ setSelectedIndex: setSelectedIndex,
431
+ activeOpacity: (_d = props.activeOpacity) !== null && _d !== void 0 ? _d : 0.2,
432
+ noOfSectionsBelowXAxis: noOfSectionsBelowXAxis,
433
+ leftShiftForLastIndexTooltip: (_e = props.leftShiftForLastIndexTooltip) !== null && _e !== void 0 ? _e : 0,
434
+ label: (_f = item.label) !== null && _f !== void 0 ? _f : (((_g = props.xAxisLabelTexts) === null || _g === void 0 ? void 0 : _g[index]) ? props.xAxisLabelTexts[index] : ''),
435
+ labelTextStyle: (_h = item.labelTextStyle) !== null && _h !== void 0 ? _h : props.xAxisLabelTextStyle,
436
+ pointerConfig: pointerConfig
437
+ };
438
+ };
439
+ var barAndLineChartsWrapperProps = {
440
+ chartType: chartTypes.BAR,
441
+ containerHeight: containerHeight,
442
+ noOfSectionsBelowXAxis: noOfSectionsBelowXAxis,
443
+ stepHeight: stepHeight,
444
+ labelsExtraHeight: labelsExtraHeight,
445
+ yAxisLabelWidth: yAxisLabelWidth,
446
+ horizontal: horizontal,
447
+ rtl: rtl,
448
+ shiftX: (_42 = props.shiftX) !== null && _42 !== void 0 ? _42 : 0,
449
+ shiftY: (_43 = props.shiftY) !== null && _43 !== void 0 ? _43 : 0,
450
+ yAxisAtTop: yAxisAtTop,
451
+ initialSpacing: initialSpacing,
452
+ data: data,
453
+ stackData: props.stackData,
454
+ secondaryData: secondaryData,
455
+ barWidth: (_44 = props.barWidth) !== null && _44 !== void 0 ? _44 : BarDefaults.barWidth,
456
+ xAxisThickness: xAxisThickness,
457
+ totalWidth: totalWidth,
458
+ disableScroll: disableScroll,
459
+ showScrollIndicator: showScrollIndicator,
460
+ scrollToEnd: scrollToEnd,
461
+ scrollToIndex: props.scrollToIndex,
462
+ scrollAnimation: scrollAnimation,
463
+ scrollEventThrottle: scrollEventThrottle,
464
+ indicatorColor: props.indicatorColor,
465
+ setSelectedIndex: setSelectedIndex,
466
+ spacing: spacing,
467
+ showLine: showLine,
468
+ lineConfig: lineConfig,
469
+ lineConfig2: lineConfig2,
470
+ maxValue: maxValue,
471
+ lineData: lineData,
472
+ lineData2: lineData2,
473
+ animatedWidth: animatedWidth,
474
+ lineBehindBars: lineBehindBars,
475
+ points: points,
476
+ points2: points2,
477
+ arrowPoints: arrowPoints,
478
+ // horizSectionProps-
479
+ width: widthFromProps,
480
+ horizSections: horizSections,
481
+ endSpacing: endSpacing,
482
+ horizontalRulesStyle: horizontalRulesStyle,
483
+ noOfSections: noOfSections,
484
+ showFractionalValues: showFractionalValues,
485
+ axesAndRulesProps: getAxesAndRulesProps(props, stepValue, secondaryMaxValue),
486
+ yAxisLabelTexts: props.yAxisLabelTexts,
487
+ yAxisOffset: props.yAxisOffset,
488
+ rotateYAxisTexts: props.rotateYAxisTexts,
489
+ hideAxesAndRules: props.hideAxesAndRules,
490
+ showXAxisIndices: showXAxisIndices,
491
+ xAxisIndicesHeight: xAxisIndicesHeight,
492
+ xAxisIndicesWidth: xAxisIndicesWidth,
493
+ xAxisIndicesColor: xAxisIndicesColor,
494
+ // These are Not needed but passing this prop to maintain consistency (between LineChart and BarChart props)
495
+ pointerConfig: pointerConfig,
496
+ getPointerProps: getPointerProps,
497
+ pointerIndex: pointerIndex,
498
+ pointerX: pointerX,
499
+ pointerY: pointerY,
500
+ onEndReached: props.onEndReached,
501
+ onStartReached: props.onStartReached,
502
+ endReachedOffset: (_45 = props.endReachedOffset) !== null && _45 !== void 0 ? _45 : BarDefaults.endReachedOffset
503
+ };
504
+ return {
505
+ lineConfig: lineConfig,
506
+ hidePointer1: hidePointer1,
507
+ pointerItem: pointerItem,
508
+ pointerY: pointerY,
509
+ pointerConfig: pointerConfig,
510
+ pointerColor: pointerColor,
511
+ pointerX: pointerX,
512
+ pointerComponent: pointerComponent,
513
+ pointerHeight: pointerHeight,
514
+ pointerRadius: pointerRadius,
515
+ pointerWidth: pointerWidth,
516
+ autoAdjustPointerLabelPosition: autoAdjustPointerLabelPosition,
517
+ pointerLabelWidth: pointerLabelWidth,
518
+ activatePointersOnLongPress: activatePointersOnLongPress,
519
+ yAxisLabelWidth: yAxisLabelWidth,
520
+ shiftPointerLabelX: shiftPointerLabelX,
521
+ pointerLabelHeight: pointerLabelHeight,
522
+ pointerStripUptoDataPoint: pointerStripUptoDataPoint,
523
+ pointerStripHeight: pointerStripHeight,
524
+ shiftPointerLabelY: shiftPointerLabelY,
525
+ showPointerStrip: showPointerStrip,
526
+ pointerStripWidth: pointerStripWidth,
527
+ containerHeight: containerHeight,
528
+ xAxisThickness: xAxisThickness,
529
+ pointerStripColor: pointerStripColor,
530
+ pointerEvents: pointerEvents,
531
+ setResponderStartTime: setResponderStartTime,
532
+ setPointerY: setPointerY,
533
+ setPointerItem: setPointerItem,
534
+ initialSpacing: initialSpacing,
535
+ spacing: spacing,
536
+ data: data,
537
+ barWidth: barWidth,
538
+ setPointerX: setPointerX,
539
+ setPointerIndex: setPointerIndex,
540
+ maxValue: maxValue,
541
+ responderStartTime: responderStartTime,
542
+ responderActive: responderActive,
543
+ setResponderActive: setResponderActive,
544
+ activatePointersDelay: activatePointersDelay,
545
+ persistPointer: persistPointer,
546
+ pointerVanishDelay: pointerVanishDelay,
547
+ containerHeightIncludingBelowXAxis: containerHeightIncludingBelowXAxis,
548
+ extendedContainerHeight: extendedContainerHeight,
549
+ totalWidth: totalWidth,
550
+ stripBehindBars: stripBehindBars,
551
+ noOfSectionsBelowXAxis: noOfSectionsBelowXAxis,
552
+ stepHeight: stepHeight,
553
+ xAxisLabelsVerticalShift: xAxisLabelsVerticalShift,
554
+ labelsExtraHeight: labelsExtraHeight,
555
+ stripOverPointer: stripOverPointer,
556
+ pointerLabelComponent: pointerLabelComponent,
557
+ opacity: opacity,
558
+ rotateLabel: rotateLabel,
559
+ showXAxisIndices: showXAxisIndices,
560
+ xAxisIndicesHeight: xAxisIndicesHeight,
561
+ xAxisIndicesWidth: xAxisIndicesWidth,
562
+ xAxisIndicesColor: xAxisIndicesColor,
563
+ horizontal: horizontal,
564
+ rtl: rtl,
565
+ intactTopLabel: intactTopLabel,
566
+ barBorderColor: barBorderColor,
567
+ barInnerComponent: barInnerComponent,
568
+ xAxisTextNumberOfLines: xAxisTextNumberOfLines,
569
+ selectedIndex: selectedIndex,
570
+ setSelectedIndex: setSelectedIndex,
571
+ isAnimated: isAnimated,
572
+ animationDuration: animationDuration,
573
+ side: side,
574
+ labelWidth: labelWidth,
575
+ isThreeD: isThreeD,
576
+ animatedHeight: animatedHeight,
577
+ appearingOpacity: appearingOpacity,
578
+ autoShiftLabels: autoShiftLabels,
579
+ yAxisAtTop: yAxisAtTop,
580
+ secondaryData: secondaryData,
581
+ disableScroll: disableScroll,
582
+ showScrollIndicator: showScrollIndicator,
583
+ scrollToEnd: scrollToEnd,
584
+ scrollAnimation: scrollAnimation,
585
+ scrollEventThrottle: scrollEventThrottle,
586
+ showLine: showLine,
587
+ lineConfig2: lineConfig2,
588
+ lineData: lineData,
589
+ lineData2: lineData2,
590
+ animatedWidth: animatedWidth,
591
+ lineBehindBars: lineBehindBars,
592
+ points: points,
593
+ setPoints: setPoints,
594
+ points2: points2,
595
+ setPoints2: setPoints2,
596
+ arrowPoints: arrowPoints,
597
+ setArrowPoints: setArrowPoints,
598
+ horizSections: horizSections,
599
+ endSpacing: endSpacing,
600
+ horizontalRulesStyle: horizontalRulesStyle,
601
+ noOfSections: noOfSections,
602
+ showFractionalValues: showFractionalValues,
603
+ widthFromProps: widthFromProps,
604
+ stepValue: stepValue,
605
+ secondaryMaxValue: secondaryMaxValue,
606
+ getPointerProps: getPointerProps,
607
+ pointerIndex: pointerIndex,
608
+ getPropsCommonForBarAndStack: getPropsCommonForBarAndStack,
609
+ barAndLineChartsWrapperProps: barAndLineChartsWrapperProps
610
+ };
611
+ };