/
props.ts
347 lines (344 loc) · 9.73 KB
/
props.ts
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
import { commonDefaultProps as defaults } from '@nivo/treemap'
import {
motionProperties,
defsProperties,
groupProperties,
themeProperty,
} from '../../../lib/componentProperties'
import {
chartDimensions,
ordinalColors,
isInteractive,
commonAccessibilityProps,
} from '../../../lib/chart-properties'
import { ChartProperty, Flavor } from '../../../types'
const allFlavors: Flavor[] = ['svg', 'html', 'canvas', 'api']
const props: ChartProperty[] = [
{
key: 'data',
group: 'Base',
flavors: allFlavors,
help: 'The hierarchical data object.',
type: 'object',
required: true,
},
{
key: 'identity',
group: 'Base',
flavors: allFlavors,
help: 'The key or function to use to retrieve nodes identity.',
type: 'string | Function',
required: false,
defaultValue: defaults.identity,
},
{
key: 'value',
group: 'Base',
flavors: allFlavors,
help: 'The key or function to use to retrieve nodes value.',
type: 'string | Function',
required: false,
defaultValue: 'value',
},
{
key: 'valueFormat',
help: `
Value format supporting d3-format notation, this formatted value
will then be used for labels and tooltips.
`,
flavors: allFlavors,
type: 'string | Function',
required: false,
control: { type: 'valueFormat' },
group: 'Base',
},
{
key: 'tile',
group: 'Base',
flavors: allFlavors,
help: 'Strategy used to compute nodes.',
description: `
Strategy used to compute nodes, see
[official d3 documentation](https://github.com/mbostock/d3/wiki/Treemap-Layout#mode).
`,
type: 'string',
required: false,
defaultValue: 'squarify',
control: {
type: 'choices',
choices: [
{ label: 'binary', value: 'binary' },
{ label: 'squarify', value: 'squarify' },
{ label: 'slice', value: 'slice' },
{ label: 'dice', value: 'dice' },
{ label: 'sliceDice', value: 'sliceDice' },
{
label: 'resquarify',
value: 'resquarify',
},
],
},
},
{
key: 'leavesOnly',
help: 'Only render leaf nodes (no parent).',
flavors: allFlavors,
type: 'boolean',
required: false,
defaultValue: defaults.leavesOnly,
control: { type: 'switch' },
group: 'Base',
},
{
key: 'innerPadding',
help: 'Padding between parent and child node.',
flavors: allFlavors,
type: 'number',
required: false,
defaultValue: defaults.innerPadding,
group: 'Base',
control: {
type: 'range',
unit: 'px',
min: 0,
max: 32,
},
},
{
key: 'outerPadding',
help: 'Padding between parent and child node.',
flavors: allFlavors,
type: 'number',
required: false,
defaultValue: defaults.outerPadding,
group: 'Base',
control: {
type: 'range',
unit: 'px',
min: 0,
max: 32,
},
},
...chartDimensions(allFlavors),
themeProperty(allFlavors),
ordinalColors({
flavors: allFlavors,
defaultValue: defaults.colors,
}),
{
key: 'nodeOpacity',
help: 'Node opacity (0~1).',
flavors: allFlavors,
required: false,
defaultValue: defaults.nodeOpacity,
type: 'number',
control: { type: 'opacity' },
group: 'Style',
},
{
key: 'borderWidth',
help: 'Control node border width.',
flavors: allFlavors,
type: 'number',
required: false,
defaultValue: defaults.borderWidth,
control: { type: 'lineWidth' },
group: 'Style',
},
{
key: 'borderColor',
help: 'Method to compute border color.',
flavors: allFlavors,
type: 'string | object | Function',
required: false,
defaultValue: defaults.borderColor,
control: { type: 'inheritedColor' },
group: 'Style',
},
...defsProperties('Style', ['svg']),
{
key: 'enableLabel',
help: 'Enable/disable labels.',
flavors: allFlavors,
type: 'boolean',
required: false,
defaultValue: defaults.enableLabel,
control: { type: 'switch' },
group: 'Labels',
},
{
key: 'label',
help: 'Label accessor.',
flavors: allFlavors,
description:
'Defines how to get label text, can be a string (used to access current node property) or a function which will receive the actual node and must return the desired label.',
type: 'string | Function',
required: false,
group: 'Labels',
control: {
type: 'choices',
choices: [
'formattedValue',
'id',
`node => \`\${node.id} (\${node.formattedValue})\``,
].map(prop => ({
label: prop,
value: prop,
})),
},
},
{
key: 'labelSkipSize',
help: 'Skip label rendering if node minimal side length is lower than given value, 0 to disable.',
flavors: allFlavors,
type: 'number',
required: false,
group: 'Labels',
control: {
type: 'range',
unit: 'px',
min: 0,
max: 100,
},
},
{
key: 'orientLabel',
help: 'Orient labels according to max node width/height.',
flavors: allFlavors,
type: 'boolean',
required: false,
defaultValue: defaults.orientLabel,
control: { type: 'switch' },
group: 'Labels',
},
{
key: 'labelTextColor',
help: 'Method to compute label text color.',
flavors: allFlavors,
type: 'string | object | Function',
required: false,
control: { type: 'inheritedColor' },
group: 'Labels',
},
{
key: 'enableParentLabel',
flavors: ['svg', 'html', 'api'],
help: 'Enable/disable labels.',
type: 'boolean',
required: false,
defaultValue: defaults.enableParentLabel,
control: { type: 'switch' },
group: 'Labels',
},
{
key: 'parentLabel',
flavors: ['svg', 'html', 'api'],
help: 'Parent label accessor.',
description:
'Defines how to get parent label text, can be a string (used to access current node property) or a function which will receive the actual node and must return the desired label.',
type: 'string | Function',
required: false,
group: 'Labels',
control: {
type: 'choices',
choices: ['id', 'formattedValue', `node => node.pathComponents.join(' / ')`].map(
prop => ({
label: prop,
value: prop,
})
),
},
},
{
key: 'parentLabelSize',
flavors: ['svg', 'html', 'api'],
help: `Parent label size.`,
required: false,
defaultValue: defaults.parentLabelSize,
type: `number`,
group: 'Labels',
control: {
type: 'range',
min: 10,
max: 40,
},
},
{
key: 'parentLabelPosition',
flavors: ['svg', 'html', 'api'],
help: 'Parent label position.',
type: `'top' | 'right' | 'bottom' | 'left'`,
required: false,
group: 'Labels',
defaultValue: defaults.parentLabelPosition,
control: {
type: 'choices',
choices: ['top', 'right', 'bottom', 'left'].map(prop => ({
label: prop,
value: prop,
})),
},
},
{
key: 'parentLabelPadding',
flavors: ['svg', 'html', 'api'],
help: `Parent label padding.`,
required: false,
defaultValue: defaults.parentLabelPadding,
type: `number`,
group: 'Labels',
control: {
type: 'range',
min: 0,
max: 20,
},
},
{
key: 'parentLabelTextColor',
flavors: ['svg', 'html', 'api'],
help: 'Method to compute parent label text color.',
type: 'string | object | Function',
required: false,
control: { type: 'inheritedColor' },
group: 'Labels',
},
isInteractive({
flavors: ['svg', 'html', 'canvas'],
defaultValue: defaults.isInteractive,
}),
{
key: 'onMouseEnter',
flavors: ['svg', 'html'],
group: 'Interactivity',
type: '(node, event) => void',
help: 'onMouseEnter handler.',
required: false,
},
{
key: 'onMouseMove',
flavors: ['svg', 'html', 'canvas'],
group: 'Interactivity',
type: '(node, event) => void',
help: 'onMouseMove handler.',
required: false,
},
{
key: 'onMouseLeave',
flavors: ['svg', 'html'],
group: 'Interactivity',
type: '(node, event) => void',
help: 'onMouseLeave handler.',
required: false,
},
{
key: 'onClick',
flavors: ['svg', 'html', 'canvas'],
group: 'Interactivity',
type: '(node, event) => void',
help: 'onClick handler.',
required: false,
},
...commonAccessibilityProps(allFlavors),
...motionProperties(['svg', 'html', 'canvas'], defaults, 'react-spring'),
]
export const groups = groupProperties(props)