forked from JesperLekland/react-native-svg-charts-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwith-image-labels.js
80 lines (73 loc) · 2.16 KB
/
with-image-labels.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React from 'react'
import { PieChart } from 'react-native-svg-charts'
import { Circle, G, Image } from 'react-native-svg'
import Images from '../../../assets/images'
class PieChartWithCenteredLabels extends React.PureComponent {
render() {
const data = [
{
key: 1,
amount: 50,
svg: { fill: '#600080' },
},
{
key: 2,
amount: 50,
svg: { fill: '#9900cc' }
},
{
key: 3,
amount: 40,
svg: { fill: '#c61aff' }
},
{
key: 4,
amount: 95,
svg: { fill: '#d966ff' }
},
{
key: 5,
amount: 35,
svg: { fill: '#ecb3ff' }
}
]
const Labels = ({ slices, height, width }) => {
return slices.map((slice, index) => {
const { labelCentroid, pieCentroid, data } = slice;
return (
<G
key={index}
x={labelCentroid[ 0 ]}
y={labelCentroid[ 1 ]}
>
<Circle
r={18}
fill={'white'}
/>
<Image
x={-10}
y={10}
width={20}
height={20}
preserveAspectRatio="xMidYMid slice"
opacity="1"
href={Images.memes[ index + 1 ]}
/>
</G>
)
})
}
return (
<PieChart
style={{ height: 200 }}
valueAccessor={({ item }) => item.amount}
data={data}
spacing={0}
outerRadius={'95%'}
>
<Labels/>
</PieChart>
)
}
}
export default PieChartWithCenteredLabels