/
index.tsx
156 lines (141 loc) · 4.26 KB
/
index.tsx
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import React from 'react'
import { generateChordData } from '@nivo/generators'
import { ResponsiveChord, svgDefaultProps } from '@nivo/chord'
import { ComponentTemplate } from '../../components/components/ComponentTemplate'
import meta from '../../data/components/chord/meta.yml'
import mapper from '../../data/components/chord/mapper'
import { groups } from '../../data/components/chord/props'
import { graphql, useStaticQuery } from 'gatsby'
const MATRIX_SIZE = 5
const initialProperties = {
margin: {
top: 60,
right: 60,
bottom: 90,
left: 60,
},
valueFormat: '.2f',
padAngle: 0.02,
innerRadiusRatio: 0.96,
innerRadiusOffset: 0.02,
arcOpacity: 1,
activeArcOpacity: 1,
inactiveArcOpacity: 0.25,
arcBorderWidth: 1,
arcBorderColor: {
from: 'color',
modifiers: [['darker', 0.6]],
},
ribbonBlendMode: 'normal',
ribbonOpacity: 0.5,
activeRibbonOpacity: 0.75,
inactiveRibbonOpacity: 0.25,
ribbonBorderWidth: 1,
ribbonBorderColor: {
from: 'color',
modifiers: [['darker', 0.6]],
},
enableLabel: true,
label: 'id',
labelOffset: 12,
labelRotation: -90,
labelTextColor: {
from: 'color',
modifiers: [['darker', 1]],
},
colors: { scheme: 'nivo' },
isInteractive: true,
animate: true,
motionConfig: 'stiff',
legends: [
{
anchor: 'bottom',
direction: 'row',
justify: false,
translateX: 0,
translateY: 70,
itemWidth: 80,
itemHeight: 14,
itemsSpacing: 0,
itemTextColor: '#999',
itemDirection: 'left-to-right',
symbolSize: 12,
symbolShape: 'circle',
onClick: d => {
alert(JSON.stringify(d, null, ' '))
},
effects: [
{
on: 'hover',
style: {
itemTextColor: '#000',
},
},
],
},
],
}
const generateData = () => generateChordData({ size: MATRIX_SIZE })
const Chord = () => {
const {
image: {
childImageSharp: { gatsbyImageData: image },
},
} = useStaticQuery(graphql`
query {
image: file(absolutePath: { glob: "**/src/assets/captures/chord.png" }) {
childImageSharp {
gatsbyImageData(layout: FIXED, width: 700, quality: 100)
}
}
}
`)
return (
<ComponentTemplate
name="Chord"
meta={meta.Chord}
icon="chord"
flavors={meta.flavors}
currentFlavor="svg"
properties={groups}
initialProperties={initialProperties}
defaultProperties={svgDefaultProps}
propertiesMapper={mapper}
codePropertiesMapper={(properties, data) => ({
keys: data.keys,
...properties,
})}
generateData={generateData}
getTabData={data => data.matrix}
image={image}
>
{(properties, data, theme, logAction) => {
return (
<ResponsiveChord
data={data.matrix}
keys={data.keys}
{...properties}
theme={theme}
onArcClick={arc => {
logAction({
type: 'click',
label: `[arc] ${arc.label}`,
color: arc.color,
data: arc,
})
}}
onRibbonClick={ribbon => {
logAction({
type: 'click',
label: `[ribbon] ${ribbon.source.label} —> ${ribbon.target.label}`,
color: ribbon.source.color,
data: ribbon,
})
}}
/>
)
}}
</ComponentTemplate>
)
}
export default Chord