react-native-gifted-charts 1.4.8 → 1.4.9

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.8",
3
+ "version": "1.4.9",
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.1"
27
+ "gifted-charts-core": "^0.1.3"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@babel/core": "^7.22.5",
@@ -1,5 +1,9 @@
1
1
  import React, {useEffect} from 'react';
2
- import {PieChartPropsType, pieColors, usePiePro} from 'gifted-charts-core';
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
- <Svg height={radius * 2 + strokeWidth} width={radius * 2 + strokeWidth}>
78
- {total ? (
79
- <>
80
- <Defs>
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
- <RadialGradient
84
- key={index + ''}
85
- id={'grad' + index}
86
- cx="50%"
87
- cy="50%"
88
- rx="50%"
89
- ry="50%"
90
- fx="50%"
91
- fy="50%"
92
- gradientUnits="userSpaceOnUse">
93
- <Stop
94
- offset="0%"
95
- stopColor={item.gradientCenterColor}
96
- stopOpacity="1"
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
- {donut
130
- ? data.map((item, index) => {
131
- if (
132
- curvedStartEdges ||
133
- edgesRadius ||
134
- item.isStartEdgeCurved ||
135
- item.startEdgeRadius
136
- )
137
- return (
138
- <AnimatedPath
139
- key={`cap${index}`}
140
- d={`${initial} ${getStartCaps(index, item)}`}
141
- opacity={isAnimated ? animatedOpacity : 1}
142
- fill={
143
- showGradient
144
- ? `url(#grad${index})`
145
- : data[index].color || pieColors[index % 9]
146
- }
147
- />
148
- );
149
- return null;
150
- })
151
- : null}
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
- {donut
154
- ? data.map((item, index) => {
155
- if (
156
- curvedEndEdges ||
157
- edgesRadius ||
158
- item.isEndEdgeCurved ||
159
- item.endEdgeRadius
160
- )
161
- return (
162
- <Path
163
- key={`cap${index}`}
164
- d={`${initial} ${getEndCaps(index, item)}`}
165
- fill={
166
- showGradient
167
- ? `url(#grad${index})`
168
- : data[index].color || pieColors[index % 9]
169
- }
170
- />
171
- );
172
- return null;
173
- })
174
- : null}
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
- {data.map((item, index) => {
177
- const {x, y} = getTextCoordinates(index, item.labelPosition);
225
+ {data.map((item, index) => {
226
+ const {x, y} = getTextCoordinates(index, item.labelPosition);
178
227
 
179
- return (
180
- <AnimatedText
181
- key={`label${index}`}
182
- // style={{ pointerEvents: 'all' }}
183
- fill={
184
- item.textColor ||
185
- props.textColor ||
186
- pieColors[(index + 2) % 9]
187
- }
188
- opacity={isAnimated ? animatedOpacity : 1}
189
- fontSize={item.textSize || props.textSize}
190
- fontFamily={item.font || props.font}
191
- fontWeight={item.fontWeight || props.fontWeight}
192
- fontStyle={item.fontStyle || props.fontStyle || 'normal'}
193
- x={
194
- x +
195
- (item.shiftTextX || 0) -
196
- (item.textSize ?? props.textSize ?? 0) / 1.8
197
- }
198
- y={y + (item.shiftTextY || 0)}
199
- onPress={() => {
200
- item.onLabelPress
201
- ? item.onLabelPress()
202
- : props.onLabelPress
203
- ? props.onLabelPress(item, index)
204
- : item.onPress
205
- ? item.onPress()
206
- : props.onPress?.(item, index);
207
- }}>
208
- {item.text || (props.showValuesAsLabels ? item.value + '' : '')}
209
- </AnimatedText>
210
- );
211
- })}
212
- </>
213
- ) : null}
214
- </Svg>
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
  };