react-native-gifted-charts 1.4.12 → 1.4.14

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 (60) hide show
  1. package/package.json +6 -10
  2. package/src/BarChart/Animated2DWithGradient.tsx +197 -0
  3. package/src/BarChart/RenderBars.tsx +458 -0
  4. package/src/BarChart/RenderStackBars.tsx +385 -0
  5. package/src/BarChart/index.tsx +381 -0
  6. package/src/BarChart/styles.tsx +47 -0
  7. package/src/Components/AnimatedThreeDBar/index.tsx +258 -0
  8. package/src/Components/AnimatedThreeDBar/styles.tsx +14 -0
  9. package/src/Components/BarAndLineChartsWrapper/index.tsx +244 -0
  10. package/src/Components/BarAndLineChartsWrapper/renderHorizSections.tsx +590 -0
  11. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.tsx +147 -0
  12. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.tsx +157 -0
  13. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.tsx +86 -0
  14. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.tsx +42 -0
  15. package/src/Components/BarAndLineChartsWrapper/renderVerticalLines.tsx +131 -0
  16. package/src/Components/BarSpecificComponents/barBackgroundPattern.tsx +30 -0
  17. package/src/Components/BarSpecificComponents/cap.tsx +34 -0
  18. package/src/Components/common/LinearGradient.tsx +27 -0
  19. package/src/Components/common/Pointer.tsx +37 -0
  20. package/src/Components/common/StripAndLabel.tsx +98 -0
  21. package/src/Components/lineSvg.tsx +42 -0
  22. package/src/LineChart/LineChartBicolor.tsx +740 -0
  23. package/src/LineChart/index.tsx +2158 -0
  24. package/src/LineChart/styles.tsx +47 -0
  25. package/src/PieChart/index.tsx +165 -0
  26. package/src/PieChart/main.tsx +363 -0
  27. package/src/PieChartPro/index.tsx +267 -0
  28. package/src/PopulationPyramid/index.tsx +603 -0
  29. package/src/index.tsx +25 -0
  30. package/src/todos.md +23 -0
  31. package/src/utils/index.ts +16 -0
  32. package/dist/BarChart/Animated2DWithGradient.js +0 -1
  33. package/dist/BarChart/RenderBars.js +0 -1
  34. package/dist/BarChart/RenderStackBars.js +0 -1
  35. package/dist/BarChart/index.js +0 -1
  36. package/dist/BarChart/styles.js +0 -1
  37. package/dist/Components/AnimatedThreeDBar/index.js +0 -1
  38. package/dist/Components/AnimatedThreeDBar/styles.js +0 -1
  39. package/dist/Components/BarAndLineChartsWrapper/index.js +0 -1
  40. package/dist/Components/BarAndLineChartsWrapper/renderHorizSections.js +0 -1
  41. package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.js +0 -1
  42. package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.js +0 -1
  43. package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.js +0 -1
  44. package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.js +0 -1
  45. package/dist/Components/BarAndLineChartsWrapper/renderVerticalLines.js +0 -1
  46. package/dist/Components/BarSpecificComponents/barBackgroundPattern.js +0 -1
  47. package/dist/Components/BarSpecificComponents/cap.js +0 -1
  48. package/dist/Components/common/LinearGradient.js +0 -1
  49. package/dist/Components/common/Pointer.js +0 -1
  50. package/dist/Components/common/StripAndLabel.js +0 -1
  51. package/dist/Components/lineSvg.js +0 -1
  52. package/dist/LineChart/LineChartBicolor.js +0 -1
  53. package/dist/LineChart/index.js +0 -1
  54. package/dist/LineChart/styles.js +0 -1
  55. package/dist/PieChart/index.js +0 -1
  56. package/dist/PieChart/main.js +0 -1
  57. package/dist/PieChartPro/index.js +0 -1
  58. package/dist/PopulationPyramid/index.js +0 -1
  59. package/dist/index.js +0 -1
  60. package/dist/utils/index.js +0 -1
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "react-native-gifted-charts",
3
- "version": "1.4.12",
3
+ "version": "1.4.14",
4
4
  "description": "The most complete library for Bar, Line, Area, Pie, Donut, Stacked Bar and Population Pyramid charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
