forked from plouc/nivo
/
props.ts
451 lines (447 loc) · 12.8 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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
import { closedCurvePropKeys } from '@nivo/core'
import { svgDefaultProps } from '@nivo/radar'
import {
themeProperty,
motionProperties,
groupProperties,
defsProperties,
} from '../../../lib/componentProperties'
import { ChartProperty } from '../../../types'
const props: ChartProperty[] = [
{
key: 'data',
group: 'Base',
type: 'Datum[]',
required: true,
help: 'Chart data.',
description: `
For example, given this config:
\`\`\`
[
{ language: 'javascript', john: 12, sarah: 32, bob: 27 },
{ language: 'golang', john: 25, sarah: 15, bob: 3 },
{ language: 'python', john: 5, sarah: 22, bob: 31 },
{ language: 'java', john: 19, sarah: 17, bob: 9 }
]
keys: ['john', 'sarah', 'bob']
indexBy: 'language'
\`\`\`
We'll have a radar chart representing programing
skills for each user by language
(3 layers and 4 dimensions).
`,
flavors: ['svg', 'api'],
},
{
key: 'indexBy',
group: 'Base',
type: 'string',
required: true,
help: 'Key to use to index the data.',
description: `
Key to use to index the data, this key
must exist in each data item.
`,
flavors: ['svg', 'api'],
},
{
key: 'keys',
group: 'Base',
type: 'string[]',
required: true,
help: 'Keys to use to determine each serie.',
description: `
Keys to use to determine each serie.
Those keys should exist in each data item.
`,
flavors: ['svg', 'api'],
},
{
key: 'maxValue',
group: 'Base',
type: `number | 'auto'`,
required: false,
help: 'Maximum value.',
description: `
Maximum value, if 'auto',
will use max value from
the provided data.
`,
flavors: ['svg', 'api'],
defaultValue: svgDefaultProps.maxValue,
controlType: 'switchableRange',
controlOptions: {
disabledValue: 'auto',
defaultValue: 200,
min: 0,
max: 1000,
},
},
{
key: 'valueFormat',
group: 'Base',
type: 'string | (value: number) => string',
required: false,
help: 'Optional formatter for values.',
description: `
The formatted value can then be used for labels & tooltips.
Under the hood, nivo uses [d3-format](https://github.com/d3/d3-format),
please have a look at it for available formats, you can also pass a function
which will receive the raw value and should return the formatted one.
`,
flavors: ['svg', 'api'],
controlType: 'valueFormat',
},
{
key: 'curve',
group: 'Base',
type: 'string',
required: false,
help: 'Curve interpolation.',
description: `
Defines the curve factory to use
for the line generator.
`,
defaultValue: svgDefaultProps.curve,
flavors: ['svg', 'api'],
controlType: 'choices',
controlOptions: {
choices: closedCurvePropKeys.map((key: string) => ({
label: key,
value: key,
})),
},
},
{
key: 'width',
group: 'Base',
type: 'number',
required: true,
help: 'Chart width.',
description: `
not required if using
\`<ResponsiveRadar/>\`.
`,
flavors: ['svg', 'api'],
enableControlForFlavors: ['api'],
controlType: 'range',
controlOptions: {
unit: 'px',
min: 100,
max: 1000,
step: 5,
},
},
{
key: 'height',
group: 'Base',
type: 'number',
required: true,
help: 'Chart height.',
description: `
not required if using
\`<ResponsiveRadar/>\`.
`,
flavors: ['svg', 'api'],
enableControlForFlavors: ['api'],
controlType: 'range',
controlOptions: {
unit: 'px',
min: 100,
max: 1000,
step: 5,
},
},
{
key: 'margin',
group: 'Base',
help: 'Chart margin.',
type: 'object',
required: false,
flavors: ['svg', 'api'],
controlType: 'margin',
},
themeProperty(['svg', 'api']),
{
key: 'colors',
group: 'Style',
type: 'string | Function | string[]',
required: false,
help: 'Defines how to compute colors.',
defaultValue: svgDefaultProps.colors,
flavors: ['svg', 'api'],
controlType: 'ordinalColors',
},
{
key: 'fillOpacity',
group: 'Style',
type: 'number',
required: false,
help: 'Shape fill opacity.',
flavors: ['svg', 'api'],
defaultValue: svgDefaultProps.fillOpacity,
controlType: 'opacity',
},
{
key: 'blendMode',
group: 'Style',
type: 'string',
required: false,
help:
'Defines CSS [mix-blend-mode](https://developer.mozilla.org/fr/docs/Web/CSS/mix-blend-mode) for shapes.',
flavors: ['svg'],
defaultValue: svgDefaultProps.blendMode,
controlType: 'blendMode',
},
{
key: 'borderWidth',
group: 'Style',
type: 'number',
required: false,
help: 'Shape border width.',
flavors: ['svg', 'api'],
defaultValue: svgDefaultProps.borderWidth,
controlType: 'lineWidth',
},
{
key: 'borderColor',
group: 'Style',
type: 'string | object | Function',
required: false,
help: 'Method to compute border color.',
flavors: ['svg', 'api'],
defaultValue: svgDefaultProps.borderColor,
controlType: 'inheritedColor',
},
...defsProperties('Style', ['svg']),
{
key: 'gridLevels',
group: 'Grid',
type: 'number',
required: false,
help: 'Number of levels to display for grid',
flavors: ['svg', 'api'],
defaultValue: svgDefaultProps.gridLevels,
controlType: 'range',
controlOptions: {
min: 1,
max: 12,
},
},
{
key: 'gridShape',
group: 'Grid',
type: 'string',
required: false,
help: 'Determine shape of the grid.',
flavors: ['svg', 'api'],
defaultValue: svgDefaultProps.gridShape,
controlType: 'choices',
controlOptions: {
choices: [
{ label: 'circular', value: 'circular' },
{ label: 'linear', value: 'linear' },
],
},
},
{
key: 'gridLabel',
group: 'Grid',
type: 'Function',
required: false,
help: 'Grid label.',
description: `
An optional function to override label rendering.
It must return a **valid SVG element** and will
receive the following props:
\`\`\`
{
id: string
# this can be used to determine the label layout,
# if the element should be centered, left/right aligned
anchor: 'start' | 'middle' | 'end'
# angle in degrees
angle: number
}
\`\`\`
The component will be wrapped inside
a \`g\` element **already positioned**
where the default label would have been placed.
`,
flavors: ['svg'],
},
{
key: 'gridLabelOffset',
group: 'Grid',
type: 'number',
required: false,
help: 'Label offset from outer radius.',
flavors: ['svg', 'api'],
defaultValue: svgDefaultProps.gridLabelOffset,
controlType: 'range',
controlOptions: {
unit: 'px',
min: 0,
max: 60,
},
},
{
key: 'enableDots',
group: 'Dots',
type: 'boolean',
required: false,
help: 'Enable/disable dots.',
flavors: ['svg', 'api'],
defaultValue: svgDefaultProps.enableDots,
controlType: 'switch',
},
{
key: 'dotSymbol',
group: 'Dots',
type: 'Function',
required: false,
help: 'Overrides default dot circle.',
description: `
Overrides default dot circle.
The function will receive \`size\`,
\`color\`, \`borderWidth\` and \`borderColor\`
props and must return a valid SVG element.
`,
flavors: ['svg'],
},
{
key: 'dotSize',
group: 'Dots',
type: 'number',
required: false,
help: 'Size of the dots.',
flavors: ['svg', 'api'],
defaultValue: svgDefaultProps.dotSize,
controlType: 'range',
controlOptions: {
unit: 'px',
min: 2,
max: 64,
},
},
{
key: 'dotColor',
type: 'string | object | Function',
required: false,
help: 'Method to compute dots color.',
flavors: ['svg', 'api'],
defaultValue: svgDefaultProps.dotColor,
controlType: 'inheritedColor',
group: 'Dots',
},
{
key: 'dotBorderWidth',
group: 'Dots',
type: 'number',
required: false,
help: 'Width of the dots border.',
flavors: ['svg', 'api'],
defaultValue: svgDefaultProps.dotBorderWidth,
controlType: 'range',
controlOptions: {
unit: 'px',
min: 0,
max: 10,
},
},
{
key: 'dotBorderColor',
group: 'Dots',
type: 'string | object | Function',
required: false,
help: 'Method to compute dots border color.',
flavors: ['svg', 'api'],
defaultValue: svgDefaultProps.dotBorderColor,
controlType: 'inheritedColor',
},
{
key: 'enableDotLabel',
group: 'Dots',
help: 'Enable/disable dots label.',
type: 'boolean',
required: false,
flavors: ['svg', 'api'],
defaultValue: svgDefaultProps.enableDotLabel,
controlType: 'switch',
},
{
key: 'dotLabel',
group: 'Dots',
type: 'string | ((point: PointData) => string | number)',
required: false,
help: 'Dot label.',
description:
'Property to use to determine dot label. If a function is provided, it will receive current value and serie and must return a label.',
flavors: ['svg'],
defaultValue: svgDefaultProps.dotLabel,
controlType: 'choices',
controlOptions: {
choices: [
'value',
'formattedValue',
'index',
'key',
`p => \`\${p.key}: \${p.value}\``,
`p => \`\${p.index}: \${p.value}\``,
].map(choice => ({
label: choice,
value: choice,
})),
},
},
{
key: 'dotLabelYOffset',
group: 'Dots',
type: 'number',
required: false,
help: 'Label Y offset from dot shape.',
flavors: ['svg', 'api'],
defaultValue: svgDefaultProps.dotLabelYOffset,
controlType: 'range',
controlOptions: {
unit: 'px',
min: -24,
max: 24,
},
},
{
key: 'layers',
group: 'Customization',
help: 'Defines the order of layers and add custom layers.',
description: `
You can also use this to insert extra layers
to the chart, the extra layer should be a component.
The layer function which will receive the chart's
context & computed data and must return a valid SVG element.
`,
required: false,
type: '(RadarLayerId | FunctionComponent<RadarCustomLayerProps>)[]',
flavors: ['svg'],
defaultValue: svgDefaultProps.layers,
},
{
key: 'isInteractive',
group: 'Interactivity',
type: 'boolean',
required: false,
help: 'Enable/disable interactivity.',
flavors: ['svg'],
defaultValue: svgDefaultProps.isInteractive,
controlType: 'switch',
},
{
key: 'sliceTooltip',
group: 'Interactivity',
type: 'FunctionComponent<RadarSliceTooltipProps>',
required: false,
help: 'Override default slice tooltip.',
flavors: ['svg'],
},
...motionProperties(['svg'], svgDefaultProps, 'react-spring'),
]
export const groups = groupProperties(props)