react-native-gifted-charts 1.4.12 → 1.4.13

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