-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
index.js
150 lines (143 loc) · 4.09 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
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
/*
* This file is part of the nivo project.
*
* Copyright 2016-present, Raphaël Benitte.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import React from 'react'
import { ResponsiveSwarmPlot, SwarmPlotDefaultProps } from '@nivo/swarmplot'
import ComponentTemplate from '../../components/components/ComponentTemplate'
import meta from '../../data/components/swarmplot/meta.yml'
import mapper from '../../data/components/swarmplot/mapper'
import { groups } from '../../data/components/swarmplot/props'
import { generateLightDataSet } from '../../data/components/swarmplot/generator'
const initialProperties = Object.freeze({
groupBy: 'group',
identity: 'id',
value: 'price',
valueFormat: '$.2f',
valueScale: {
type: 'linear',
min: 0,
max: 500,
reverse: false,
},
size: {
key: 'volume',
values: [4, 20],
sizes: [6, 20],
},
spacing: 2,
layout: SwarmPlotDefaultProps.layout,
gap: SwarmPlotDefaultProps.gap,
forceStrength: 4,
simulationIterations: 100,
colors: SwarmPlotDefaultProps.colors,
colorBy: 'group',
borderWidth: 0,
borderColor: {
from: 'color',
modifiers: [
['darker', 0.6],
['opacity', 0.5],
],
},
margin: {
top: 80,
right: 100,
bottom: 80,
left: 100,
},
enableGridX: true,
enableGridY: true,
axisTop: {
enable: true,
orient: 'top',
tickSize: 10,
tickPadding: 5,
tickRotation: 0,
legend: 'group if vertical, price if horizontal',
legendPosition: 'middle',
legendOffset: -46,
},
axisRight: {
enable: true,
orient: 'right',
tickSize: 10,
tickPadding: 5,
tickRotation: 0,
legend: 'price if vertical, group if horizontal',
legendPosition: 'middle',
legendOffset: 76,
},
axisBottom: {
enable: true,
orient: 'bottom',
tickSize: 10,
tickPadding: 5,
tickRotation: 0,
legend: 'group if vertical, price if horizontal',
legendPosition: 'middle',
legendOffset: 46,
},
axisLeft: {
enable: true,
orient: 'left',
tickSize: 10,
tickPadding: 5,
tickRotation: 0,
legend: 'price if vertical, group if horizontal',
legendPosition: 'middle',
legendOffset: -76,
},
isInteractive: true,
useMesh: false,
debugMesh: false,
animate: true,
motionStiffness: 50,
motionDamping: 10,
})
const ScatterPlot = () => {
return (
<ComponentTemplate
name="SwarmPlot"
meta={meta.SwarmPlot}
icon="swarmplot"
flavors={meta.flavors}
currentFlavor="svg"
properties={groups}
initialProperties={initialProperties}
defaultProperties={SwarmPlotDefaultProps}
propertiesMapper={mapper}
codePropertiesMapper={(properties, data) => ({
groups: data.groups,
...properties,
})}
generateData={generateLightDataSet}
getTabData={data => data.data}
getDataSize={data => data.data.length}
>
{(properties, data, theme, logAction) => {
return (
<ResponsiveSwarmPlot
data={data.data}
groups={data.groups}
{...properties}
theme={theme}
onClick={node => {
logAction({
type: 'click',
label: `[node] id: ${node.id}, group: ${node.group}, value: ${node.value}`,
color: node.color,
data: node,
})
}}
/>
)
}}
</ComponentTemplate>
)
}
export default ScatterPlot