react-native-gifted-charts 1.3.33 → 1.4.1
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.
- package/README.md +9 -2
- package/package.json +2 -1
- package/src/BarChart/Animated2DWithGradient.tsx +13 -154
- package/src/BarChart/RenderBars.tsx +29 -179
- package/src/BarChart/RenderStackBars.tsx +22 -104
- package/src/BarChart/index.tsx +87 -686
- package/src/Components/AnimatedThreeDBar/index.tsx +16 -48
- package/src/Components/BarAndLineChartsWrapper/index.tsx +38 -283
- package/src/Components/BarAndLineChartsWrapper/renderHorizSections.tsx +17 -339
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.tsx +147 -0
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.tsx +157 -0
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.tsx +86 -0
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.tsx +42 -0
- package/src/Components/BarAndLineChartsWrapper/renderVerticalLines.tsx +1 -1
- package/src/Components/BarSpecificComponents/cap.tsx +1 -1
- package/src/Components/common/StripAndLabel.tsx +3 -56
- package/src/Components/lineSvg.tsx +1 -1
- package/src/LineChart/LineChartBicolor.tsx +80 -516
- package/src/LineChart/index.tsx +266 -1778
- package/src/PieChart/index.tsx +20 -84
- package/src/PieChart/main.tsx +47 -119
- package/src/PopulationPyramid/index.tsx +90 -203
- package/src/index.tsx +7 -12
- package/src/BarChart/types.ts +0 -394
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart.tsx +0 -402
- package/src/LineChart/types.ts +0 -575
- package/src/PieChart/types.ts +0 -77
- package/src/PopulationPyramid/types.ts +0 -200
- package/src/utils/constants.ts +0 -333
- package/src/utils/index.tsx +0 -1137
- package/src/utils/types.ts +0 -360
package/src/BarChart/index.tsx
CHANGED
|
@@ -1,330 +1,94 @@
|
|
|
1
|
-
import React, {useCallback, useEffect, useMemo,
|
|
1
|
+
import React, {useCallback, useEffect, useMemo, useRef} from 'react';
|
|
2
2
|
import {Animated, Easing, View} from 'react-native';
|
|
3
3
|
import RenderBars from './RenderBars';
|
|
4
4
|
import RenderStackBars from './RenderStackBars';
|
|
5
|
+
import BarAndLineChartsWrapper from '../Components/BarAndLineChartsWrapper';
|
|
5
6
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
getExtendedContainerHeightWithPadding,
|
|
9
|
-
getLineConfigForBarChart,
|
|
10
|
-
getSecondaryDataWithOffsetIncluded,
|
|
11
|
-
getXForLineInBar,
|
|
12
|
-
getYForLineInBar,
|
|
13
|
-
maxAndMinUtil,
|
|
14
|
-
svgPath,
|
|
15
|
-
} from '../utils';
|
|
16
|
-
import {
|
|
17
|
-
AxesAndRulesDefaults,
|
|
18
|
-
BarDefaults,
|
|
19
|
-
chartTypes,
|
|
20
|
-
defaultLineConfig,
|
|
21
|
-
defaultPointerConfig,
|
|
7
|
+
BarChartPropsType,
|
|
8
|
+
useBarChart,
|
|
22
9
|
screenWidth,
|
|
23
|
-
} from '
|
|
24
|
-
import BarAndLineChartsWrapper from '../Components/BarAndLineChartsWrapper';
|
|
25
|
-
import {BarChartPropsType, barDataItem} from './types';
|
|
26
|
-
import {BarAndLineChartsWrapperTypes} from '../utils/types';
|
|
10
|
+
} from 'gifted-charts-core';
|
|
27
11
|
import {StripAndLabel} from '../Components/common/StripAndLabel';
|
|
28
12
|
import {Pointer} from '../Components/common/Pointer';
|
|
29
13
|
|
|
30
14
|
export const BarChart = (props: BarChartPropsType) => {
|
|
31
|
-
const scrollRef = props.scrollRef ?? useRef(null);
|
|
32
|
-
const [points, setPoints] = useState('');
|
|
33
|
-
const [points2, setPoints2] = useState('');
|
|
34
|
-
const [arrowPoints, setArrowPoints] = useState('');
|
|
35
|
-
const [selectedIndex, setSelectedIndex] = useState(-1);
|
|
36
|
-
const showLine = props.showLine || BarDefaults.showLine;
|
|
37
|
-
const spacing = props.spacing ?? BarDefaults.spacing;
|
|
38
|
-
const initialSpacing = props.initialSpacing ?? spacing;
|
|
39
|
-
const endSpacing = props.endSpacing ?? spacing;
|
|
40
|
-
const showFractionalValues =
|
|
41
|
-
props.showFractionalValues || AxesAndRulesDefaults.showFractionalValues;
|
|
42
|
-
|
|
43
|
-
const horizontal = props.horizontal ?? BarDefaults.horizontal;
|
|
44
|
-
const rtl = props.rtl ?? BarDefaults.rtl;
|
|
45
|
-
const yAxisAtTop = props.yAxisAtTop ?? BarDefaults.yAxisAtTop;
|
|
46
|
-
const intactTopLabel = props.intactTopLabel ?? BarDefaults.intactTopLabel;
|
|
47
|
-
|
|
48
|
-
const heightFromProps = horizontal ? props.width : props.height;
|
|
49
|
-
const widthFromProps = horizontal ? props.height : props.width;
|
|
50
|
-
|
|
51
|
-
const isAnimated = props.isAnimated ?? BarDefaults.isAnimated;
|
|
52
|
-
const animationDuration =
|
|
53
|
-
props.animationDuration ?? BarDefaults.animationDuration;
|
|
54
|
-
|
|
55
|
-
const data = useMemo(() => {
|
|
56
|
-
if (!props.data) {
|
|
57
|
-
return [];
|
|
58
|
-
}
|
|
59
|
-
if (props.yAxisOffset) {
|
|
60
|
-
return props.data.map(item => {
|
|
61
|
-
item.value = item.value - (props.yAxisOffset ?? 0);
|
|
62
|
-
return item;
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
return props.data;
|
|
66
|
-
}, [props.yAxisOffset, props.data]);
|
|
67
|
-
|
|
68
|
-
const secondaryData = getSecondaryDataWithOffsetIncluded(
|
|
69
|
-
props.secondaryData,
|
|
70
|
-
props.secondaryYAxis,
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
const lineData = useMemo(() => {
|
|
74
|
-
if (!props.lineData) {
|
|
75
|
-
return props.stackData ?? data;
|
|
76
|
-
}
|
|
77
|
-
if (props.yAxisOffset) {
|
|
78
|
-
return props.lineData.map(item => {
|
|
79
|
-
item.value = item.value - (props.yAxisOffset ?? 0);
|
|
80
|
-
return item;
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
return props.lineData;
|
|
84
|
-
}, [props.yAxisOffset, props.lineData, data, props.stackData]);
|
|
85
|
-
|
|
86
|
-
const lineData2 = props.lineData2;
|
|
87
|
-
|
|
88
|
-
const lineBehindBars = props.lineBehindBars || BarDefaults.lineBehindBars;
|
|
89
|
-
|
|
90
|
-
defaultLineConfig.initialSpacing = initialSpacing;
|
|
91
|
-
defaultLineConfig.endIndex = lineData.length - 1;
|
|
92
|
-
defaultLineConfig.animationDuration = animationDuration;
|
|
93
|
-
|
|
94
|
-
const lineConfig = props.lineConfig
|
|
95
|
-
? getLineConfigForBarChart(props.lineConfig, initialSpacing)
|
|
96
|
-
: defaultLineConfig;
|
|
97
|
-
const lineConfig2 = props.lineConfig2
|
|
98
|
-
? getLineConfigForBarChart(props.lineConfig2, initialSpacing)
|
|
99
|
-
: defaultLineConfig;
|
|
100
|
-
const noOfSections = props.noOfSections ?? AxesAndRulesDefaults.noOfSections;
|
|
101
|
-
const containerHeight =
|
|
102
|
-
heightFromProps ??
|
|
103
|
-
((props.stepHeight ?? 0) * noOfSections ||
|
|
104
|
-
AxesAndRulesDefaults.containerHeight);
|
|
105
|
-
const horizSections = [{value: '0'}];
|
|
106
|
-
const stepHeight = props.stepHeight ?? containerHeight / noOfSections;
|
|
107
|
-
const labelWidth = props.labelWidth ?? AxesAndRulesDefaults.labelWidth;
|
|
108
|
-
const scrollToEnd = props.scrollToEnd ?? BarDefaults.scrollToEnd;
|
|
109
|
-
const scrollAnimation = props.scrollAnimation ?? BarDefaults.scrollAnimation;
|
|
110
|
-
const scrollEventThrottle =
|
|
111
|
-
props.scrollEventThrottle ?? BarDefaults.scrollEventThrottle;
|
|
112
|
-
const labelsExtraHeight =
|
|
113
|
-
props.labelsExtraHeight ?? AxesAndRulesDefaults.labelsExtraHeight;
|
|
114
|
-
|
|
115
|
-
let totalWidth = initialSpacing;
|
|
116
|
-
let maxItem = 0,
|
|
117
|
-
minItem = 0;
|
|
118
|
-
if (props.stackData) {
|
|
119
|
-
props.stackData.forEach(stackItem => {
|
|
120
|
-
const stackSumMax = stackItem.stacks.reduce(
|
|
121
|
-
(acc, stack) => acc + (stack.value >= 0 ? stack.value : 0),
|
|
122
|
-
0,
|
|
123
|
-
);
|
|
124
|
-
const stackSumMin = stackItem.stacks.reduce(
|
|
125
|
-
(acc, stack) => acc + (stack.value < 0 ? stack.value : 0),
|
|
126
|
-
0,
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
if (stackSumMax > maxItem) {
|
|
130
|
-
maxItem = stackSumMax;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (stackSumMin < minItem) {
|
|
134
|
-
minItem = stackSumMin;
|
|
135
|
-
}
|
|
136
|
-
totalWidth +=
|
|
137
|
-
(stackItem.stacks[0].barWidth ??
|
|
138
|
-
props.barWidth ??
|
|
139
|
-
BarDefaults.barWidth) + spacing;
|
|
140
|
-
});
|
|
141
|
-
} else {
|
|
142
|
-
data.forEach((item: barDataItem) => {
|
|
143
|
-
if (item.value > maxItem) {
|
|
144
|
-
maxItem = item.value;
|
|
145
|
-
}
|
|
146
|
-
if (item.value < minItem) {
|
|
147
|
-
minItem = item.value;
|
|
148
|
-
}
|
|
149
|
-
totalWidth +=
|
|
150
|
-
(item.barWidth ?? props.barWidth ?? BarDefaults.barWidth) +
|
|
151
|
-
(item.spacing ?? spacing);
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
let secondaryMaxItem = 0,
|
|
156
|
-
secondaryMinItem = 0;
|
|
157
|
-
|
|
158
|
-
if (lineConfig.isSecondary) {
|
|
159
|
-
lineData.forEach((item: barDataItem) => {
|
|
160
|
-
if (item.value > secondaryMaxItem) {
|
|
161
|
-
secondaryMaxItem = item.value;
|
|
162
|
-
}
|
|
163
|
-
if (item.value < secondaryMinItem) {
|
|
164
|
-
secondaryMinItem = item.value;
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const maxAndMin = maxAndMinUtil(
|
|
170
|
-
maxItem,
|
|
171
|
-
minItem,
|
|
172
|
-
props.roundToDigits,
|
|
173
|
-
props.showFractionalValues,
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
const secondaryMaxAndMin = maxAndMinUtil(
|
|
177
|
-
secondaryMaxItem,
|
|
178
|
-
secondaryMinItem,
|
|
179
|
-
props.roundToDigits,
|
|
180
|
-
props.showFractionalValues,
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
const maxValue = props.maxValue ?? maxAndMin.maxItem;
|
|
184
|
-
const secondaryMaxValue = lineConfig.isSecondary
|
|
185
|
-
? secondaryMaxAndMin.maxItem
|
|
186
|
-
: maxValue;
|
|
187
|
-
const mostNegativeValue = props.mostNegativeValue ?? maxAndMin.minItem;
|
|
188
|
-
|
|
189
|
-
const stepValue = props.stepValue ?? maxValue / noOfSections;
|
|
190
|
-
const noOfSectionsBelowXAxis =
|
|
191
|
-
props.noOfSectionsBelowXAxis ?? -mostNegativeValue / stepValue;
|
|
192
|
-
const showScrollIndicator =
|
|
193
|
-
props.showScrollIndicator ?? BarDefaults.showScrollIndicator;
|
|
194
|
-
const side = props.side ?? BarDefaults.side;
|
|
195
|
-
const rotateLabel = props.rotateLabel ?? AxesAndRulesDefaults.rotateLabel;
|
|
196
|
-
const opacity = props.opacity ?? BarDefaults.opacity;
|
|
197
|
-
const isThreeD = props.isThreeD ?? BarDefaults.isThreeD;
|
|
198
|
-
|
|
199
|
-
const showXAxisIndices =
|
|
200
|
-
props.showXAxisIndices ?? AxesAndRulesDefaults.showXAxisIndices;
|
|
201
|
-
const xAxisIndicesHeight =
|
|
202
|
-
props.xAxisIndicesHeight ?? AxesAndRulesDefaults.xAxisIndicesHeight;
|
|
203
|
-
const xAxisIndicesWidth =
|
|
204
|
-
props.xAxisIndicesWidth ?? AxesAndRulesDefaults.xAxisIndicesWidth;
|
|
205
|
-
const xAxisIndicesColor =
|
|
206
|
-
props.xAxisIndicesColor ?? AxesAndRulesDefaults.xAxisIndicesColor;
|
|
207
|
-
|
|
208
|
-
const xAxisThickness =
|
|
209
|
-
props.xAxisThickness ?? AxesAndRulesDefaults.xAxisThickness;
|
|
210
|
-
|
|
211
|
-
const xAxisTextNumberOfLines =
|
|
212
|
-
props.xAxisTextNumberOfLines ?? AxesAndRulesDefaults.xAxisTextNumberOfLines;
|
|
213
|
-
const xAxisLabelsVerticalShift =
|
|
214
|
-
props.xAxisLabelsVerticalShift ??
|
|
215
|
-
AxesAndRulesDefaults.xAxisLabelsVerticalShift;
|
|
216
|
-
const horizontalRulesStyle = props.horizontalRulesStyle;
|
|
217
|
-
const yAxisLabelWidth =
|
|
218
|
-
props.yAxisLabelWidth ??
|
|
219
|
-
(props.hideYAxisText
|
|
220
|
-
? AxesAndRulesDefaults.yAxisEmptyLabelWidth
|
|
221
|
-
: AxesAndRulesDefaults.yAxisLabelWidth);
|
|
222
|
-
|
|
223
15
|
const heightValue = useMemo(() => new Animated.Value(0), []);
|
|
224
16
|
const opacValue = useMemo(() => new Animated.Value(0), []);
|
|
225
17
|
const widthValue = useMemo(() => new Animated.Value(0), []);
|
|
226
|
-
const autoShiftLabels = props.autoShiftLabels ?? false;
|
|
227
18
|
|
|
228
|
-
const
|
|
229
|
-
const
|
|
19
|
+
const scrollRef = props.scrollRef ?? useRef(null);
|
|
20
|
+
const remainingScrollViewProps = {
|
|
21
|
+
onTouchStart: evt => {
|
|
22
|
+
if (props.renderTooltip) {
|
|
23
|
+
setSelectedIndex(-1);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
};
|
|
230
27
|
|
|
231
|
-
const
|
|
28
|
+
const {
|
|
29
|
+
lineConfig,
|
|
30
|
+
hidePointer1,
|
|
31
|
+
pointerItem,
|
|
32
|
+
pointerY,
|
|
33
|
+
pointerConfig,
|
|
34
|
+
pointerColor,
|
|
35
|
+
pointerX,
|
|
36
|
+
pointerComponent,
|
|
37
|
+
pointerHeight,
|
|
38
|
+
pointerRadius,
|
|
39
|
+
pointerWidth,
|
|
40
|
+
autoAdjustPointerLabelPosition,
|
|
41
|
+
pointerLabelWidth,
|
|
42
|
+
activatePointersOnLongPress,
|
|
43
|
+
yAxisLabelWidth,
|
|
44
|
+
shiftPointerLabelX,
|
|
45
|
+
pointerLabelHeight,
|
|
46
|
+
pointerStripUptoDataPoint,
|
|
47
|
+
pointerStripHeight,
|
|
48
|
+
shiftPointerLabelY,
|
|
49
|
+
showPointerStrip,
|
|
50
|
+
pointerStripWidth,
|
|
232
51
|
containerHeight,
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
const pointerLabelComponent =
|
|
274
|
-
pointerConfig?.pointerLabelComponent ??
|
|
275
|
-
defaultPointerConfig.pointerLabelComponent;
|
|
276
|
-
const stripOverPointer =
|
|
277
|
-
pointerConfig?.stripOverPointer ?? defaultPointerConfig.stripOverPointer;
|
|
278
|
-
const shiftPointerLabelX =
|
|
279
|
-
pointerConfig?.shiftPointerLabelX ??
|
|
280
|
-
defaultPointerConfig.shiftPointerLabelX;
|
|
281
|
-
const shiftPointerLabelY =
|
|
282
|
-
pointerConfig?.shiftPointerLabelY ??
|
|
283
|
-
defaultPointerConfig.shiftPointerLabelY;
|
|
284
|
-
const pointerLabelWidth =
|
|
285
|
-
pointerConfig?.pointerLabelWidth ?? defaultPointerConfig.pointerLabelWidth;
|
|
286
|
-
const pointerLabelHeight =
|
|
287
|
-
pointerConfig?.pointerLabelHeight ??
|
|
288
|
-
defaultPointerConfig.pointerLabelHeight;
|
|
289
|
-
const autoAdjustPointerLabelPosition =
|
|
290
|
-
pointerConfig?.autoAdjustPointerLabelPosition ??
|
|
291
|
-
defaultPointerConfig.autoAdjustPointerLabelPosition;
|
|
292
|
-
const pointerVanishDelay =
|
|
293
|
-
pointerConfig?.pointerVanishDelay ??
|
|
294
|
-
defaultPointerConfig.pointerVanishDelay;
|
|
295
|
-
const activatePointersOnLongPress =
|
|
296
|
-
pointerConfig?.activatePointersOnLongPress ??
|
|
297
|
-
defaultPointerConfig.activatePointersOnLongPress;
|
|
298
|
-
const activatePointersDelay =
|
|
299
|
-
pointerConfig?.activatePointersDelay ??
|
|
300
|
-
defaultPointerConfig.activatePointersDelay;
|
|
301
|
-
const initialPointerIndex =
|
|
302
|
-
pointerConfig?.initialPointerIndex ??
|
|
303
|
-
defaultPointerConfig.initialPointerIndex;
|
|
304
|
-
const initialPointerAppearDelay =
|
|
305
|
-
pointerConfig?.initialPointerAppearDelay ??
|
|
306
|
-
(isAnimated
|
|
307
|
-
? animationDuration
|
|
308
|
-
: defaultPointerConfig.initialPointerAppearDelay);
|
|
309
|
-
const persistPointer =
|
|
310
|
-
pointerConfig?.persistPointer ?? defaultPointerConfig.persistPointer;
|
|
311
|
-
const hidePointer1 =
|
|
312
|
-
pointerConfig?.hidePointer1 ?? defaultPointerConfig.hidePointer1;
|
|
313
|
-
const pointerEvents = pointerConfig?.pointerEvents;
|
|
314
|
-
const stripBehindBars =
|
|
315
|
-
pointerConfig?.stripBehindBars ?? defaultPointerConfig.stripBehindBars;
|
|
316
|
-
|
|
317
|
-
const disableScroll =
|
|
318
|
-
props.disableScroll ||
|
|
319
|
-
(pointerConfig
|
|
320
|
-
? activatePointersOnLongPress
|
|
321
|
-
? responderActive
|
|
322
|
-
? true
|
|
323
|
-
: false
|
|
324
|
-
: true
|
|
325
|
-
: false);
|
|
326
|
-
|
|
327
|
-
const barInnerComponent = props.barInnerComponent;
|
|
52
|
+
xAxisThickness,
|
|
53
|
+
pointerStripColor,
|
|
54
|
+
pointerEvents,
|
|
55
|
+
setResponderStartTime,
|
|
56
|
+
setPointerY,
|
|
57
|
+
setPointerItem,
|
|
58
|
+
initialSpacing,
|
|
59
|
+
spacing,
|
|
60
|
+
data,
|
|
61
|
+
barWidth,
|
|
62
|
+
setPointerX,
|
|
63
|
+
setPointerIndex,
|
|
64
|
+
maxValue,
|
|
65
|
+
responderStartTime,
|
|
66
|
+
setResponderActive,
|
|
67
|
+
activatePointersDelay,
|
|
68
|
+
persistPointer,
|
|
69
|
+
pointerVanishDelay,
|
|
70
|
+
containerHeightIncludingBelowXAxis,
|
|
71
|
+
extendedContainerHeight,
|
|
72
|
+
totalWidth,
|
|
73
|
+
stripBehindBars,
|
|
74
|
+
noOfSectionsBelowXAxis,
|
|
75
|
+
stepHeight,
|
|
76
|
+
xAxisLabelsVerticalShift,
|
|
77
|
+
labelsExtraHeight,
|
|
78
|
+
stripOverPointer,
|
|
79
|
+
pointerLabelComponent,
|
|
80
|
+
setSelectedIndex,
|
|
81
|
+
isAnimated,
|
|
82
|
+
animationDuration,
|
|
83
|
+
side,
|
|
84
|
+
labelWidth,
|
|
85
|
+
isThreeD,
|
|
86
|
+
animatedHeight,
|
|
87
|
+
appearingOpacity,
|
|
88
|
+
autoShiftLabels,
|
|
89
|
+
getPropsCommonForBarAndStack,
|
|
90
|
+
barAndLineChartsWrapperProps,
|
|
91
|
+
} = useBarChart({...props, heightValue, widthValue, opacValue});
|
|
328
92
|
|
|
329
93
|
const labelsAppear = useCallback(() => {
|
|
330
94
|
opacValue.setValue(0);
|
|
@@ -347,240 +111,11 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
347
111
|
}, [lineConfig.animationDuration, widthValue]);
|
|
348
112
|
|
|
349
113
|
useEffect(() => {
|
|
350
|
-
if (
|
|
351
|
-
|
|
352
|
-
pp2 = '';
|
|
353
|
-
const firstBarWidth =
|
|
354
|
-
(props.stackData ?? data)?.[0].barWidth ?? props.barWidth ?? 30;
|
|
355
|
-
if (!lineConfig.curved) {
|
|
356
|
-
for (let i = 0; i < lineData.length; i++) {
|
|
357
|
-
if (i < lineConfig.startIndex || i > lineConfig.endIndex) continue;
|
|
358
|
-
const currentBarWidth =
|
|
359
|
-
data?.[i]?.barWidth ?? props.barWidth ?? BarDefaults.barWidth;
|
|
360
|
-
const currentValue = props.lineData
|
|
361
|
-
? props.lineData[i].value
|
|
362
|
-
: props.stackData
|
|
363
|
-
? props.stackData[i].stacks.reduce(
|
|
364
|
-
(total, item) => total + item.value,
|
|
365
|
-
0,
|
|
366
|
-
)
|
|
367
|
-
: data[i].value;
|
|
368
|
-
pp +=
|
|
369
|
-
'L' +
|
|
370
|
-
getXForLineInBar(
|
|
371
|
-
i,
|
|
372
|
-
firstBarWidth,
|
|
373
|
-
currentBarWidth,
|
|
374
|
-
yAxisLabelWidth,
|
|
375
|
-
lineConfig,
|
|
376
|
-
spacing,
|
|
377
|
-
) +
|
|
378
|
-
' ' +
|
|
379
|
-
getYForLineInBar(
|
|
380
|
-
currentValue,
|
|
381
|
-
lineConfig.shiftY,
|
|
382
|
-
containerHeight,
|
|
383
|
-
lineConfig.isSecondary ? secondaryMaxValue : maxValue,
|
|
384
|
-
) +
|
|
385
|
-
' ';
|
|
386
|
-
}
|
|
387
|
-
setPoints(pp.replace('L', 'M'));
|
|
388
|
-
if (lineData.length > 1 && lineConfig.showArrow) {
|
|
389
|
-
let ppArray = pp.trim().split(' ');
|
|
390
|
-
let arrowTipY = parseInt(ppArray[ppArray.length - 1]);
|
|
391
|
-
let arrowTipX = parseInt(
|
|
392
|
-
ppArray[ppArray.length - 2].replace('L', ''),
|
|
393
|
-
);
|
|
394
|
-
let y1 = parseInt(ppArray[ppArray.length - 3]);
|
|
395
|
-
let x1 = parseInt(ppArray[ppArray.length - 4].replace('L', ''));
|
|
396
|
-
|
|
397
|
-
let arrowPoints = getArrowPoints(
|
|
398
|
-
arrowTipX,
|
|
399
|
-
arrowTipY,
|
|
400
|
-
x1,
|
|
401
|
-
y1,
|
|
402
|
-
lineConfig.arrowConfig.length,
|
|
403
|
-
lineConfig.arrowConfig.width,
|
|
404
|
-
lineConfig.arrowConfig.showArrowBase,
|
|
405
|
-
);
|
|
406
|
-
|
|
407
|
-
setArrowPoints(arrowPoints);
|
|
408
|
-
}
|
|
409
|
-
} else {
|
|
410
|
-
let p1Array: Array<Array<number>> = [];
|
|
411
|
-
for (let i = 0; i < lineData.length; i++) {
|
|
412
|
-
if (i < lineConfig.startIndex || i > lineConfig.endIndex) continue;
|
|
413
|
-
const currentBarWidth =
|
|
414
|
-
data?.[i]?.barWidth ?? props.barWidth ?? BarDefaults.barWidth;
|
|
415
|
-
const currentValue = props.lineData
|
|
416
|
-
? props.lineData[i].value
|
|
417
|
-
: props.stackData
|
|
418
|
-
? props.stackData[i].stacks.reduce(
|
|
419
|
-
(total, item) => total + item.value,
|
|
420
|
-
0,
|
|
421
|
-
)
|
|
422
|
-
: data[i].value;
|
|
423
|
-
p1Array.push([
|
|
424
|
-
getXForLineInBar(
|
|
425
|
-
i,
|
|
426
|
-
firstBarWidth,
|
|
427
|
-
currentBarWidth,
|
|
428
|
-
yAxisLabelWidth,
|
|
429
|
-
lineConfig,
|
|
430
|
-
spacing,
|
|
431
|
-
),
|
|
432
|
-
getYForLineInBar(
|
|
433
|
-
currentValue,
|
|
434
|
-
lineConfig.shiftY,
|
|
435
|
-
containerHeight,
|
|
436
|
-
lineConfig.isSecondary ? secondaryMaxValue : maxValue,
|
|
437
|
-
),
|
|
438
|
-
]);
|
|
439
|
-
let xx = svgPath(p1Array, lineConfig.curveType, lineConfig.curvature);
|
|
440
|
-
setPoints(xx);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
if (lineData2?.length) {
|
|
444
|
-
if (!lineConfig2?.curved) {
|
|
445
|
-
for (let i = 0; i < lineData2.length; i++) {
|
|
446
|
-
if (i < lineConfig2.startIndex || i > lineConfig2.endIndex)
|
|
447
|
-
continue;
|
|
448
|
-
const currentBarWidth =
|
|
449
|
-
data?.[i]?.barWidth ?? props.barWidth ?? BarDefaults.barWidth;
|
|
450
|
-
const currentValue = lineData2[i].value;
|
|
451
|
-
pp2 +=
|
|
452
|
-
'L' +
|
|
453
|
-
getXForLineInBar(
|
|
454
|
-
i,
|
|
455
|
-
firstBarWidth,
|
|
456
|
-
currentBarWidth,
|
|
457
|
-
yAxisLabelWidth,
|
|
458
|
-
lineConfig2,
|
|
459
|
-
spacing,
|
|
460
|
-
) +
|
|
461
|
-
' ' +
|
|
462
|
-
getYForLineInBar(
|
|
463
|
-
currentValue,
|
|
464
|
-
lineConfig2.shiftY,
|
|
465
|
-
containerHeight,
|
|
466
|
-
lineConfig2.isSecondary ? secondaryMaxValue : maxValue,
|
|
467
|
-
) +
|
|
468
|
-
' ';
|
|
469
|
-
}
|
|
470
|
-
setPoints2(pp2.replace('L', 'M'));
|
|
471
|
-
} else {
|
|
472
|
-
let p2Array: Array<Array<number>> = [];
|
|
473
|
-
for (let i = 0; i < lineData2.length; i++) {
|
|
474
|
-
if (i < lineConfig2.startIndex || i > lineConfig2.endIndex)
|
|
475
|
-
continue;
|
|
476
|
-
const currentBarWidth =
|
|
477
|
-
data?.[i]?.barWidth ?? props.barWidth ?? BarDefaults.barWidth;
|
|
478
|
-
const currentValue = lineData2[i].value;
|
|
479
|
-
p2Array.push([
|
|
480
|
-
getXForLineInBar(
|
|
481
|
-
i,
|
|
482
|
-
firstBarWidth,
|
|
483
|
-
currentBarWidth,
|
|
484
|
-
yAxisLabelWidth,
|
|
485
|
-
lineConfig2,
|
|
486
|
-
spacing,
|
|
487
|
-
),
|
|
488
|
-
getYForLineInBar(
|
|
489
|
-
currentValue,
|
|
490
|
-
lineConfig2.shiftY,
|
|
491
|
-
containerHeight,
|
|
492
|
-
lineConfig2.isSecondary ? secondaryMaxValue : maxValue,
|
|
493
|
-
),
|
|
494
|
-
]);
|
|
495
|
-
let xx = svgPath(
|
|
496
|
-
p2Array,
|
|
497
|
-
lineConfig2.curveType,
|
|
498
|
-
lineConfig2.curvature,
|
|
499
|
-
);
|
|
500
|
-
setPoints2(xx);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
if (lineConfig.isAnimated) {
|
|
505
|
-
setTimeout(() => decreaseWidth(), lineConfig.delay || 0);
|
|
506
|
-
}
|
|
114
|
+
if (lineConfig.isAnimated) {
|
|
115
|
+
setTimeout(() => decreaseWidth(), lineConfig.delay || 0);
|
|
507
116
|
}
|
|
508
117
|
setTimeout(() => labelsAppear(), animationDuration);
|
|
509
|
-
}, [
|
|
510
|
-
animationDuration,
|
|
511
|
-
containerHeight,
|
|
512
|
-
data,
|
|
513
|
-
lineData,
|
|
514
|
-
decreaseWidth,
|
|
515
|
-
initialSpacing,
|
|
516
|
-
labelsAppear,
|
|
517
|
-
lineConfig.initialSpacing,
|
|
518
|
-
lineConfig.curved,
|
|
519
|
-
lineConfig.dataPointsWidth,
|
|
520
|
-
lineConfig.shiftY,
|
|
521
|
-
lineConfig.isAnimated,
|
|
522
|
-
lineConfig.delay,
|
|
523
|
-
lineConfig.startIndex,
|
|
524
|
-
lineConfig.endIndex,
|
|
525
|
-
maxValue,
|
|
526
|
-
props.barWidth,
|
|
527
|
-
showLine,
|
|
528
|
-
spacing,
|
|
529
|
-
yAxisLabelWidth,
|
|
530
|
-
lineConfig.showArrow,
|
|
531
|
-
lineConfig.arrowConfig.length,
|
|
532
|
-
lineConfig.arrowConfig.width,
|
|
533
|
-
lineConfig.arrowConfig.showArrowBase,
|
|
534
|
-
]);
|
|
535
|
-
useEffect(() => {
|
|
536
|
-
if (initialPointerIndex !== -1) {
|
|
537
|
-
const item = (props.stackData ?? data)?.[initialPointerIndex];
|
|
538
|
-
const stackItem = props.stackData?.[initialPointerIndex];
|
|
539
|
-
const stackSum = stackItem?.stacks?.reduce(
|
|
540
|
-
(acc, stack) => acc + (stack.value ?? 0),
|
|
541
|
-
0,
|
|
542
|
-
);
|
|
543
|
-
const x =
|
|
544
|
-
initialSpacing +
|
|
545
|
-
(spacing + barWidth) * initialPointerIndex -
|
|
546
|
-
(pointerRadius || pointerWidth / 2) +
|
|
547
|
-
barWidth / 2;
|
|
548
|
-
const y =
|
|
549
|
-
containerHeight -
|
|
550
|
-
((stackSum ?? data[initialPointerIndex].value) * containerHeight) /
|
|
551
|
-
maxValue -
|
|
552
|
-
(pointerRadius || pointerHeight / 2) +
|
|
553
|
-
10;
|
|
554
|
-
if (initialPointerAppearDelay) {
|
|
555
|
-
setTimeout(() => {
|
|
556
|
-
setPointerConfig(initialPointerIndex, item, x, y);
|
|
557
|
-
}, initialPointerAppearDelay);
|
|
558
|
-
} else {
|
|
559
|
-
setPointerConfig(initialPointerIndex, item, x, y);
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
}, []);
|
|
563
|
-
|
|
564
|
-
const setPointerConfig = (initialPointerIndex, item, x, y) => {
|
|
565
|
-
setPointerIndex(initialPointerIndex);
|
|
566
|
-
setPointerItem(item);
|
|
567
|
-
setPointerX(x);
|
|
568
|
-
setPointerY(y);
|
|
569
|
-
};
|
|
570
|
-
|
|
571
|
-
const animatedHeight = heightValue.interpolate({
|
|
572
|
-
inputRange: [0, 1],
|
|
573
|
-
outputRange: ['0%', '100%'],
|
|
574
|
-
});
|
|
575
|
-
const appearingOpacity = opacValue.interpolate({
|
|
576
|
-
inputRange: [0, 1],
|
|
577
|
-
outputRange: [0, 1],
|
|
578
|
-
});
|
|
579
|
-
|
|
580
|
-
const animatedWidth = widthValue.interpolate({
|
|
581
|
-
inputRange: [0, 1],
|
|
582
|
-
outputRange: [0, totalWidth],
|
|
583
|
-
});
|
|
118
|
+
}, [decreaseWidth, labelsAppear, animationDuration]);
|
|
584
119
|
|
|
585
120
|
const renderPointer = (lineNumber: number) => {
|
|
586
121
|
if (lineNumber === 1 && hidePointer1) return;
|
|
@@ -782,64 +317,6 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
782
317
|
};
|
|
783
318
|
|
|
784
319
|
const renderChart = () => {
|
|
785
|
-
const getPropsCommonForBarAndStack = (item, index) => {
|
|
786
|
-
return {
|
|
787
|
-
key: index,
|
|
788
|
-
item: item,
|
|
789
|
-
index: index,
|
|
790
|
-
containerHeight: containerHeight,
|
|
791
|
-
maxValue: maxValue,
|
|
792
|
-
spacing: item.spacing ?? spacing,
|
|
793
|
-
propSpacing: spacing,
|
|
794
|
-
xAxisThickness: xAxisThickness,
|
|
795
|
-
barWidth: props.barWidth,
|
|
796
|
-
opacity: opacity,
|
|
797
|
-
disablePress: item.disablePress || props.disablePress,
|
|
798
|
-
rotateLabel: rotateLabel,
|
|
799
|
-
showXAxisIndices: showXAxisIndices,
|
|
800
|
-
xAxisIndicesHeight: xAxisIndicesHeight,
|
|
801
|
-
xAxisIndicesWidth: xAxisIndicesWidth,
|
|
802
|
-
xAxisIndicesColor: xAxisIndicesColor,
|
|
803
|
-
horizontal: horizontal,
|
|
804
|
-
rtl: rtl,
|
|
805
|
-
intactTopLabel: intactTopLabel,
|
|
806
|
-
showValuesAsTopLabel: props.showValuesAsTopLabel,
|
|
807
|
-
topLabelContainerStyle: props.topLabelContainerStyle,
|
|
808
|
-
topLabelTextStyle: props.topLabelTextStyle,
|
|
809
|
-
barBorderWidth: props.barBorderWidth,
|
|
810
|
-
barBorderColor: barBorderColor,
|
|
811
|
-
barBorderRadius: props.barBorderRadius,
|
|
812
|
-
barBorderTopLeftRadius: props.barBorderTopLeftRadius,
|
|
813
|
-
barBorderTopRightRadius: props.barBorderTopRightRadius,
|
|
814
|
-
barBorderBottomLeftRadius: props.barBorderBottomLeftRadius,
|
|
815
|
-
barBorderBottomRightRadius: props.barBorderBottomRightRadius,
|
|
816
|
-
barInnerComponent,
|
|
817
|
-
color: props.color,
|
|
818
|
-
showGradient: props.showGradient,
|
|
819
|
-
gradientColor: props.gradientColor,
|
|
820
|
-
barBackgroundPattern: props.barBackgroundPattern,
|
|
821
|
-
patternId: props.patternId,
|
|
822
|
-
onPress: props.onPress,
|
|
823
|
-
xAxisTextNumberOfLines: xAxisTextNumberOfLines,
|
|
824
|
-
xAxisLabelsHeight: props.xAxisLabelsHeight,
|
|
825
|
-
xAxisLabelsVerticalShift,
|
|
826
|
-
renderTooltip: props.renderTooltip,
|
|
827
|
-
leftShiftForTooltip: props.leftShiftForTooltip || 0,
|
|
828
|
-
initialSpacing: initialSpacing,
|
|
829
|
-
selectedIndex: selectedIndex,
|
|
830
|
-
setSelectedIndex: setSelectedIndex,
|
|
831
|
-
activeOpacity: props.activeOpacity || 0.2,
|
|
832
|
-
|
|
833
|
-
leftShiftForLastIndexTooltip: props.leftShiftForLastIndexTooltip || 0,
|
|
834
|
-
label:
|
|
835
|
-
item.label ||
|
|
836
|
-
(props.xAxisLabelTexts && props.xAxisLabelTexts[index]
|
|
837
|
-
? props.xAxisLabelTexts[index]
|
|
838
|
-
: ''),
|
|
839
|
-
labelTextStyle: item.labelTextStyle || props.xAxisLabelTextStyle,
|
|
840
|
-
pointerConfig,
|
|
841
|
-
};
|
|
842
|
-
};
|
|
843
320
|
if (props.stackData) {
|
|
844
321
|
return props.stackData.map((item, index) => {
|
|
845
322
|
return (
|
|
@@ -887,88 +364,12 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
887
364
|
}
|
|
888
365
|
};
|
|
889
366
|
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
const barAndLineChartsWrapperProps: BarAndLineChartsWrapperTypes = {
|
|
899
|
-
chartType: chartTypes.BAR,
|
|
900
|
-
containerHeight,
|
|
901
|
-
noOfSectionsBelowXAxis,
|
|
902
|
-
stepHeight,
|
|
903
|
-
labelsExtraHeight,
|
|
904
|
-
yAxisLabelWidth,
|
|
905
|
-
horizontal,
|
|
906
|
-
rtl,
|
|
907
|
-
shiftX: props.shiftX ?? 0,
|
|
908
|
-
shiftY: props.shiftY ?? 0,
|
|
909
|
-
scrollRef,
|
|
910
|
-
yAxisAtTop,
|
|
911
|
-
initialSpacing,
|
|
912
|
-
data,
|
|
913
|
-
stackData: props.stackData,
|
|
914
|
-
secondaryData: secondaryData,
|
|
915
|
-
barWidth: props.barWidth || BarDefaults.barWidth,
|
|
916
|
-
xAxisThickness,
|
|
917
|
-
totalWidth,
|
|
918
|
-
disableScroll,
|
|
919
|
-
showScrollIndicator,
|
|
920
|
-
scrollToEnd,
|
|
921
|
-
scrollToIndex: props.scrollToIndex,
|
|
922
|
-
scrollAnimation,
|
|
923
|
-
scrollEventThrottle,
|
|
924
|
-
indicatorColor: props.indicatorColor,
|
|
925
|
-
setSelectedIndex,
|
|
926
|
-
spacing,
|
|
927
|
-
showLine,
|
|
928
|
-
lineConfig,
|
|
929
|
-
lineConfig2,
|
|
930
|
-
maxValue,
|
|
931
|
-
lineData,
|
|
932
|
-
lineData2,
|
|
933
|
-
animatedWidth,
|
|
934
|
-
lineBehindBars,
|
|
935
|
-
points,
|
|
936
|
-
points2,
|
|
937
|
-
arrowPoints,
|
|
938
|
-
renderChartContent,
|
|
939
|
-
remainingScrollViewProps,
|
|
940
|
-
|
|
941
|
-
//horizSectionProps-
|
|
942
|
-
width: widthFromProps,
|
|
943
|
-
horizSections,
|
|
944
|
-
endSpacing,
|
|
945
|
-
horizontalRulesStyle,
|
|
946
|
-
noOfSections,
|
|
947
|
-
showFractionalValues,
|
|
948
|
-
|
|
949
|
-
axesAndRulesProps: getAxesAndRulesProps(
|
|
950
|
-
props,
|
|
951
|
-
stepValue,
|
|
952
|
-
secondaryMaxValue,
|
|
953
|
-
),
|
|
954
|
-
|
|
955
|
-
yAxisLabelTexts: props.yAxisLabelTexts,
|
|
956
|
-
yAxisOffset: props.yAxisOffset,
|
|
957
|
-
rotateYAxisTexts: props.rotateYAxisTexts,
|
|
958
|
-
hideAxesAndRules: props.hideAxesAndRules,
|
|
959
|
-
|
|
960
|
-
showXAxisIndices,
|
|
961
|
-
xAxisIndicesHeight,
|
|
962
|
-
xAxisIndicesWidth,
|
|
963
|
-
xAxisIndicesColor,
|
|
964
|
-
|
|
965
|
-
// These are Not needed but passing this prop to maintain consistency (between LineChart and BarChart props)
|
|
966
|
-
pointerConfig,
|
|
967
|
-
getPointerProps,
|
|
968
|
-
pointerIndex,
|
|
969
|
-
pointerX,
|
|
970
|
-
pointerY,
|
|
971
|
-
};
|
|
972
|
-
|
|
973
|
-
return <BarAndLineChartsWrapper {...barAndLineChartsWrapperProps} />;
|
|
367
|
+
return (
|
|
368
|
+
<BarAndLineChartsWrapper
|
|
369
|
+
{...barAndLineChartsWrapperProps}
|
|
370
|
+
scrollRef={scrollRef}
|
|
371
|
+
renderChartContent={renderChartContent}
|
|
372
|
+
remainingScrollViewProps={remainingScrollViewProps}
|
|
373
|
+
/>
|
|
374
|
+
);
|
|
974
375
|
};
|