/
index.js
94 lines (89 loc) · 2.88 KB
/
index.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import React from 'react'
import { defaultProps, ResponsiveSunburst } from '@nivo/sunburst'
import { generateLibTree } from '@nivo/generators'
import { omit } from 'lodash'
import ComponentTemplate from '../../components/components/ComponentTemplate'
import meta from '../../data/components/sunburst/meta.yml'
import mapper from '../../data/components/sunburst/mapper'
import { groups } from '../../data/components/sunburst/props'
const Tooltip = () => {
/* return custom tooltip */
}
const generateData = () => generateLibTree()
const initialProperties = {
margin: {
top: 10,
right: 10,
bottom: 10,
left: 10,
},
id: 'name',
value: 'loc',
valueFormat: { format: '', enabled: false },
cornerRadius: 2,
borderWidth: 1,
borderColor: { theme: 'background' },
colors: { scheme: 'nivo' },
childColor: {
from: 'color',
modifiers: [['brighter', 0.1]],
},
enableArcLabels: true,
arcLabel: 'formattedValue',
arcLabelsRadiusOffset: 0.5,
arcLabelsSkipAngle: 10,
arcLabelsTextColor: {
from: 'color',
modifiers: [['darker', 1.4]],
},
animate: defaultProps.animate,
motionConfig: defaultProps.motionConfig,
transitionMode: defaultProps.transitionMode,
defs: [],
fill: [],
isInteractive: true,
'custom tooltip example': false,
tooltip: null,
'showcase pattern usage': false,
}
const Sunburst = () => {
return (
<ComponentTemplate
name="Sunburst"
meta={meta.Sunburst}
icon="sunburst"
flavors={meta.flavors}
currentFlavor="svg"
properties={groups}
defaultProperties={defaultProps}
initialProperties={initialProperties}
propertiesMapper={mapper}
generateData={generateData}
>
{(properties, data, theme, logAction) => {
return (
<ResponsiveSunburst
data={data}
{...properties}
theme={theme}
onClick={node =>
logAction({
type: 'click',
label: `[sunburst] ${node.id} - ${node.value}: ${
Math.round(node.percentage * 100) / 100
}%`,
color: node.color,
// prevent cyclic dependency
data: {
...omit(node, ['parent']),
parent: omit(node.parent, ['data', 'parent', 'children']),
},
})
}
/>
)
}}
</ComponentTemplate>
)
}
export default Sunburst