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,267 @@
1
+ import React, {useEffect} from 'react';
2
+ import {
3
+ PieChartPropsType,
4
+ pieColors,
5
+ usePiePro,
6
+ } from 'gifted-charts-core';
7
+ import {
8
+ Defs,
9
+ Path,
10
+ Stop,
11
+ Svg,
12
+ Text as SvgText,
13
+ RadialGradient,
14
+ } from 'react-native-svg';
15
+ import {Animated, View} from 'react-native';
16
+
17
+ export const PieChartPro = (props: PieChartPropsType) => {
18
+ const {
19
+ radius,
20
+ total,
21
+ donut,
22
+ strokeWidth,
23
+ maxStrokeWidth,
24
+ animationDuration,
25
+ initial,
26
+ dInitial,
27
+ dFinal,
28
+ getStartCaps,
29
+ getEndCaps,
30
+ getTextCoordinates,
31
+ height,
32
+ heightFactor,
33
+ svgProps,
34
+ } = usePiePro(props);
35
+
36
+ const {
37
+ data,
38
+ curvedStartEdges,
39
+ curvedEndEdges,
40
+ edgesRadius = 0,
41
+ showGradient,
42
+ ring,
43
+ centerLabelComponent,
44
+ strokeDashArray,
45
+ semiCircle,
46
+ } = props;
47
+
48
+ let {isAnimated} = props;
49
+
50
+ if (!props.semiCircle && data.some(dataItem => dataItem.value > total / 2)) {
51
+ // if we have an obtuse arc, we cant animate
52
+ isAnimated = false;
53
+ }
54
+
55
+ const AnimatedPath = Animated.createAnimatedComponent(Path);
56
+ const AnimatedText = Animated.createAnimatedComponent(SvgText);
57
+
58
+ const animatedValues = data.map(i => new Animated.Value(0));
59
+ const animatedOpacityValue = new Animated.Value(0);
60
+ const animatedPaths = data.map((item, index) =>
61
+ animatedValues[index]?.interpolate({
62
+ inputRange: [0, 1],
63
+ outputRange: [dInitial[index], dFinal[index]],
64
+ }),
65
+ );
66
+
67
+ const animatedOpacity = animatedOpacityValue.interpolate({
68
+ inputRange: [0, 1],
69
+ outputRange: [0, 1],
70
+ });
71
+
72
+ useEffect(() => {
73
+ Animated.timing(animatedOpacityValue, {
74
+ toValue: 1,
75
+ duration: 10,
76
+ useNativeDriver: true,
77
+ delay: animationDuration,
78
+ }).start();
79
+ animatedValues.forEach(animatedValue =>
80
+ Animated.timing(animatedValue, {
81
+ toValue: 1,
82
+ duration: animationDuration,
83
+ useNativeDriver: true,
84
+ }).start(),
85
+ );
86
+ }, [data]);
87
+
88
+ const adjustHeight = height * heightFactor;
89
+ const rnSvgProps = semiCircle ? {} : svgProps;
90
+
91
+ return (
92
+ <View
93
+ style={{
94
+ display: 'flex',
95
+ justifyContent: 'center',
96
+ alignItems: 'center',
97
+ height: adjustHeight,
98
+ width: height * 2,
99
+ }}>
100
+ <View
101
+ style={
102
+ semiCircle
103
+ ? {position: 'absolute', bottom: 0}
104
+ : {position: 'absolute'}
105
+ }>
106
+ {centerLabelComponent ? centerLabelComponent() : null}
107
+ </View>
108
+ <Svg
109
+ {...rnSvgProps}
110
+ viewBox={
111
+ semiCircle
112
+ ? ``
113
+ : `${-maxStrokeWidth * 1.5} ${
114
+ -maxStrokeWidth - (semiCircle ? height / 2 : 0)
115
+ } ${adjustHeight} ${adjustHeight}`
116
+ }
117
+ transform={
118
+ semiCircle
119
+ ? []
120
+ : [{scaleY: maxStrokeWidth ? 1 + maxStrokeWidth / (radius * 2) : 1}]
121
+ }>
122
+ {total ? (
123
+ <>
124
+ <Defs>
125
+ {data.map((item, index) => {
126
+ return (
127
+ <RadialGradient
128
+ key={index + ''}
129
+ id={'grad' + index}
130
+ cx="50%"
131
+ cy="50%"
132
+ rx="50%"
133
+ ry="50%"
134
+ fx="50%"
135
+ fy="50%"
136
+ gradientUnits="userSpaceOnUse">
137
+ <Stop
138
+ offset="0%"
139
+ stopColor={item.gradientCenterColor}
140
+ stopOpacity="1"
141
+ />
142
+ <Stop
143
+ offset="100%"
144
+ stopColor={item.color || pieColors[index % 9]}
145
+ stopOpacity="1"
146
+ />
147
+ </RadialGradient>
148
+ );
149
+ })}
150
+ </Defs>
151
+ {data.map((item, index) => {
152
+ const borderWidth = item.strokeWidth ?? strokeWidth;
153
+ const borderColor =
154
+ item.strokeColor ??
155
+ props.strokeColor ??
156
+ (borderWidth ? 'black' : 'transparent');
157
+ const strokeDashArrayLocal =
158
+ item.strokeDashArray ?? strokeDashArray;
159
+ return (
160
+ <AnimatedPath
161
+ key={`path${index}`}
162
+ id="renderPath"
163
+ d={isAnimated ? animatedPaths[index] : dFinal[index]}
164
+ fill={
165
+ ring
166
+ ? 'transparent'
167
+ : showGradient
168
+ ? `url(#grad${index})`
169
+ : data[index].color || pieColors[index % 9]
170
+ }
171
+ strokeWidth={borderWidth}
172
+ strokeDasharray={strokeDashArrayLocal}
173
+ stroke={borderColor}
174
+ />
175
+ );
176
+ })}
177
+
178
+ {donut
179
+ ? data.map((item, index) => {
180
+ if (
181
+ curvedStartEdges ||
182
+ edgesRadius ||
183
+ item.isStartEdgeCurved ||
184
+ item.startEdgeRadius
185
+ )
186
+ return (
187
+ <AnimatedPath
188
+ key={`cap${index}`}
189
+ d={`${initial} ${getStartCaps(index, item)}`}
190
+ opacity={isAnimated ? animatedOpacity : 1}
191
+ fill={
192
+ showGradient
193
+ ? `url(#grad${index})`
194
+ : data[index].color || pieColors[index % 9]
195
+ }
196
+ />
197
+ );
198
+ return null;
199
+ })
200
+ : null}
201
+
202
+ {donut
203
+ ? data.map((item, index) => {
204
+ if (
205
+ curvedEndEdges ||
206
+ edgesRadius ||
207
+ item.isEndEdgeCurved ||
208
+ item.endEdgeRadius
209
+ )
210
+ return (
211
+ <Path
212
+ key={`cap${index}`}
213
+ d={`${initial} ${getEndCaps(index, item)}`}
214
+ fill={
215
+ showGradient
216
+ ? `url(#grad${index})`
217
+ : data[index].color || pieColors[index % 9]
218
+ }
219
+ />
220
+ );
221
+ return null;
222
+ })
223
+ : null}
224
+
225
+ {data.map((item, index) => {
226
+ const {x, y} = getTextCoordinates(index, item.labelPosition);
227
+
228
+ return (
229
+ <AnimatedText
230
+ key={`label${index}`}
231
+ // style={{ pointerEvents: 'all' }}
232
+ fill={
233
+ item.textColor ||
234
+ props.textColor ||
235
+ pieColors[(index + 2) % 9]
236
+ }
237
+ opacity={isAnimated ? animatedOpacity : 1}
238
+ fontSize={item.textSize || props.textSize}
239
+ fontFamily={item.font || props.font}
240
+ fontWeight={item.fontWeight || props.fontWeight}
241
+ fontStyle={item.fontStyle || props.fontStyle || 'normal'}
242
+ x={
243
+ x +
244
+ (item.shiftTextX || 0) -
245
+ (item.textSize ?? props.textSize ?? 0) / 1.8
246
+ }
247
+ y={y + (item.shiftTextY || 0)}
248
+ onPress={() => {
249
+ item.onLabelPress
250
+ ? item.onLabelPress()
251
+ : props.onLabelPress
252
+ ? props.onLabelPress(item, index)
253
+ : item.onPress
254
+ ? item.onPress()
255
+ : props.onPress?.(item, index);
256
+ }}>
257
+ {item.text ||
258
+ (props.showValuesAsLabels ? item.value + '' : '')}
259
+ </AnimatedText>
260
+ );
261
+ })}
262
+ </>
263
+ ) : null}
264
+ </Svg>
265
+ </View>
266
+ );
267
+ };