react-native-gifted-charts 1.4.8 → 1.4.10
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-gifted-charts",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.10",
|
|
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
5
|
"main": "src/index.tsx",
|
|
6
6
|
"files": [
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"registry": "https://registry.npmjs.org/"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"gifted-charts-core": "^0.1.
|
|
27
|
+
"gifted-charts-core": "^0.1.4"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@babel/core": "^7.22.5",
|
|
@@ -52,6 +52,7 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
|
|
|
52
52
|
|
|
53
53
|
onEndReached,
|
|
54
54
|
onStartReached,
|
|
55
|
+
onMomentumScrollEnd,
|
|
55
56
|
} = props;
|
|
56
57
|
|
|
57
58
|
const {
|
|
@@ -77,7 +78,7 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
|
|
|
77
78
|
verticalLinesProps,
|
|
78
79
|
lineInBarChartProps,
|
|
79
80
|
lineInBarChartProps2,
|
|
80
|
-
} = useBarAndLineChartsWrapper({...props, isRTL:I18nManager.isRTL});
|
|
81
|
+
} = useBarAndLineChartsWrapper({...props, isRTL: I18nManager.isRTL});
|
|
81
82
|
|
|
82
83
|
useEffect(() => {
|
|
83
84
|
if (pointerConfig && getPointerProps) {
|
|
@@ -124,6 +125,9 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
|
|
|
124
125
|
setCanMomentum(true);
|
|
125
126
|
}}
|
|
126
127
|
onMomentumScrollEnd={({nativeEvent}) => {
|
|
128
|
+
if (onMomentumScrollEnd) {
|
|
129
|
+
onMomentumScrollEnd();
|
|
130
|
+
}
|
|
127
131
|
if (isCloseToEnd(nativeEvent) && canMomentum) {
|
|
128
132
|
onEndReached ? onEndReached() : null;
|
|
129
133
|
setCanMomentum(false);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import React, {useEffect} from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
PieChartPropsType,
|
|
4
|
+
pieColors,
|
|
5
|
+
usePiePro,
|
|
6
|
+
} from 'gifted-charts-core';
|
|
3
7
|
import {
|
|
4
8
|
Defs,
|
|
5
9
|
Path,
|
|
@@ -8,7 +12,7 @@ import {
|
|
|
8
12
|
Text as SvgText,
|
|
9
13
|
RadialGradient,
|
|
10
14
|
} from 'react-native-svg';
|
|
11
|
-
import {Animated} from 'react-native';
|
|
15
|
+
import {Animated, View} from 'react-native';
|
|
12
16
|
|
|
13
17
|
export const PieChartPro = (props: PieChartPropsType) => {
|
|
14
18
|
const {
|
|
@@ -16,6 +20,7 @@ export const PieChartPro = (props: PieChartPropsType) => {
|
|
|
16
20
|
total,
|
|
17
21
|
donut,
|
|
18
22
|
strokeWidth,
|
|
23
|
+
maxStrokeWidth,
|
|
19
24
|
animationDuration,
|
|
20
25
|
initial,
|
|
21
26
|
dInitial,
|
|
@@ -23,6 +28,9 @@ export const PieChartPro = (props: PieChartPropsType) => {
|
|
|
23
28
|
getStartCaps,
|
|
24
29
|
getEndCaps,
|
|
25
30
|
getTextCoordinates,
|
|
31
|
+
height,
|
|
32
|
+
heightFactor,
|
|
33
|
+
svgProps,
|
|
26
34
|
} = usePiePro(props);
|
|
27
35
|
|
|
28
36
|
const {
|
|
@@ -31,6 +39,10 @@ export const PieChartPro = (props: PieChartPropsType) => {
|
|
|
31
39
|
curvedEndEdges,
|
|
32
40
|
edgesRadius = 0,
|
|
33
41
|
showGradient,
|
|
42
|
+
ring,
|
|
43
|
+
pieInnerComponent,
|
|
44
|
+
strokeDashArray,
|
|
45
|
+
semiCircle,
|
|
34
46
|
} = props;
|
|
35
47
|
|
|
36
48
|
let {isAnimated} = props;
|
|
@@ -73,144 +85,183 @@ export const PieChartPro = (props: PieChartPropsType) => {
|
|
|
73
85
|
);
|
|
74
86
|
}, [data]);
|
|
75
87
|
|
|
88
|
+
const adjustHeight = height * heightFactor;
|
|
89
|
+
const rnSvgProps = semiCircle ? {} : svgProps;
|
|
90
|
+
|
|
76
91
|
return (
|
|
77
|
-
<
|
|
78
|
-
{
|
|
79
|
-
|
|
80
|
-
|
|
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
|
+
{pieInnerComponent ? pieInnerComponent() : 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>
|
|
81
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;
|
|
82
159
|
return (
|
|
83
|
-
<
|
|
84
|
-
key={index
|
|
85
|
-
id=
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
<Stop
|
|
99
|
-
offset="100%"
|
|
100
|
-
stopColor={item.color || pieColors[index % 9]}
|
|
101
|
-
stopOpacity="1"
|
|
102
|
-
/>
|
|
103
|
-
</RadialGradient>
|
|
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
|
+
/>
|
|
104
175
|
);
|
|
105
176
|
})}
|
|
106
|
-
</Defs>
|
|
107
|
-
{data.map((item, index) => {
|
|
108
|
-
const borderWidth = item.strokeWidth ?? strokeWidth;
|
|
109
|
-
const borderColor =
|
|
110
|
-
item.strokeColor ??
|
|
111
|
-
props.strokeColor ??
|
|
112
|
-
(borderWidth ? 'black' : 'transparent');
|
|
113
|
-
return (
|
|
114
|
-
<AnimatedPath
|
|
115
|
-
key={`path${index}`}
|
|
116
|
-
id="renderPath"
|
|
117
|
-
d={isAnimated ? animatedPaths[index] : dFinal[index]}
|
|
118
|
-
fill={
|
|
119
|
-
showGradient
|
|
120
|
-
? `url(#grad${index})`
|
|
121
|
-
: data[index].color || pieColors[index % 9]
|
|
122
|
-
}
|
|
123
|
-
strokeWidth={borderWidth}
|
|
124
|
-
stroke={borderColor}
|
|
125
|
-
/>
|
|
126
|
-
);
|
|
127
|
-
})}
|
|
128
177
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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}
|
|
152
201
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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}
|
|
175
224
|
|
|
176
|
-
|
|
177
|
-
|
|
225
|
+
{data.map((item, index) => {
|
|
226
|
+
const {x, y} = getTextCoordinates(index, item.labelPosition);
|
|
178
227
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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>
|
|
215
266
|
);
|
|
216
267
|
};
|