react-native-gifted-charts 1.2.5 → 1.2.6
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 +1 -1
- package/src/BarChart/index.tsx +3 -1
- package/src/LineChart/index.tsx +3 -1
- package/src/PieChart/index.tsx +79 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-gifted-charts",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"description": "The most complete library for Bar, Line, Area, Pie, Donut and Stacked Bar charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
|
|
5
5
|
"main": "src/index.tsx",
|
|
6
6
|
"files": [
|
package/src/BarChart/index.tsx
CHANGED
|
@@ -845,7 +845,9 @@ export const BarChart = (props: PropTypes) => {
|
|
|
845
845
|
props.hideAxesAndRules !== true &&
|
|
846
846
|
!hideYAxisText &&
|
|
847
847
|
horizSectionsBelow.map((sectionItems, index) => {
|
|
848
|
-
let label = getLabel(
|
|
848
|
+
let label = getLabel(
|
|
849
|
+
horizSectionsBelow[horizSectionsBelow.length - 1 - index].value,
|
|
850
|
+
);
|
|
849
851
|
return (
|
|
850
852
|
<View
|
|
851
853
|
key={index}
|
package/src/LineChart/index.tsx
CHANGED
|
@@ -1866,7 +1866,9 @@ export const LineChart = (props: propTypes) => {
|
|
|
1866
1866
|
props.hideAxesAndRules !== true &&
|
|
1867
1867
|
!hideYAxisText &&
|
|
1868
1868
|
horizSectionsBelow.map((sectionItems, index) => {
|
|
1869
|
-
let label = getLabel(
|
|
1869
|
+
let label = getLabel(
|
|
1870
|
+
horizSectionsBelow[horizSectionsBelow.length - 1 - index].value,
|
|
1871
|
+
);
|
|
1870
1872
|
return (
|
|
1871
1873
|
<View
|
|
1872
1874
|
key={index}
|
package/src/PieChart/index.tsx
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import {ColorValue, View} from 'react-native';
|
|
3
|
-
import Svg, {
|
|
3
|
+
import Svg, {
|
|
4
|
+
Path,
|
|
5
|
+
Circle,
|
|
6
|
+
Text as SvgText,
|
|
7
|
+
FontStyle,
|
|
8
|
+
Defs,
|
|
9
|
+
RadialGradient,
|
|
10
|
+
Stop,
|
|
11
|
+
} from 'react-native-svg';
|
|
4
12
|
|
|
5
13
|
type propTypes = {
|
|
6
14
|
radius?: number;
|
|
@@ -36,12 +44,17 @@ type propTypes = {
|
|
|
36
44
|
tiltAngle?: string;
|
|
37
45
|
initialAngle?: number;
|
|
38
46
|
labelsPosition?: 'onBorder' | 'outward' | 'inward' | 'mid';
|
|
47
|
+
showGradient?: boolean;
|
|
48
|
+
gradientCenterColor?: string;
|
|
49
|
+
onPress?: Function;
|
|
50
|
+
onLabelPress?: Function;
|
|
39
51
|
};
|
|
40
52
|
type itemType = {
|
|
41
53
|
value: number;
|
|
42
54
|
shiftX?: number;
|
|
43
55
|
shiftY?: number;
|
|
44
56
|
color?: string;
|
|
57
|
+
gradientCenterColor?: string;
|
|
45
58
|
text?: string;
|
|
46
59
|
textColor?: string;
|
|
47
60
|
textSize?: number;
|
|
@@ -53,6 +66,8 @@ type itemType = {
|
|
|
53
66
|
shiftTextX?: number;
|
|
54
67
|
shiftTextY?: number;
|
|
55
68
|
labelPosition?: 'onBorder' | 'outward' | 'inward' | 'mid';
|
|
69
|
+
onPress?: Function;
|
|
70
|
+
onLabelPress?: Function;
|
|
56
71
|
};
|
|
57
72
|
|
|
58
73
|
export const PieChart = (props: propTypes) => {
|
|
@@ -102,6 +117,8 @@ export const PieChart = (props: propTypes) => {
|
|
|
102
117
|
const showTextBackground = props.showTextBackground || false;
|
|
103
118
|
const textBackgroundColor = props.textBackgroundColor || 'white';
|
|
104
119
|
const showValuesAsLabels = props.showValuesAsLabels || false;
|
|
120
|
+
const showGradient = props.showGradient || false;
|
|
121
|
+
const gradientCenterColor = props.gradientCenterColor || 'white';
|
|
105
122
|
|
|
106
123
|
const colors = [
|
|
107
124
|
'cyan',
|
|
@@ -186,6 +203,32 @@ export const PieChart = (props: propTypes) => {
|
|
|
186
203
|
}`}
|
|
187
204
|
height={radius * 2 + strokeWidth}
|
|
188
205
|
width={radius * 2 + strokeWidth}>
|
|
206
|
+
<Defs>
|
|
207
|
+
{data.map((item, index) => {
|
|
208
|
+
return (
|
|
209
|
+
<RadialGradient
|
|
210
|
+
id={'grad' + index}
|
|
211
|
+
cx="50%"
|
|
212
|
+
cy="50%"
|
|
213
|
+
rx="50%"
|
|
214
|
+
ry="50%"
|
|
215
|
+
fx="50%"
|
|
216
|
+
fy="50%"
|
|
217
|
+
gradientUnits="userSpaceOnUse">
|
|
218
|
+
<Stop
|
|
219
|
+
offset="0%"
|
|
220
|
+
stopColor={item.gradientCenterColor || gradientCenterColor}
|
|
221
|
+
stopOpacity="1"
|
|
222
|
+
/>
|
|
223
|
+
<Stop
|
|
224
|
+
offset="100%"
|
|
225
|
+
stopColor={item.color || colors[index % 9]}
|
|
226
|
+
stopOpacity="1"
|
|
227
|
+
/>
|
|
228
|
+
</RadialGradient>
|
|
229
|
+
);
|
|
230
|
+
})}
|
|
231
|
+
</Defs>
|
|
189
232
|
{data.map((item, index) => {
|
|
190
233
|
console.log('index', index);
|
|
191
234
|
let nextItem;
|
|
@@ -219,14 +262,24 @@ export const PieChart = (props: propTypes) => {
|
|
|
219
262
|
}`}
|
|
220
263
|
stroke={strokeColor}
|
|
221
264
|
strokeWidth={strokeWidth}
|
|
222
|
-
fill={
|
|
265
|
+
fill={
|
|
266
|
+
showGradient
|
|
267
|
+
? `url(#grad${index})`
|
|
268
|
+
: item.color || colors[index % 9]
|
|
269
|
+
}
|
|
270
|
+
onPress={() => {
|
|
271
|
+
item.onPress
|
|
272
|
+
? item.onPress
|
|
273
|
+
: props.onPress
|
|
274
|
+
? props.onPress(item, index)
|
|
275
|
+
: null;
|
|
276
|
+
}}
|
|
223
277
|
/>
|
|
224
278
|
);
|
|
225
279
|
})}
|
|
226
280
|
|
|
227
281
|
{showText &&
|
|
228
282
|
data.map((item, index) => {
|
|
229
|
-
|
|
230
283
|
let mx = cx * (1 + Math.sin(2 * pi * mData[index] + initialAngle));
|
|
231
284
|
let my = cy * (1 - Math.cos(2 * pi * mData[index] + initialAngle));
|
|
232
285
|
|
|
@@ -270,6 +323,17 @@ export const PieChart = (props: propTypes) => {
|
|
|
270
323
|
textSize
|
|
271
324
|
}
|
|
272
325
|
fill={item.textBackgroundColor || textBackgroundColor}
|
|
326
|
+
onPress={() => {
|
|
327
|
+
item.onLabelPress
|
|
328
|
+
? item.onLabelPress()
|
|
329
|
+
: props.onLabelPress
|
|
330
|
+
? props.onLabelPress(item, index)
|
|
331
|
+
: item.onPress
|
|
332
|
+
? item.onPress()
|
|
333
|
+
: props.onPress
|
|
334
|
+
? props.onPress(item, index)
|
|
335
|
+
: null;
|
|
336
|
+
}}
|
|
273
337
|
/>
|
|
274
338
|
)}
|
|
275
339
|
<SvgText
|
|
@@ -283,7 +347,18 @@ export const PieChart = (props: propTypes) => {
|
|
|
283
347
|
(item.shiftTextX || 0) -
|
|
284
348
|
(item.textSize || textSize) / 1.8
|
|
285
349
|
}
|
|
286
|
-
y={y + (item.shiftTextY || 0)}
|
|
350
|
+
y={y + (item.shiftTextY || 0)}
|
|
351
|
+
onPress={() => {
|
|
352
|
+
item.onLabelPress
|
|
353
|
+
? item.onLabelPress()
|
|
354
|
+
: props.onLabelPress
|
|
355
|
+
? props.onLabelPress(item, index)
|
|
356
|
+
: item.onPress
|
|
357
|
+
? item.onPress()
|
|
358
|
+
: props.onPress
|
|
359
|
+
? props.onPress(item, index)
|
|
360
|
+
: null;
|
|
361
|
+
}}>
|
|
287
362
|
{item.text || (showValuesAsLabels ? item.value + '' : '')}
|
|
288
363
|
</SvgText>
|
|
289
364
|
</>
|