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
@@ -0,0 +1,385 @@
1
+ import React, {useEffect} from 'react';
2
+ import {
3
+ View,
4
+ TouchableOpacity,
5
+ Text,
6
+ LayoutAnimation,
7
+ Platform,
8
+ UIManager,
9
+ } from 'react-native';
10
+ import Svg, {Defs, Rect} from 'react-native-svg';
11
+ import LinearGradient from '../Components/common/LinearGradient';
12
+ import {
13
+ useRenderStackBars,
14
+ BarDefaults,
15
+ StackedBarChartPropsType,
16
+ } from 'gifted-charts-core';
17
+
18
+ if (Platform.OS === 'android') {
19
+ UIManager.setLayoutAnimationEnabledExperimental &&
20
+ UIManager.setLayoutAnimationEnabledExperimental(true);
21
+ }
22
+
23
+ const RenderStackBars = (props: StackedBarChartPropsType) => {
24
+ const {
25
+ barBackgroundPattern,
26
+ patternId,
27
+ item,
28
+ index,
29
+ containerHeight,
30
+ spacing,
31
+ rotateLabel,
32
+ label,
33
+ labelTextStyle,
34
+ xAxisTextNumberOfLines,
35
+ xAxisLabelsVerticalShift,
36
+ renderTooltip,
37
+ leftShiftForTooltip,
38
+ leftShiftForLastIndexTooltip,
39
+ selectedIndex,
40
+ setSelectedIndex,
41
+ activeOpacity,
42
+ stackData,
43
+ animationDuration = BarDefaults.animationDuration,
44
+ barBorderWidth,
45
+ barBorderColor,
46
+ stackBorderRadius,
47
+ stackBorderTopLeftRadius,
48
+ stackBorderTopRightRadius,
49
+ stackBorderBottomLeftRadius,
50
+ stackBorderBottomRightRadius,
51
+ showValuesAsTopLabel,
52
+ autoShiftLabelsForNegativeStacks = true,
53
+ labelsDistanceFromXaxis = 0,
54
+ } = props;
55
+ const {
56
+ cotainsNegative,
57
+ noAnimation,
58
+ localBarInnerComponent,
59
+ borderRadius,
60
+ borderTopLeftRadius,
61
+ borderTopRightRadius,
62
+ borderBottomLeftRadius,
63
+ borderBottomRightRadius,
64
+ leftSpacing,
65
+ disablePress,
66
+ totalHeight,
67
+ height,
68
+ setHeight,
69
+ getBarHeight,
70
+ getPosition,
71
+ lowestBarPosition,
72
+ getStackBorderRadii,
73
+ } = useRenderStackBars(props);
74
+
75
+ const renderLabel = (label: String, labelTextStyle: any) => {
76
+ return (
77
+ <View
78
+ style={[
79
+ {
80
+ width:
81
+ (item.stacks[0].barWidth || props.barWidth || 30) + spacing / 2,
82
+ position: 'absolute',
83
+ bottom: autoShiftLabelsForNegativeStacks
84
+ ? -6 - xAxisTextNumberOfLines * 18 + lowestBarPosition
85
+ : -labelsDistanceFromXaxis,
86
+ },
87
+ rotateLabel
88
+ ? props.horizontal
89
+ ? {transform: [{rotate: '330deg'}]}
90
+ : {transform: [{rotate: '60deg'}]}
91
+ : props.horizontal
92
+ ? {transform: [{rotate: '-90deg'}]}
93
+ : {},
94
+ ]}>
95
+ {item.labelComponent ? (
96
+ item.labelComponent()
97
+ ) : (
98
+ <Text style={[labelTextStyle]} numberOfLines={xAxisTextNumberOfLines}>
99
+ {label || ''}
100
+ </Text>
101
+ )}
102
+ </View>
103
+ );
104
+ };
105
+
106
+ useEffect(() => {
107
+ if (!noAnimation) {
108
+ layoutAppear();
109
+ }
110
+ }, [totalHeight]);
111
+
112
+ const elevate = () => {
113
+ LayoutAnimation.configureNext({
114
+ duration: animationDuration,
115
+ update: {type: 'linear', property: 'scaleXY'},
116
+ });
117
+ setHeight(totalHeight);
118
+ };
119
+
120
+ const layoutAppear = () => {
121
+ LayoutAnimation.configureNext({
122
+ duration: Platform.OS == 'ios' ? animationDuration : 20,
123
+ create: {type: 'linear', property: 'opacity'},
124
+ update: {type: 'linear', property: 'scaleXY'},
125
+ });
126
+ setTimeout(() => elevate(), Platform.OS == 'ios' ? 10 : 100);
127
+ };
128
+
129
+ const static2DSimple = () => {
130
+ return (
131
+ <>
132
+ <TouchableOpacity
133
+ disabled={disablePress}
134
+ activeOpacity={activeOpacity}
135
+ onPress={() => {
136
+ setSelectedIndex(index);
137
+ if (item.onPress) {
138
+ item.onPress();
139
+ } else if (props.onPress) {
140
+ props.onPress(item, index);
141
+ }
142
+ }}
143
+ onLongPress={() => {
144
+ if (item.onLongPress) {
145
+ item.onLongPress();
146
+ } else if (props.onLongPress) {
147
+ props.onLongPress(item, index);
148
+ }
149
+ }}
150
+ onPressOut={() => {
151
+ if (item.onPressOut) {
152
+ item.onPressOut();
153
+ } else if (props.onPressOut) {
154
+ props.onPressOut(item, index);
155
+ }
156
+ }}
157
+ style={[
158
+ {
159
+ position: 'absolute',
160
+ width: item.stacks[0].barWidth || props.barWidth || 30,
161
+ height: '100%',
162
+ borderTopLeftRadius:
163
+ borderTopLeftRadius ??
164
+ borderRadius ??
165
+ stackBorderTopLeftRadius ??
166
+ stackBorderRadius,
167
+ borderTopRightRadius:
168
+ borderTopRightRadius ??
169
+ borderRadius ??
170
+ stackBorderTopRightRadius ??
171
+ stackBorderRadius,
172
+ borderBottomLeftRadius:
173
+ borderBottomLeftRadius ??
174
+ borderRadius ??
175
+ stackBorderBottomLeftRadius ??
176
+ stackBorderRadius,
177
+ borderBottomRightRadius:
178
+ borderBottomRightRadius ??
179
+ borderRadius ??
180
+ stackBorderBottomRightRadius ??
181
+ stackBorderRadius,
182
+ overflow: lowestBarPosition ? 'visible' : 'hidden',
183
+ },
184
+ ]}>
185
+ {item.stacks.map((stackItem, index) => {
186
+ const borderRadii = getStackBorderRadii(item, index);
187
+ const barHeight = getBarHeight(
188
+ stackItem.value,
189
+ stackItem.marginBottom,
190
+ );
191
+
192
+ return (
193
+ <TouchableOpacity
194
+ key={index}
195
+ onPress={stackItem.onPress}
196
+ activeOpacity={activeOpacity}
197
+ disabled={disablePress || !stackItem.onPress}
198
+ style={{
199
+ position: 'absolute',
200
+ bottom: getPosition(index) + (stackItem.marginBottom || 0),
201
+ width: '100%',
202
+ height: barHeight,
203
+ backgroundColor:
204
+ stackItem.color || item.color || props.color || 'black',
205
+ borderWidth: barBorderWidth ?? 0,
206
+ borderColor: barBorderColor,
207
+ ...borderRadii,
208
+ }}>
209
+ {stackItem.showGradient ||
210
+ item.showGradient ||
211
+ props.showGradient ? (
212
+ <LinearGradient
213
+ style={{
214
+ position: 'absolute',
215
+ width: '100%',
216
+ height: '100%',
217
+ ...borderRadii,
218
+ }}
219
+ start={{x: 0, y: 0}}
220
+ end={{x: 0, y: 1}}
221
+ colors={[
222
+ stackItem.gradientColor ||
223
+ item.gradientColor ||
224
+ props.gradientColor ||
225
+ 'white',
226
+ stackItem.color || item.color || props.color || 'black',
227
+ ]}
228
+ />
229
+ ) : null}
230
+ {stackItem.innerBarComponent && stackItem.innerBarComponent()}
231
+ </TouchableOpacity>
232
+ );
233
+ })}
234
+ {(item.barBackgroundPattern || barBackgroundPattern) && (
235
+ <Svg>
236
+ <Defs>
237
+ {item.barBackgroundPattern
238
+ ? item.barBackgroundPattern()
239
+ : barBackgroundPattern?.()}
240
+ </Defs>
241
+ <Rect
242
+ stroke="transparent"
243
+ x="1"
244
+ y="1"
245
+ width="100%"
246
+ height="100%"
247
+ fill={`url(#${item.patternId || patternId})`}
248
+ />
249
+ </Svg>
250
+ )}
251
+ </TouchableOpacity>
252
+ {localBarInnerComponent ? (
253
+ <View style={{height: '100%', width: '100%'}}>
254
+ {localBarInnerComponent(item, index)}
255
+ </View>
256
+ ) : null}
257
+ {(item.topLabelComponent || showValuesAsTopLabel) && (
258
+ <View
259
+ style={[
260
+ {
261
+ position: 'absolute',
262
+ top: cotainsNegative
263
+ ? 0
264
+ : (item.barWidth || props.barWidth || 30) * -1,
265
+ height: item.barWidth || props.barWidth || 30,
266
+ width: item.barWidth || props.barWidth || 30,
267
+ justifyContent: 'center',
268
+ alignItems: 'center',
269
+ },
270
+ cotainsNegative && {transform: [{translateY: totalHeight * 2}]},
271
+ props.horizontal &&
272
+ !props.intactTopLabel && {transform: [{rotate: '270deg'}]},
273
+ item.topLabelContainerStyle,
274
+ ]}>
275
+ {showValuesAsTopLabel ? (
276
+ <Text style={item.topLabelTextStyle}>
277
+ {item.stacks.reduce((acc, stack) => acc + stack.value, 0)}
278
+ </Text>
279
+ ) : (
280
+ item.topLabelComponent?.()
281
+ )}
282
+ </View>
283
+ )}
284
+ </>
285
+ );
286
+ };
287
+
288
+ const barWrapper = () => {
289
+ return noAnimation ? (
290
+ static2DSimple()
291
+ ) : (
292
+ <View
293
+ style={{
294
+ position: 'absolute',
295
+ bottom: 0,
296
+ height: height,
297
+ width: '100%',
298
+ overflow: 'hidden',
299
+ }}>
300
+ {static2DSimple()}
301
+ </View>
302
+ );
303
+ };
304
+
305
+ return (
306
+ <>
307
+ <View
308
+ pointerEvents={
309
+ props.pointerConfig
310
+ ? props.pointerConfig.pointerEvents ?? 'none'
311
+ : 'auto'
312
+ }
313
+ style={[
314
+ {
315
+ // overflow: 'visible',
316
+ marginBottom: 60 + xAxisLabelsVerticalShift,
317
+ width: item.stacks[0].barWidth || props.barWidth || 30,
318
+ height: totalHeight,
319
+ marginRight: spacing,
320
+ },
321
+
322
+ props.pointerConfig
323
+ ? {
324
+ transform: [
325
+ {
326
+ translateY:
327
+ (containerHeight || 200) -
328
+ (totalHeight - 10 + xAxisLabelsVerticalShift),
329
+ },
330
+ ],
331
+ }
332
+ : null,
333
+ ]}>
334
+ {/* {props.showVerticalLines && (
335
+ <View
336
+ style={{
337
+ zIndex: props.verticalLinesZIndex,
338
+ position: 'absolute',
339
+ height: (containerHeight || 200) + 15,
340
+ width: props.verticalLinesThickness,
341
+ bottom: 0,
342
+ left: (item.barWidth || props.barWidth || 30) / 2,
343
+ backgroundColor: props.verticalLinesColor,
344
+ }}
345
+ />
346
+ )} */}
347
+ {(props.showXAxisIndices || item.showXAxisIndex) && (
348
+ <View
349
+ style={{
350
+ zIndex: 2,
351
+ position: 'absolute',
352
+ height: props.xAxisIndicesHeight,
353
+ width: props.xAxisIndicesWidth,
354
+ bottom: props.xAxisIndicesHeight / -2,
355
+ left:
356
+ ((item.barWidth || props.barWidth || 30) -
357
+ props.xAxisIndicesWidth) /
358
+ 2,
359
+ backgroundColor: props.xAxisIndicesColor,
360
+ }}
361
+ />
362
+ )}
363
+ {barWrapper()}
364
+ {renderLabel(label || '', labelTextStyle)}
365
+ </View>
366
+ {renderTooltip && selectedIndex === index && (
367
+ <View
368
+ style={{
369
+ position: 'absolute',
370
+ bottom: totalHeight + 60,
371
+ left:
372
+ index === stackData.length - 1
373
+ ? leftSpacing - leftShiftForLastIndexTooltip
374
+ : leftSpacing -
375
+ (item.leftShiftForTooltip ?? leftShiftForTooltip ?? 0),
376
+ zIndex: 1000,
377
+ }}>
378
+ {renderTooltip(item, index)}
379
+ </View>
380
+ )}
381
+ </>
382
+ );
383
+ };
384
+
385
+ export default RenderStackBars;