5
- "main": "dist/index.tsx",
5
+ "main": "src/index.tsx",
6
6
  "files": [
7
- "dist"
7
+ "src"
8
8
  ],
9
9
  "scripts": {
10
10
  "android": "react-native run-android",
11
- "build": "babel --extensions .ts,.tsx ./src -d ./dist",
11
+ "build": "tsc -p .",
12
12
  "ios": "react-native run-ios",
13
13
  "start": "react-native start",
14
14
  "test": "jest",
@@ -25,14 +25,10 @@
25
25
  "registry": "https://registry.npmjs.org/"
26
26
  },
27
27
  "dependencies": {
28
- "gifted-charts-core": "^0.1.8"
28
+ "gifted-charts-core": "^0.1.10"
29
29
  },
30
30
  "devDependencies": {
31
- "@babel/cli": "^7.24.7",
32
- "@babel/core": "^7.24.7",
33
- "@babel/preset-env": "^7.24.7",
34
- "@babel/preset-react": "^7.24.7",
35
- "@babel/preset-typescript": "^7.24.7",
31
+ "@babel/core": "^7.22.5",
36
32
  "@babel/runtime": "^7.22.5",
37
33
  "@react-native-community/eslint-config": "^3.2.0",
38
34
  "@types/jest": "^29.5.2",
@@ -0,0 +1,197 @@
1
+ import React, {useEffect, useState} from 'react';
2
+ import {View, LayoutAnimation, Platform, UIManager, Text} from 'react-native';
3
+ import Svg, {Defs, Rect} from 'react-native-svg';
4
+ import Cap from '../Components/BarSpecificComponents/cap';
5
+ import LinearGradient from "../Components/common/LinearGradient";
6
+ import {Animated2DWithGradientPropsType} from 'gifted-charts-core';
7
+
8
+ if (Platform.OS === 'android') {
9
+ UIManager.setLayoutAnimationEnabledExperimental &&
10
+ UIManager.setLayoutAnimationEnabledExperimental(true);
11
+ }
12
+
13
+ const Animated2DWithGradient = (props: Animated2DWithGradientPropsType) => {
14
+ const {
15
+ barBackgroundPattern,
16
+ patternId,
17
+ barWidth,
18
+ barStyle,
19
+ item,
20
+ index,
21
+ opacity,
22
+ animationDuration,
23
+ noGradient,
24
+ noAnimation,
25
+ containerHeight,
26
+ maxValue,
27
+ barMarginBottom,
28
+ barInnerComponent,
29
+ intactTopLabel,
30
+ showValuesAsTopLabel,
31
+ topLabelContainerStyle,
32
+ topLabelTextStyle,
33
+ commonStyleForBar,
34
+ barStyleWithBackground,
35
+ yAxisOffset,
36
+ } = props;
37
+ const [height, setHeight] = useState(noAnimation ? props.height : 0.2);
38
+ const [initialRender, setInitialRender] = useState(
39
+ noAnimation ? false : true,
40
+ );
41
+
42
+ useEffect(() => {
43
+ if (!noAnimation) {
44
+ if (initialRender) {
45
+ setTimeout(() => layoutAppear(), 20);
46
+ } else {
47
+ elevate();
48
+ }
49
+ }
50
+ }, [props.height]);
51
+
52
+ const elevate = () => {
53
+ LayoutAnimation.configureNext({
54
+ duration: animationDuration,
55
+ update: {type: 'linear', property: 'scaleXY'},
56
+ });
57
+ setHeight(props.height);
58
+ };
59
+
60
+ const layoutAppear = () => {
61
+ LayoutAnimation.configureNext({
62
+ duration: Platform.OS == 'ios' ? animationDuration : 20,
63
+ create: {type: 'linear', property: 'opacity'},
64
+ update: {type: 'linear', property: 'scaleXY'},
65
+ });
66
+ setInitialRender(false);
67
+ setTimeout(() => elevate(), Platform.OS == 'ios' ? 10 : 100);
68
+ };
69
+
70
+ return (
71
+ <>
72
+ {!initialRender && (
73
+ <View
74
+ style={{
75
+ position: 'absolute',
76
+ bottom: -0.5,
77
+ width: '100%',
78
+ overflow: 'hidden',
79
+ height:
80
+ (noAnimation
81
+ ? Math.max(props.minHeight, Math.abs(height))
82
+ : height) - (barMarginBottom || 0),
83
+ }}>
84
+ <View
85
+ style={[
86
+ {
87
+ width: '100%',
88
+ height:
89
+ (noAnimation
90
+ ? Math.max(props.minHeight, Math.abs(height))
91
+ : height) - (barMarginBottom || 0),
92
+ },
93
+ item.barStyle || barStyle,
94
+ ]}>
95
+ {noGradient ? (
96
+ <View style={barStyleWithBackground}>
97
+ {props.cappedBars && item.value ? (
98
+ <Cap
99
+ capThicknessFromItem={item.capThickness}
100
+ capThicknessFromProps={props.capThickness}
101
+ capColorFromItem={item.capColor}
102
+ capColorFromProps={props.capColor}
103
+ capRadiusFromItem={item.capRadius}
104
+ capRadiusFromProps={props.capRadius}
105
+ />
106
+ ) : null}
107
+ </View>
108
+ ) : (
109
+ <LinearGradient
110
+ style={commonStyleForBar}
111
+ start={{x: 0, y: 0}}
112
+ end={{x: 1, y: 1}}
113
+ colors={[
114
+ item.gradientColor || props.gradientColor || 'white',
115
+ item.frontColor || props.frontColor || 'black',
116
+ ]}>
117
+ {props.cappedBars && (
118
+ <View
119
+ style={{
120
+ position: 'absolute',
121
+ width: '100%',
122
+ height:
123
+ item.capThickness === 0
124
+ ? 0
125
+ : item.capThickness || props.capThickness || 6,
126
+ backgroundColor:
127
+ item.capColor || props.capColor || 'black',
128
+ borderTopLeftRadius:
129
+ item.capRadius === 0
130
+ ? 0
131
+ : item.capRadius || props.capRadius || 0,
132
+ borderTopRightRadius:
133
+ item.capRadius === 0
134
+ ? 0
135
+ : item.capRadius || props.capRadius || 0,
136
+ }}
137
+ />
138
+ )}
139
+ </LinearGradient>
140
+ )}
141
+ {(item.barBackgroundPattern || barBackgroundPattern) && (
142
+ <Svg>
143
+ <Defs>
144
+ {item.barBackgroundPattern
145
+ ? item.barBackgroundPattern()
146
+ : barBackgroundPattern?.()}
147
+ </Defs>
148
+ <Rect
149
+ stroke="transparent"
150
+ x="1"
151
+ y="1"
152
+ width={item.barWidth || props.barWidth || 30}
153
+ height={noAnimation ? Math.abs(height) : height}
154
+ fill={`url(#${item.patternId || patternId})`}
155
+ />
156
+ </Svg>
157
+ )}
158
+ {barInnerComponent ? (
159
+ <View style={{height: '100%', width: '100%'}}>
160
+ {barInnerComponent(item, index)}
161
+ </View>
162
+ ) : null}
163
+ </View>
164
+ </View>
165
+ )}
166
+ {item.topLabelComponent || showValuesAsTopLabel ? (
167
+ <View
168
+ style={[
169
+ {
170
+ position: 'absolute',
171
+ top: (item.barWidth || barWidth || 30) * -1,
172
+ height: item.barWidth || barWidth || 30,
173
+ width: item.barWidth || barWidth || 30,
174
+ justifyContent:
175
+ (props.horizontal && !intactTopLabel) || item.value < 0
176
+ ? 'center'
177
+ : 'flex-end',
178
+ alignItems: 'center',
179
+ opacity: opacity,
180
+ },
181
+ item.value < 0 && {transform: [{rotate: '180deg'}]},
182
+ props.horizontal &&
183
+ !intactTopLabel && {transform: [{rotate: '270deg'}]},
184
+ topLabelContainerStyle ?? item.topLabelContainerStyle,
185
+ ]}>
186
+ {showValuesAsTopLabel ? (
187
+ <Text style={topLabelTextStyle}>{item.value + yAxisOffset}</Text>
188
+ ) : (
189
+ item.topLabelComponent?.()
190
+ )}
191
+ </View>
192
+ ) : null}
193
+ </>
194
+ );
195
+ };
196
+
197
+ export default Animated2DWithGradient;
@@ -0,0 +1,458 @@
1
+ import React from 'react';
2
+ import {View, TouchableOpacity, Animated, Text} from 'react-native';
3
+ import AnimatedThreeDBar from '../Components/AnimatedThreeDBar';
4
+ import Animated2DWithGradient from './Animated2DWithGradient';
5
+ import Cap from '../Components/BarSpecificComponents/cap';
6
+ import BarBackgroundPattern from '../Components/BarSpecificComponents/barBackgroundPattern';
7
+ import LinearGradient from '../Components/common/LinearGradient';
8
+ import {
9
+ getPropsForAnimated2DWithGradient,
10
+ RenderBarsPropsType,
11
+ barDataItem,
12
+ AxesAndRulesDefaults,
13
+ } from 'gifted-charts-core';
14
+
15
+ const RenderBars = (props: RenderBarsPropsType) => {
16
+ const {
17
+ item,
18
+ index,
19
+ containerHeight,
20
+ maxValue,
21
+ minHeight,
22
+ spacing,
23
+ propSpacing,
24
+ side,
25
+ data,
26
+ barBorderWidth,
27
+ barBorderColor,
28
+ isThreeD,
29
+ isAnimated,
30
+ rotateLabel,
31
+ appearingOpacity,
32
+ animationDuration,
33
+ autoShiftLabels,
34
+ label,
35
+ labelTextStyle,
36
+ xAxisTextNumberOfLines,
37
+ xAxisLabelsVerticalShift,
38
+ renderTooltip,
39
+ leftShiftForTooltip,
40
+ leftShiftForLastIndexTooltip,
41
+ initialSpacing,
42
+ selectedIndex,
43
+ setSelectedIndex,
44
+ xAxisThickness = AxesAndRulesDefaults.xAxisThickness,
45
+ horizontal,
46
+ rtl,
47
+ intactTopLabel,
48
+ showValuesAsTopLabel,
49
+ topLabelContainerStyle,
50
+ topLabelTextStyle,
51
+ pointerConfig,
52
+ noOfSectionsBelowXAxis,
53
+ yAxisOffset,
54
+ barWidth,
55
+ labelsDistanceFromXaxis = 0,
56
+ } = props;
57
+
58
+ const barHeight = Math.max(
59
+ minHeight,
60
+ (Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200) -
61
+ xAxisThickness,
62
+ );
63
+
64
+ const {
65
+ commonStyleForBar,
66
+ barStyleWithBackground,
67
+ commonPropsFor2Dand3Dbars,
68
+ isFocused,
69
+ focusedBarConfig,
70
+ localFrontColor,
71
+ } = getPropsForAnimated2DWithGradient({...props, barHeight});
72
+
73
+ const itemOrPropsBarInnerComponent =
74
+ item.barInnerComponent ?? props.barInnerComponent;
75
+ const localBarInnerComponent = isFocused
76
+ ? focusedBarConfig?.barInnerComponent ?? itemOrPropsBarInnerComponent
77
+ : itemOrPropsBarInnerComponent;
78
+
79
+ const barMarginBottom =
80
+ item.barMarginBottom === 0
81
+ ? 0
82
+ : item.barMarginBottom || props.barMarginBottom || 0;
83
+
84
+ const renderLabel = (label: String, labelTextStyle: any, value: number) => {
85
+ return (
86
+ <View
87
+ style={[
88
+ {
89
+ width:
90
+ (item.labelWidth ||
91
+ props.labelWidth ||
92
+ item.barWidth ||
93
+ barWidth) + spacing,
94
+ left: spacing / -2,
95
+ position: 'absolute',
96
+ height: props.xAxisLabelsHeight ?? xAxisTextNumberOfLines * 18,
97
+ bottom:
98
+ (rotateLabel
99
+ ? -40
100
+ : -6 - xAxisTextNumberOfLines * 18 - xAxisLabelsVerticalShift) -
101
+ barMarginBottom -
102
+ labelsDistanceFromXaxis,
103
+ },
104
+ rotateLabel
105
+ ? horizontal
106
+ ? {transform: [{rotate: '330deg'}]}
107
+ : {
108
+ transform: [
109
+ {rotate: value < 0 ? '240deg' : '60deg'},
110
+ {translateX: value < 0 ? 56 : 0},
111
+ {translateY: value < 0 ? 32 : 0},
112
+ ],
113
+ }
114
+ : horizontal
115
+ ? {transform: [{rotate: '-90deg'}]}
116
+ : value < 0
117
+ ? {
118
+ transform: [
119
+ {rotate: '180deg'},
120
+ {
121
+ translateY: autoShiftLabels
122
+ ? 0
123
+ : 16.5 * xAxisTextNumberOfLines + 14,
124
+ },
125
+ ],
126
+ }
127
+ : {},
128
+ ]}>
129
+ {item.labelComponent ? (
130
+ item.labelComponent()
131
+ ) : (
132
+ <Text
133
+ style={[
134
+ {textAlign: 'center'},
135
+ rtl && horizontal && {transform: [{rotate: '180deg'}]},
136
+ labelTextStyle,
137
+ ]}
138
+ numberOfLines={xAxisTextNumberOfLines}>
139
+ {label || ''}
140
+ </Text>
141
+ )}
142
+ </View>
143
+ );
144
+ };
145
+
146
+ const renderAnimatedLabel = (
147
+ label: String,
148
+ labelTextStyle: any,
149
+ value: number,
150
+ ) => {
151
+ return (
152
+ <Animated.View
153
+ style={[
154
+ {
155
+ width:
156
+ (item.labelWidth ||
157
+ props.labelWidth ||
158
+ item.barWidth ||
159
+ barWidth) + spacing,
160
+ left: spacing / -2,
161
+ position: 'absolute',
162
+ height: props.xAxisLabelsHeight ?? xAxisTextNumberOfLines * 18,
163
+ bottom:
164
+ (rotateLabel
165
+ ? -40
166
+ : -6 - xAxisTextNumberOfLines * 18 - xAxisLabelsVerticalShift) -
167
+ barMarginBottom,
168
+ opacity: appearingOpacity,
169
+ },
170
+ value < 0 && {transform: [{rotate: '180deg'}]},
171
+ rotateLabel
172
+ ? horizontal
173
+ ? {transform: [{rotate: '330deg'}]}
174
+ : {transform: [{rotate: '60deg'}]}
175
+ : horizontal
176
+ ? {transform: [{rotate: '-90deg'}]}
177
+ : value < 0
178
+ ? {
179
+ transform: [
180
+ {rotate: '180deg'},
181
+ {
182
+ translateY: autoShiftLabels
183
+ ? 0
184
+ : 16.5 * xAxisTextNumberOfLines + 14,
185
+ },
186
+ ],
187
+ }
188
+ : {},
189
+ ]}>
190
+ {item.labelComponent ? (
191
+ item.labelComponent()
192
+ ) : (
193
+ <Text
194
+ style={[
195
+ {textAlign: 'center'},
196
+ rtl && horizontal && {transform: [{rotate: '180deg'}]},
197
+ labelTextStyle,
198
+ ]}
199
+ numberOfLines={xAxisTextNumberOfLines}>
200
+ {label || ''}
201
+ </Text>
202
+ )}
203
+ </Animated.View>
204
+ );
205
+ };
206
+
207
+ let leftSpacing = initialSpacing;
208
+ for (let i = 0; i < index; i++) {
209
+ leftSpacing +=
210
+ (data[i].spacing ?? propSpacing) + (data[i].barWidth || barWidth);
211
+ }
212
+
213
+ const static2DWithGradient = (item: barDataItem) => {
214
+ const localGradientColor =
215
+ item.gradientColor || props.gradientColor || 'white';
216
+ return (
217
+ <>
218
+ <LinearGradient
219
+ style={commonStyleForBar}
220
+ start={{x: 0, y: 0}}
221
+ end={{x: 0, y: 1}}
222
+ colors={[
223
+ isFocused
224
+ ? focusedBarConfig?.gradientColor ?? localGradientColor
225
+ : localGradientColor,
226
+ localFrontColor,
227
+ ]}>
228
+ {props.cappedBars && item.value ? (
229
+ <Cap
230
+ capThicknessFromItem={item.capThickness}
231
+ capThicknessFromProps={props.capThickness}
232
+ capColorFromItem={item.capColor}
233
+ capColorFromProps={props.capColor}
234
+ capRadiusFromItem={item.capRadius}
235
+ capRadiusFromProps={props.capRadius}
236
+ />
237
+ ) : null}
238
+ </LinearGradient>
239
+ {(item.barBackgroundPattern || props.barBackgroundPattern) && (
240
+ <BarBackgroundPattern
241
+ barBackgroundPatternFromItem={item.barBackgroundPattern}
242
+ barBackgroundPatternFromProps={props.barBackgroundPattern}
243
+ patternIdFromItem={item.patternId}
244
+ patternIdFromProps={props.patternId}
245
+ />
246
+ )}
247
+ {(item.topLabelComponent || showValuesAsTopLabel) && (
248
+ <View
249
+ style={[
250
+ {
251
+ position: 'absolute',
252
+ top: (item.barWidth || barWidth) * -1,
253
+ height: item.barWidth || barWidth,
254
+ width: item.barWidth || barWidth,
255
+ justifyContent:
256
+ (horizontal && !intactTopLabel) || item.value < 0
257
+ ? 'center'
258
+ : 'flex-end',
259
+ alignItems: 'center',
260
+ },
261
+ item.value < 0 && {transform: [{rotate: '180deg'}]},
262
+ horizontal &&
263
+ !intactTopLabel && {transform: [{rotate: '270deg'}]},
264
+ topLabelContainerStyle ?? item.topLabelContainerStyle,
265
+ ]}>
266
+ {showValuesAsTopLabel ? (
267
+ <Text style={topLabelTextStyle}>{item.value + yAxisOffset}</Text>
268
+ ) : (
269
+ item.topLabelComponent?.()
270
+ )}
271
+ </View>
272
+ )}
273
+ {localBarInnerComponent ? (
274
+ <View style={{height: '100%', width: '100%'}}>
275
+ {localBarInnerComponent(item, index)}
276
+ </View>
277
+ ) : null}
278
+ </>
279
+ );
280
+ };
281
+
282
+ const barWrapperStyle = [
283
+ {
284
+ // overflow: 'visible',
285
+ marginBottom: 60 + barMarginBottom + xAxisLabelsVerticalShift - 0.5,
286
+ width: commonPropsFor2Dand3Dbars.barWidth,
287
+ height: barHeight,
288
+ marginRight: spacing,
289
+ },
290
+
291
+ pointerConfig
292
+ ? {
293
+ transform: [
294
+ {
295
+ translateY:
296
+ (containerHeight || 200) -
297
+ (barHeight - 10 + xAxisLabelsVerticalShift) +
298
+ (item.value < 0
299
+ ? (Math.abs(item.value) * (containerHeight || 200)) /
300
+ (maxValue || 200)
301
+ : 0),
302
+ },
303
+ ],
304
+ }
305
+ : item.value < 0
306
+ ? {
307
+ transform: [
308
+ {
309
+ translateY:
310
+ (Math.abs(item.value) * (containerHeight || 200)) /
311
+ (maxValue || 200),
312
+ },
313
+ {rotateZ: '180deg'},
314
+ ],
315
+ }
316
+ : null,
317
+ side !== 'right' && {zIndex: data.length - index},
318
+ ];
319
+
320
+ const pressDisabled =
321
+ item.disablePress ||
322
+ props.disablePress ||
323
+ (pointerConfig && pointerConfig.barTouchable !== true);
324
+
325
+ const barContent = () => {
326
+ const isBarBelowXaxisAndInvisible =
327
+ item.value < 0 && !noOfSectionsBelowXAxis;
328
+ const animated2DWithGradient = (noGradient, noAnimation) => (
329
+ <Animated2DWithGradient
330
+ {...commonPropsFor2Dand3Dbars}
331
+ animationDuration={animationDuration || 800}
332
+ roundedBottom={props.roundedBottom || false}
333
+ roundedTop={props.roundedTop || false}
334
+ noGradient={noGradient}
335
+ noAnimation={noAnimation}
336
+ containerHeight={containerHeight}
337
+ maxValue={maxValue}
338
+ minHeight={minHeight ?? 0}
339
+ barMarginBottom={barMarginBottom}
340
+ cappedBars={props.cappedBars}
341
+ capThickness={props.capThickness}
342
+ capColor={props.capColor}
343
+ capRadius={props.capRadius}
344
+ horizontal={horizontal}
345
+ barBorderWidth={barBorderWidth}
346
+ barBorderColor={barBorderColor}
347
+ commonStyleForBar={commonStyleForBar}
348
+ barStyleWithBackground={barStyleWithBackground}
349
+ />
350
+ );
351
+ return (
352
+ <>
353
+ {(props.showXAxisIndices || item.showXAxisIndex) && (
354
+ <View
355
+ style={{
356
+ zIndex: 2,
357
+ position: 'absolute',
358
+ height: props.xAxisIndicesHeight,
359
+ width: props.xAxisIndicesWidth,
360
+ bottom: props.xAxisIndicesHeight / -2,
361
+ left: ((item.barWidth || barWidth) - props.xAxisIndicesWidth) / 2,
362
+ backgroundColor: props.xAxisIndicesColor,
363
+ }}
364
+ />
365
+ )}
366
+ {isBarBelowXaxisAndInvisible ? null : isThreeD ? (
367
+ <AnimatedThreeDBar
368
+ {...commonPropsFor2Dand3Dbars}
369
+ sideWidth={
370
+ item.sideWidth ||
371
+ props.sideWidth ||
372
+ (item.barWidth || barWidth) / 2
373
+ }
374
+ side={side || 'left'}
375
+ sideColor={item.sideColor || props.sideColor || ''}
376
+ topColor={item.topColor || props.topColor || ''}
377
+ horizontal={horizontal}
378
+ isAnimated={isAnimated}
379
+ animationDuration={animationDuration || 800}
380
+ selectedIndex={selectedIndex}
381
+ />
382
+ ) : item.showGradient || props.showGradient ? (
383
+ isAnimated ? (
384
+ animated2DWithGradient(false, false)
385
+ ) : (
386
+ static2DWithGradient(item)
387
+ )
388
+ ) : isAnimated ? (
389
+ animated2DWithGradient(true, false)
390
+ ) : (
391
+ animated2DWithGradient(true, true)
392
+ )}
393
+ {isAnimated
394
+ ? renderAnimatedLabel(label, labelTextStyle, item.value)
395
+ : renderLabel(label, labelTextStyle, item.value)}
396
+ </>
397
+ );
398
+ };
399
+
400
+ return (
401
+ <>
402
+ {pressDisabled ? (
403
+ <View pointerEvents="none" style={barWrapperStyle}>
404
+ {barContent()}
405
+ </View>
406
+ ) : (
407
+ <TouchableOpacity
408
+ activeOpacity={props.activeOpacity || 0.2}
409
+ onPress={() => {
410
+ if (renderTooltip || props.focusBarOnPress) {
411
+ if (props.focusedBarIndex === undefined || !props.onPress) {
412
+ setSelectedIndex(index);
413
+ }
414
+ }
415
+ item.onPress
416
+ ? item.onPress()
417
+ : props.onPress
418
+ ? props.onPress(item, index)
419
+ : null;
420
+ }}
421
+ onLongPress={() => {
422
+ item.onLongPress
423
+ ? item.onLongPress()
424
+ : props.onLongPress
425
+ ? props.onLongPress(item, index)
426
+ : null;
427
+ }}
428
+ onPressOut={() => {
429
+ item.onPressOut
430
+ ? item.onPressOut()
431
+ : props.onPressOut
432
+ ? props.onPressOut(item, index)
433
+ : null;
434
+ }}
435
+ style={barWrapperStyle}>
436
+ {barContent()}
437
+ </TouchableOpacity>
438
+ )}
439
+ {renderTooltip && selectedIndex === index && (
440
+ <View
441
+ style={{
442
+ position: 'absolute',
443
+ bottom: barHeight + 60,
444
+ left:
445
+ index === data.length - 1
446
+ ? leftSpacing - leftShiftForLastIndexTooltip
447
+ : leftSpacing -
448
+ (item?.leftShiftForTooltip ?? leftShiftForTooltip ?? 0),
449
+ zIndex: 1000,
450
+ }}>
451
+ {renderTooltip(item, index)}
452
+ </View>
453
+ )}
454
+ </>
455
+ );
456
+ };
457
+
458
+ export default RenderBars;