react-native-gifted-charts 1.4.12 → 1.4.14
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 +6 -10
- package/src/BarChart/Animated2DWithGradient.tsx +197 -0
- package/src/BarChart/RenderBars.tsx +458 -0
- package/src/BarChart/RenderStackBars.tsx +385 -0
- package/src/BarChart/index.tsx +381 -0
- package/src/BarChart/styles.tsx +47 -0
- package/src/Components/AnimatedThreeDBar/index.tsx +258 -0
- package/src/Components/AnimatedThreeDBar/styles.tsx +14 -0
- package/src/Components/BarAndLineChartsWrapper/index.tsx +244 -0
- package/src/Components/BarAndLineChartsWrapper/renderHorizSections.tsx +590 -0
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.tsx +147 -0
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.tsx +157 -0
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.tsx +86 -0
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.tsx +42 -0
- package/src/Components/BarAndLineChartsWrapper/renderVerticalLines.tsx +131 -0
- package/src/Components/BarSpecificComponents/barBackgroundPattern.tsx +30 -0
- package/src/Components/BarSpecificComponents/cap.tsx +34 -0
- package/src/Components/common/LinearGradient.tsx +27 -0
- package/src/Components/common/Pointer.tsx +37 -0
- package/src/Components/common/StripAndLabel.tsx +98 -0
- package/src/Components/lineSvg.tsx +42 -0
- package/src/LineChart/LineChartBicolor.tsx +740 -0
- package/src/LineChart/index.tsx +2158 -0
- package/src/LineChart/styles.tsx +47 -0
- package/src/PieChart/index.tsx +165 -0
- package/src/PieChart/main.tsx +363 -0
- package/src/PieChartPro/index.tsx +267 -0
- package/src/PopulationPyramid/index.tsx +603 -0
- package/src/index.tsx +25 -0
- package/src/todos.md +23 -0
- package/src/utils/index.ts +16 -0
- package/dist/BarChart/Animated2DWithGradient.js +0 -1
- package/dist/BarChart/RenderBars.js +0 -1
- package/dist/BarChart/RenderStackBars.js +0 -1
- package/dist/BarChart/index.js +0 -1
- package/dist/BarChart/styles.js +0 -1
- package/dist/Components/AnimatedThreeDBar/index.js +0 -1
- package/dist/Components/AnimatedThreeDBar/styles.js +0 -1
- package/dist/Components/BarAndLineChartsWrapper/index.js +0 -1
- package/dist/Components/BarAndLineChartsWrapper/renderHorizSections.js +0 -1
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.js +0 -1
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.js +0 -1
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.js +0 -1
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.js +0 -1
- package/dist/Components/BarAndLineChartsWrapper/renderVerticalLines.js +0 -1
- package/dist/Components/BarSpecificComponents/barBackgroundPattern.js +0 -1
- package/dist/Components/BarSpecificComponents/cap.js +0 -1
- package/dist/Components/common/LinearGradient.js +0 -1
- package/dist/Components/common/Pointer.js +0 -1
- package/dist/Components/common/StripAndLabel.js +0 -1
- package/dist/Components/lineSvg.js +0 -1
- package/dist/LineChart/LineChartBicolor.js +0 -1
- package/dist/LineChart/index.js +0 -1
- package/dist/LineChart/styles.js +0 -1
- package/dist/PieChart/index.js +0 -1
- package/dist/PieChart/main.js +0 -1
- package/dist/PieChartPro/index.js +0 -1
- package/dist/PopulationPyramid/index.js +0 -1
- package/dist/index.js +0 -1
- package/dist/utils/index.js +0 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {StyleSheet} from 'react-native';
|
|
2
|
+
|
|
3
|
+
export const styles = StyleSheet.create({
|
|
4
|
+
container: {
|
|
5
|
+
width: '100%',
|
|
6
|
+
marginBottom: 40,
|
|
7
|
+
marginRight: 40,
|
|
8
|
+
},
|
|
9
|
+
horizBar: {
|
|
10
|
+
flexDirection: 'row',
|
|
11
|
+
},
|
|
12
|
+
leftLabel: {
|
|
13
|
+
justifyContent: 'center',
|
|
14
|
+
alignItems: 'center',
|
|
15
|
+
},
|
|
16
|
+
lastLeftLabel: {
|
|
17
|
+
justifyContent: 'center',
|
|
18
|
+
alignItems: 'center',
|
|
19
|
+
},
|
|
20
|
+
leftPart: {
|
|
21
|
+
justifyContent: 'center',
|
|
22
|
+
// width: '100%',
|
|
23
|
+
},
|
|
24
|
+
lastLeftPart: {
|
|
25
|
+
justifyContent: 'flex-end',
|
|
26
|
+
// width: '100%',
|
|
27
|
+
},
|
|
28
|
+
line: {
|
|
29
|
+
width: '100%',
|
|
30
|
+
height: 1,
|
|
31
|
+
backgroundColor: 'gray',
|
|
32
|
+
opacity: 0.5,
|
|
33
|
+
},
|
|
34
|
+
lastLine: {
|
|
35
|
+
width: '100%',
|
|
36
|
+
height: 1,
|
|
37
|
+
backgroundColor: 'black',
|
|
38
|
+
},
|
|
39
|
+
bottomLabel: {
|
|
40
|
+
width: '100%',
|
|
41
|
+
},
|
|
42
|
+
customDataPointContainer: {
|
|
43
|
+
position: 'absolute',
|
|
44
|
+
justifyContent: 'center',
|
|
45
|
+
alignItems: 'center',
|
|
46
|
+
},
|
|
47
|
+
});
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {View} from 'react-native';
|
|
3
|
+
import {PieChartMain} from './main';
|
|
4
|
+
import {PieChartPropsType, pieColors, usePieChart} from 'gifted-charts-core';
|
|
5
|
+
|
|
6
|
+
export const PieChart = (props: PieChartPropsType) => {
|
|
7
|
+
const {
|
|
8
|
+
radius,
|
|
9
|
+
extraRadiusForFocused,
|
|
10
|
+
selectedIndex,
|
|
11
|
+
setSelectedIndex,
|
|
12
|
+
startAngle,
|
|
13
|
+
total,
|
|
14
|
+
donut,
|
|
15
|
+
isThreeD,
|
|
16
|
+
semiCircle,
|
|
17
|
+
inwardExtraLengthForFocused,
|
|
18
|
+
canvasWidth,
|
|
19
|
+
canvasHeight,
|
|
20
|
+
innerRadius,
|
|
21
|
+
innerCircleColor,
|
|
22
|
+
innerCircleBorderWidth,
|
|
23
|
+
innerCircleBorderColor,
|
|
24
|
+
shiftInnerCenterX,
|
|
25
|
+
shiftInnerCenterY,
|
|
26
|
+
tiltAngle,
|
|
27
|
+
isDataShifted,
|
|
28
|
+
paddingHorizontal,
|
|
29
|
+
paddingVertical,
|
|
30
|
+
} = usePieChart(props);
|
|
31
|
+
|
|
32
|
+
const renderInnerCircle = (innerRadius, innerCircleBorderWidth) => {
|
|
33
|
+
if (props.centerLabelComponent || (donut && !isDataShifted)) {
|
|
34
|
+
return (
|
|
35
|
+
<View
|
|
36
|
+
style={[
|
|
37
|
+
{
|
|
38
|
+
height: innerRadius * 2,
|
|
39
|
+
width: innerRadius * 2,
|
|
40
|
+
borderRadius: innerRadius,
|
|
41
|
+
position: 'absolute',
|
|
42
|
+
// zIndex: 100,
|
|
43
|
+
alignSelf: 'center',
|
|
44
|
+
backgroundColor: innerCircleColor,
|
|
45
|
+
left:
|
|
46
|
+
canvasWidth / 2 -
|
|
47
|
+
innerRadius +
|
|
48
|
+
shiftInnerCenterX +
|
|
49
|
+
extraRadiusForFocused +
|
|
50
|
+
paddingHorizontal / 2,
|
|
51
|
+
top:
|
|
52
|
+
canvasHeight / 2 -
|
|
53
|
+
innerRadius +
|
|
54
|
+
shiftInnerCenterY +
|
|
55
|
+
extraRadiusForFocused +
|
|
56
|
+
paddingVertical / 2,
|
|
57
|
+
borderWidth: innerCircleBorderWidth,
|
|
58
|
+
borderColor: innerCircleBorderColor,
|
|
59
|
+
justifyContent: 'center',
|
|
60
|
+
alignItems: 'center',
|
|
61
|
+
},
|
|
62
|
+
isThreeD && {
|
|
63
|
+
borderTopWidth: innerCircleBorderWidth * 5,
|
|
64
|
+
borderLeftWidth: shiftInnerCenterX
|
|
65
|
+
? innerCircleBorderWidth * 2
|
|
66
|
+
: innerCircleBorderWidth,
|
|
67
|
+
transform: [{rotateX: tiltAngle}],
|
|
68
|
+
},
|
|
69
|
+
semiCircle &&
|
|
70
|
+
isThreeD && {
|
|
71
|
+
borderTopWidth: isThreeD
|
|
72
|
+
? innerCircleBorderWidth * 5
|
|
73
|
+
: innerCircleBorderWidth,
|
|
74
|
+
borderLeftWidth: 0.5,
|
|
75
|
+
borderLeftColor: innerCircleColor,
|
|
76
|
+
borderBottomWidth: 0,
|
|
77
|
+
borderRightWidth: 0.5,
|
|
78
|
+
borderRightColor: innerCircleColor,
|
|
79
|
+
},
|
|
80
|
+
]}>
|
|
81
|
+
<View style={{marginTop: semiCircle ? -0.5 * innerRadius : 0}}>
|
|
82
|
+
{props.centerLabelComponent ? props.centerLabelComponent() : null}
|
|
83
|
+
</View>
|
|
84
|
+
</View>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
if (!total) return null;
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<View
|
|
94
|
+
style={{
|
|
95
|
+
height:
|
|
96
|
+
(radius + extraRadiusForFocused + paddingVertical / 2) *
|
|
97
|
+
(props.semiCircle ? 1 : 2),
|
|
98
|
+
width: (radius + extraRadiusForFocused + paddingHorizontal / 2) * 2,
|
|
99
|
+
overflow: 'hidden',
|
|
100
|
+
}}>
|
|
101
|
+
<View style={{position: 'absolute'}}>
|
|
102
|
+
<PieChartMain
|
|
103
|
+
{...props}
|
|
104
|
+
selectedIndex={selectedIndex}
|
|
105
|
+
setSelectedIndex={setSelectedIndex}
|
|
106
|
+
paddingHorizontal={paddingHorizontal}
|
|
107
|
+
paddingVertical={paddingVertical}
|
|
108
|
+
extraRadiusForFocused={extraRadiusForFocused}
|
|
109
|
+
/>
|
|
110
|
+
</View>
|
|
111
|
+
{renderInnerCircle(innerRadius, innerCircleBorderWidth)}
|
|
112
|
+
{props.data.length > 1 &&
|
|
113
|
+
props.data[selectedIndex] && // don't forget to add this one so there are no errors when the data is empty / updating
|
|
114
|
+
(props.focusOnPress || props.sectionAutoFocus) &&
|
|
115
|
+
selectedIndex !== -1 && (
|
|
116
|
+
<View
|
|
117
|
+
pointerEvents="box-none"
|
|
118
|
+
style={{
|
|
119
|
+
position: 'absolute',
|
|
120
|
+
top: -extraRadiusForFocused,
|
|
121
|
+
left: -extraRadiusForFocused,
|
|
122
|
+
}}>
|
|
123
|
+
<PieChartMain
|
|
124
|
+
{...props}
|
|
125
|
+
data={[
|
|
126
|
+
{
|
|
127
|
+
value: props.data[selectedIndex].value,
|
|
128
|
+
text: props.data[selectedIndex].text,
|
|
129
|
+
color:
|
|
130
|
+
props.data[selectedIndex].color ||
|
|
131
|
+
pieColors[selectedIndex % 9],
|
|
132
|
+
strokeColor:
|
|
133
|
+
props.data[selectedIndex].strokeColor || undefined,
|
|
134
|
+
strokeWidth:
|
|
135
|
+
props.data[selectedIndex].strokeWidth || undefined,
|
|
136
|
+
gradientCenterColor:
|
|
137
|
+
props.data[selectedIndex].gradientCenterColor || undefined,
|
|
138
|
+
shiftTextX: props.data[selectedIndex].shiftTextX || undefined,
|
|
139
|
+
shiftTextY: props.data[selectedIndex].shiftTextY || undefined,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
value: total - props.data[selectedIndex].value,
|
|
143
|
+
onPress: () => alert('black'),
|
|
144
|
+
peripheral: true,
|
|
145
|
+
strokeWidth: 0,
|
|
146
|
+
},
|
|
147
|
+
]}
|
|
148
|
+
radius={radius + extraRadiusForFocused}
|
|
149
|
+
initialAngle={startAngle}
|
|
150
|
+
innerRadius={props.innerRadius || radius / 2.5}
|
|
151
|
+
isBiggerPie
|
|
152
|
+
setSelectedIndex={setSelectedIndex}
|
|
153
|
+
paddingHorizontal={paddingHorizontal}
|
|
154
|
+
paddingVertical={paddingVertical}
|
|
155
|
+
extraRadiusForFocused={extraRadiusForFocused}
|
|
156
|
+
/>
|
|
157
|
+
</View>
|
|
158
|
+
)}
|
|
159
|
+
{renderInnerCircle(
|
|
160
|
+
innerRadius - inwardExtraLengthForFocused,
|
|
161
|
+
inwardExtraLengthForFocused ? 0 : innerCircleBorderWidth,
|
|
162
|
+
)}
|
|
163
|
+
</View>
|
|
164
|
+
);
|
|
165
|
+
};
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {View} from 'react-native';
|
|
3
|
+
import Svg, {
|
|
4
|
+
Path,
|
|
5
|
+
Circle,
|
|
6
|
+
Text as SvgText,
|
|
7
|
+
Defs,
|
|
8
|
+
RadialGradient,
|
|
9
|
+
Stop,
|
|
10
|
+
G,
|
|
11
|
+
} from 'react-native-svg';
|
|
12
|
+
import {
|
|
13
|
+
getPieChartMainProps,
|
|
14
|
+
PieChartMainProps,
|
|
15
|
+
pieColors,
|
|
16
|
+
} from 'gifted-charts-core';
|
|
17
|
+
import { rnVersion } from '../utils';
|
|
18
|
+
|
|
19
|
+
export const PieChartMain = (props: PieChartMainProps) => {
|
|
20
|
+
const {
|
|
21
|
+
isThreeD,
|
|
22
|
+
isBiggerPie,
|
|
23
|
+
data,
|
|
24
|
+
showInnerComponent,
|
|
25
|
+
radius,
|
|
26
|
+
canvasWidth,
|
|
27
|
+
canvasHeight,
|
|
28
|
+
shadowWidth,
|
|
29
|
+
backgroundColor,
|
|
30
|
+
shadowColor,
|
|
31
|
+
semiCircle,
|
|
32
|
+
pi,
|
|
33
|
+
initialAngle,
|
|
34
|
+
shadow,
|
|
35
|
+
donut,
|
|
36
|
+
strokeWidth,
|
|
37
|
+
strokeColor,
|
|
38
|
+
innerRadius,
|
|
39
|
+
showText,
|
|
40
|
+
textColor,
|
|
41
|
+
textSize,
|
|
42
|
+
tiltAngle,
|
|
43
|
+
labelsPosition,
|
|
44
|
+
showTextBackground,
|
|
45
|
+
textBackgroundColor,
|
|
46
|
+
showValuesAsLabels,
|
|
47
|
+
showGradient,
|
|
48
|
+
gradientCenterColor,
|
|
49
|
+
toggleFocusOnPress,
|
|
50
|
+
minShiftX,
|
|
51
|
+
minShiftY,
|
|
52
|
+
total,
|
|
53
|
+
horizAdjustment,
|
|
54
|
+
vertAdjustment,
|
|
55
|
+
cx,
|
|
56
|
+
cy,
|
|
57
|
+
pData,
|
|
58
|
+
mData,
|
|
59
|
+
paddingHorizontal,
|
|
60
|
+
paddingVertical,
|
|
61
|
+
extraRadiusForFocused,
|
|
62
|
+
} = getPieChartMainProps(props);
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<View
|
|
66
|
+
pointerEvents="box-none"
|
|
67
|
+
style={[
|
|
68
|
+
{
|
|
69
|
+
backgroundColor: backgroundColor,
|
|
70
|
+
height: semiCircle
|
|
71
|
+
? (canvasHeight + paddingVertical) / 2 + extraRadiusForFocused
|
|
72
|
+
: canvasHeight + paddingVertical + extraRadiusForFocused * 2,
|
|
73
|
+
width: canvasWidth + paddingHorizontal + extraRadiusForFocused * 2,
|
|
74
|
+
overflow: 'hidden',
|
|
75
|
+
},
|
|
76
|
+
isThreeD && {transform: [{rotateX: tiltAngle}]},
|
|
77
|
+
]}>
|
|
78
|
+
<Svg
|
|
79
|
+
pointerEvents={rnVersion >= 720000 ? 'box-none' : 'auto'} // use 'box-none' react-native version 0.72 onwards
|
|
80
|
+
viewBox={`${strokeWidth / -2 + minShiftX - extraRadiusForFocused - paddingHorizontal / 2} ${
|
|
81
|
+
strokeWidth / -2 +
|
|
82
|
+
minShiftY -
|
|
83
|
+
extraRadiusForFocused -
|
|
84
|
+
paddingVertical / 2
|
|
85
|
+
} ${
|
|
86
|
+
(radius + extraRadiusForFocused + strokeWidth) * 2 +
|
|
87
|
+
paddingHorizontal +
|
|
88
|
+
horizAdjustment +
|
|
89
|
+
(horizAdjustment ? strokeWidth : 0)
|
|
90
|
+
} ${
|
|
91
|
+
(radius + extraRadiusForFocused + strokeWidth) * 2 +
|
|
92
|
+
paddingVertical +
|
|
93
|
+
vertAdjustment +
|
|
94
|
+
(vertAdjustment ? strokeWidth : 0)
|
|
95
|
+
}`}
|
|
96
|
+
height={
|
|
97
|
+
(radius + extraRadiusForFocused) * 2 + strokeWidth + paddingVertical
|
|
98
|
+
}
|
|
99
|
+
width={
|
|
100
|
+
(radius + extraRadiusForFocused) * 2 + strokeWidth + paddingHorizontal
|
|
101
|
+
}>
|
|
102
|
+
<Defs>
|
|
103
|
+
{data.map((item, index) => {
|
|
104
|
+
return (
|
|
105
|
+
<RadialGradient
|
|
106
|
+
key={index + ''}
|
|
107
|
+
id={'grad' + index}
|
|
108
|
+
cx="50%"
|
|
109
|
+
cy="50%"
|
|
110
|
+
rx="50%"
|
|
111
|
+
ry="50%"
|
|
112
|
+
fx="50%"
|
|
113
|
+
fy="50%"
|
|
114
|
+
gradientUnits="userSpaceOnUse">
|
|
115
|
+
<Stop
|
|
116
|
+
offset="0%"
|
|
117
|
+
stopColor={item.gradientCenterColor || gradientCenterColor}
|
|
118
|
+
stopOpacity="1"
|
|
119
|
+
/>
|
|
120
|
+
<Stop
|
|
121
|
+
offset="100%"
|
|
122
|
+
stopColor={item.color || pieColors[index % 9]}
|
|
123
|
+
stopOpacity="1"
|
|
124
|
+
/>
|
|
125
|
+
</RadialGradient>
|
|
126
|
+
);
|
|
127
|
+
})}
|
|
128
|
+
</Defs>
|
|
129
|
+
{data.length === 1 ? (
|
|
130
|
+
<>
|
|
131
|
+
<Circle
|
|
132
|
+
cx={cx}
|
|
133
|
+
cy={cy}
|
|
134
|
+
r={radius}
|
|
135
|
+
fill={
|
|
136
|
+
showGradient
|
|
137
|
+
? `url(#grad${0})`
|
|
138
|
+
: data[0].color || pieColors[0 % 9]
|
|
139
|
+
}
|
|
140
|
+
onPress={() => {
|
|
141
|
+
data[0].onPress
|
|
142
|
+
? data[0].onPress()
|
|
143
|
+
: props.onPress
|
|
144
|
+
? props.onPress(data[0], 0)
|
|
145
|
+
: null;
|
|
146
|
+
}}
|
|
147
|
+
/>
|
|
148
|
+
</>
|
|
149
|
+
) : (
|
|
150
|
+
data.map((item, index) => {
|
|
151
|
+
// console.log('index', index);
|
|
152
|
+
let nextItem;
|
|
153
|
+
if (index === pData.length - 1) nextItem = pData[0];
|
|
154
|
+
else nextItem = pData[index + 1];
|
|
155
|
+
let sx =
|
|
156
|
+
cx * (1 + Math.sin(2 * pi * pData[index] + initialAngle)) +
|
|
157
|
+
(item.shiftX || 0);
|
|
158
|
+
let sy =
|
|
159
|
+
cy * (1 - Math.cos(2 * pi * pData[index] + initialAngle)) +
|
|
160
|
+
(item.shiftY || 0);
|
|
161
|
+
let ax =
|
|
162
|
+
cx * (1 + Math.sin(2 * pi * nextItem + initialAngle)) +
|
|
163
|
+
(item.shiftX || 0);
|
|
164
|
+
let ay =
|
|
165
|
+
cy * (1 - Math.cos(2 * pi * nextItem + initialAngle)) +
|
|
166
|
+
(item.shiftY || 0);
|
|
167
|
+
|
|
168
|
+
if (isBiggerPie && index) return null;
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<Path
|
|
172
|
+
key={index + 'a'}
|
|
173
|
+
d={`M ${cx + (item.shiftX || 0)} ${
|
|
174
|
+
cy + (item.shiftY || 0)
|
|
175
|
+
} L ${sx} ${sy} A ${radius} ${radius} 0 ${
|
|
176
|
+
semiCircle ? 0 : data[index].value > total / 2 ? 1 : 0
|
|
177
|
+
} 1 ${ax} ${ay} L ${cx + (item.shiftX || 0)} ${
|
|
178
|
+
cy + (item.shiftY || 0)
|
|
179
|
+
}`}
|
|
180
|
+
stroke={item.strokeColor || strokeColor}
|
|
181
|
+
strokeWidth={
|
|
182
|
+
props.focusOnPress && props.selectedIndex === index
|
|
183
|
+
? 0
|
|
184
|
+
: item.strokeWidth === 0
|
|
185
|
+
? 0
|
|
186
|
+
: item.strokeWidth || strokeWidth
|
|
187
|
+
}
|
|
188
|
+
fill={
|
|
189
|
+
props.selectedIndex === index || item.peripheral
|
|
190
|
+
? 'transparent'
|
|
191
|
+
: showGradient
|
|
192
|
+
? `url(#grad${index})`
|
|
193
|
+
: item.color || pieColors[index % 9]
|
|
194
|
+
}
|
|
195
|
+
onPress={() => {
|
|
196
|
+
if (item.onPress) {
|
|
197
|
+
item.onPress();
|
|
198
|
+
} else if (props.onPress) {
|
|
199
|
+
props.onPress(item, index);
|
|
200
|
+
}
|
|
201
|
+
if (props.focusOnPress) {
|
|
202
|
+
if (props.selectedIndex === index || props.isBiggerPie) {
|
|
203
|
+
if (toggleFocusOnPress) {
|
|
204
|
+
props.setSelectedIndex(-1);
|
|
205
|
+
}
|
|
206
|
+
} else {
|
|
207
|
+
props.setSelectedIndex(index);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}}
|
|
211
|
+
/>
|
|
212
|
+
);
|
|
213
|
+
})
|
|
214
|
+
)}
|
|
215
|
+
|
|
216
|
+
{(showText || showInnerComponent) &&
|
|
217
|
+
data.map((item, index) => {
|
|
218
|
+
const localPieInnerComponent =
|
|
219
|
+
item.pieInnerComponent ?? props.pieInnerComponent;
|
|
220
|
+
if (isBiggerPie && index) return null;
|
|
221
|
+
if (!props.data[index].value) return null;
|
|
222
|
+
let mx = cx * (1 + Math.sin(2 * pi * mData[index] + initialAngle));
|
|
223
|
+
let my = cy * (1 - Math.cos(2 * pi * mData[index] + initialAngle));
|
|
224
|
+
|
|
225
|
+
let midx = (mx + cx) / 2;
|
|
226
|
+
let midy = (my + cy) / 2;
|
|
227
|
+
|
|
228
|
+
let x = midx,
|
|
229
|
+
y = midy;
|
|
230
|
+
|
|
231
|
+
const labelPosition = item.labelPosition || labelsPosition;
|
|
232
|
+
|
|
233
|
+
if (labelPosition === 'onBorder') {
|
|
234
|
+
x = mx;
|
|
235
|
+
y = my;
|
|
236
|
+
} else if (labelPosition === 'outward') {
|
|
237
|
+
x = (midx + mx) / 2;
|
|
238
|
+
y = (midy + my) / 2;
|
|
239
|
+
} else if (labelPosition === 'inward') {
|
|
240
|
+
x = (midx + cx) / 2;
|
|
241
|
+
y = (midy + cy) / 2;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
x += item.shiftX || 0;
|
|
245
|
+
y += item.shiftY || 0;
|
|
246
|
+
|
|
247
|
+
if (data.length === 1) {
|
|
248
|
+
if (donut) {
|
|
249
|
+
y =
|
|
250
|
+
(radius -
|
|
251
|
+
innerRadius +
|
|
252
|
+
(item.textBackgroundRadius ||
|
|
253
|
+
props.textBackgroundRadius ||
|
|
254
|
+
item.textSize ||
|
|
255
|
+
textSize)) /
|
|
256
|
+
2;
|
|
257
|
+
} else {
|
|
258
|
+
y = cy;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return (
|
|
263
|
+
<React.Fragment key={index}>
|
|
264
|
+
{/* <Line x1={mx} x2={cx} y1={my} y2={cy} stroke="black" /> */}
|
|
265
|
+
{showTextBackground ? (
|
|
266
|
+
<Circle
|
|
267
|
+
cx={x + (item.shiftTextBackgroundX ?? item.shiftTextX ?? 0)}
|
|
268
|
+
cy={
|
|
269
|
+
y +
|
|
270
|
+
(item.shiftTextBackgroundY ?? item.shiftTextY ?? 0) -
|
|
271
|
+
(item.textSize || textSize) / 4
|
|
272
|
+
}
|
|
273
|
+
r={
|
|
274
|
+
item.textBackgroundRadius ||
|
|
275
|
+
props.textBackgroundRadius ||
|
|
276
|
+
item.textSize ||
|
|
277
|
+
textSize
|
|
278
|
+
}
|
|
279
|
+
fill={item.textBackgroundColor || textBackgroundColor}
|
|
280
|
+
onPress={() => {
|
|
281
|
+
item.onLabelPress
|
|
282
|
+
? item.onLabelPress()
|
|
283
|
+
: props.onLabelPress
|
|
284
|
+
? props.onLabelPress(item, index)
|
|
285
|
+
: item.onPress
|
|
286
|
+
? item.onPress()
|
|
287
|
+
: props.onPress
|
|
288
|
+
? props.onPress(item, index)
|
|
289
|
+
: null;
|
|
290
|
+
if (props.focusOnPress) {
|
|
291
|
+
if (props.selectedIndex === index) {
|
|
292
|
+
if (toggleFocusOnPress) {
|
|
293
|
+
props.setSelectedIndex(-1);
|
|
294
|
+
}
|
|
295
|
+
} else {
|
|
296
|
+
props.setSelectedIndex(index);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}}
|
|
300
|
+
/>
|
|
301
|
+
) : null}
|
|
302
|
+
<SvgText
|
|
303
|
+
fill={
|
|
304
|
+
item.textColor || textColor || pieColors[(index + 2) % 9]
|
|
305
|
+
}
|
|
306
|
+
fontSize={item.textSize || textSize}
|
|
307
|
+
fontFamily={item.font || props.font}
|
|
308
|
+
fontWeight={item.fontWeight || props.fontWeight}
|
|
309
|
+
fontStyle={item.fontStyle || props.fontStyle || 'normal'}
|
|
310
|
+
x={
|
|
311
|
+
x +
|
|
312
|
+
(item.shiftTextX || 0) -
|
|
313
|
+
(item.textSize || textSize) / 1.8
|
|
314
|
+
}
|
|
315
|
+
y={y + (item.shiftTextY || 0)}
|
|
316
|
+
onPress={() => {
|
|
317
|
+
item.onLabelPress
|
|
318
|
+
? item.onLabelPress()
|
|
319
|
+
: props.onLabelPress
|
|
320
|
+
? props.onLabelPress(item, index)
|
|
321
|
+
: item.onPress
|
|
322
|
+
? item.onPress()
|
|
323
|
+
: props.onPress
|
|
324
|
+
? props.onPress(item, index)
|
|
325
|
+
: null;
|
|
326
|
+
if (props.focusOnPress) {
|
|
327
|
+
if (props.selectedIndex === index) {
|
|
328
|
+
if (toggleFocusOnPress) {
|
|
329
|
+
props.setSelectedIndex(-1);
|
|
330
|
+
}
|
|
331
|
+
} else {
|
|
332
|
+
props.setSelectedIndex(index);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}}>
|
|
336
|
+
{item.text || (showValuesAsLabels ? item.value + '' : '')}
|
|
337
|
+
</SvgText>
|
|
338
|
+
{localPieInnerComponent ? (
|
|
339
|
+
<G x={x} y={y}>
|
|
340
|
+
{localPieInnerComponent?.(item, index) ?? null}
|
|
341
|
+
</G>
|
|
342
|
+
) : null}
|
|
343
|
+
</React.Fragment>
|
|
344
|
+
);
|
|
345
|
+
})}
|
|
346
|
+
</Svg>
|
|
347
|
+
{isThreeD && shadow && !semiCircle ? (
|
|
348
|
+
<View
|
|
349
|
+
style={{
|
|
350
|
+
width: radius * 2,
|
|
351
|
+
height: radius * 2,
|
|
352
|
+
backgroundColor: shadowColor,
|
|
353
|
+
borderRadius: radius,
|
|
354
|
+
position: 'absolute',
|
|
355
|
+
top: shadowWidth + paddingVertical / 2,
|
|
356
|
+
left: paddingHorizontal / 2,
|
|
357
|
+
zIndex: -1,
|
|
358
|
+
}}
|
|
359
|
+
/>
|
|
360
|
+
) : null}
|
|
361
|
+
</View>
|
|
362
|
+
);
|
|
363
|
+
};
|