/
props.js
584 lines (571 loc) · 16.7 KB
/
props.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
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
/*
* 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 { PieDefaultProps as defaults } from '@nivo/pie'
import { themeProperty, defsProperties, groupProperties } from '../../../lib/componentProperties'
const props = [
{
key: 'data',
group: 'Base',
help: 'Chart data, which should be immutable.',
description: `
Chart data, which must conform to this structure
if using the default \`id\` and \`value\` accessors:
\`\`\`
Array<{
id: string | number,
value: number
}>
\`\`\`
If using a different data structure, you must make sure
to adjust both \`id\` and \`value\`. Meaning you can provide
a completely different data structure as long as \`id\` and \`value\`
return the appropriate values.
Immutability of the data is important as re-computations
depends on it.
`,
type: 'object[]',
required: true,
},
{
key: 'id',
group: 'Base',
help: 'ID accessor.',
description: `
Define how to access the ID of each datum,
by default, nivo will look for the \`id\` property.
`,
type: 'string | (datum: any): string | number',
required: false,
defaultValue: defaults.id,
},
{
key: 'value',
group: 'Base',
help: 'Value accessor.',
description: `
Define how to access the value of each datum,
by default, nivo will look for the \`value\` property.
`,
type: 'string | (datum: any): number',
required: false,
defaultValue: defaults.id,
},
{
key: 'valueFormat',
group: 'Base',
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.
`,
required: false,
type: 'Function | string',
controlType: 'valueFormat',
},
{
key: 'width',
enableControlForFlavors: ['api'],
help: 'Chart width.',
description: `
not required if using
\`<ResponsivePie/>\`.
`,
type: 'number',
required: true,
controlType: 'range',
group: 'Base',
controlOptions: {
unit: 'px',
min: 100,
max: 1000,
step: 5,
},
},
{
key: 'height',
enableControlForFlavors: ['api'],
help: 'Chart height.',
description: `
not required if using
\`<ResponsivePie/>\`.
`,
type: 'number',
required: true,
controlType: 'range',
group: 'Base',
controlOptions: {
unit: 'px',
min: 100,
max: 1000,
step: 5,
},
},
{
key: 'pixelRatio',
flavors: ['canvas'],
help: `Adjust pixel ratio, useful for HiDPI screens.`,
required: false,
defaultValue: 'Depends on device',
type: `number`,
controlType: 'range',
group: 'Base',
controlOptions: {
min: 1,
max: 2,
},
},
{
key: 'startAngle',
help: 'Start angle (in degrees), useful to make gauges for example.',
type: 'number',
required: false,
defaultValue: defaults.startAngle,
controlType: 'angle',
group: 'Base',
controlOptions: {
unit: '°',
min: -180,
max: 360,
step: 5,
},
},
{
key: 'endAngle',
help: 'End angle (in degrees), useful to make gauges for example.',
type: 'number',
required: false,
defaultValue: defaults.endAngle,
controlType: 'angle',
group: 'Base',
controlOptions: {
unit: '°',
min: -360,
max: 360,
step: 5,
},
},
{
key: 'fit',
help: `If 'true', pie will be omptimized to occupy more space when using partial pie.`,
type: 'boolean',
required: false,
defaultValue: defaults.fit,
controlType: 'switch',
group: 'Base',
},
{
key: 'innerRadius',
help: `Donut chart if greater than 0. Value should be between 0~1 as it's a ratio from original radius.`,
type: 'number',
required: false,
defaultValue: defaults.innerRadius,
controlType: 'range',
group: 'Base',
controlOptions: {
min: 0,
max: 0.95,
step: 0.05,
},
},
{
key: 'padAngle',
help: 'Padding between each pie slice.',
type: 'number',
required: false,
defaultValue: defaults.padAngle,
controlType: 'range',
group: 'Base',
controlOptions: {
unit: '°',
min: 0,
max: 45,
step: 1,
},
},
{
key: 'cornerRadius',
help: 'Rounded slices.',
type: 'number',
required: false,
defaultValue: defaults.cornerRadius,
controlType: 'range',
group: 'Base',
controlOptions: {
unit: 'px',
min: 0,
max: 45,
step: 1,
},
},
{
key: 'sortByValue',
help: `If 'true', arcs will be ordered according to their associated value.`,
type: 'boolean',
required: false,
defaultValue: defaults.sortByValue,
controlType: 'switch',
group: 'Base',
},
{
key: 'margin',
help: 'Chart margin.',
type: 'object',
required: false,
controlType: 'margin',
group: 'Base',
},
themeProperty,
{
key: 'colors',
help: 'Defines color range.',
type: 'string | Function | string[]',
required: false,
defaultValue: defaults.colors,
controlType: 'ordinalColors',
group: 'Style',
},
...defsProperties('Style', ['svg', 'api']),
{
key: 'showcase pattern usage',
flavors: ['svg'],
help: 'Patterns.',
description: `
You can use \`defs\` and \`fill\` properties
to use patterns, see
[dedicated guide](self:/guides/patterns)
for further information.
`,
type: 'boolean',
controlType: 'switch',
group: 'Style',
},
{
key: 'borderWidth',
help: 'Slices border width.',
type: 'number',
required: false,
defaultValue: defaults.borderWidth,
controlType: 'lineWidth',
group: 'Style',
},
{
key: 'borderColor',
help: 'Method to compute border color.',
type: 'string | object | Function',
required: false,
defaultValue: defaults.borderColor,
controlType: 'inheritedColor',
group: 'Style',
},
{
key: 'enableRadialLabels',
help: 'Enable/disable radial labels.',
type: 'boolean',
required: false,
defaultValue: defaults.enableRadialLabels,
controlType: 'switch',
group: 'Radial labels',
},
{
key: 'radialLabel',
help: 'Radial label',
description: `
Defines how to get label text,
can be a string (used to access current node data property)
or a function which will receive the actual node data.
`,
type: 'string | Function',
required: false,
defaultValue: defaults.radialLabel,
controlType: 'choices',
group: 'Radial labels',
controlOptions: {
choices: ['id', 'value', `d => \`\${d.id} (\${d.value})\``].map(choice => ({
label: choice,
value: choice,
})),
},
},
{
key: 'radialLabelsSkipAngle',
help: `Skip label if corresponding slice's angle is lower than provided value.`,
type: 'number',
required: false,
defaultValue: defaults.radialLabelsSkipAngle,
controlType: 'range',
group: 'Radial labels',
controlOptions: {
unit: '°',
min: 0,
max: 45,
step: 1,
},
},
{
key: 'radialLabelsLinkOffset',
help: `Link offset from pie outer radius, useful to have links overlapping pie slices.`,
type: 'number',
required: false,
defaultValue: defaults.radialLabelsLinkOffset,
controlType: 'range',
group: 'Radial labels',
controlOptions: {
unit: 'px',
min: -24,
max: 24,
step: 1,
},
},
{
key: 'radialLabelsLinkDiagonalLength',
help: `Link diagonal length.`,
type: 'number',
required: false,
defaultValue: defaults.radialLabelsLinkDiagonalLength,
controlType: 'range',
group: 'Radial labels',
controlOptions: {
unit: 'px',
min: 0,
max: 36,
step: 1,
},
},
{
key: 'radialLabelsLinkHorizontalLength',
help: `Links horizontal length.`,
type: 'number',
required: false,
defaultValue: defaults.radialLabelsLinkHorizontalLength,
controlType: 'range',
group: 'Radial labels',
controlOptions: {
unit: 'px',
min: 0,
max: 36,
step: 1,
},
},
{
key: 'radialLabelsTextXOffset',
help: `X offset from links' end.`,
type: 'number',
required: false,
defaultValue: defaults.radialLabelsTextXOffset,
controlType: 'range',
group: 'Radial labels',
controlOptions: {
unit: 'px',
min: 0,
max: 36,
step: 1,
},
},
{
key: 'radialLabelsLinkStrokeWidth',
help: 'Links stroke width.',
type: 'number',
required: false,
defaultValue: defaults.radialLabelsLinkStrokeWidth,
controlType: 'lineWidth',
group: 'Radial labels',
},
{
key: 'radialLabelsTextColor',
help: 'Defines how to compute radial label text color.',
type: 'string | object | Function',
required: false,
defaultValue: defaults.radialLabelsTextColor,
controlType: 'inheritedColor',
group: 'Radial labels',
},
{
key: 'radialLabelsLinkColor',
help: 'Defines how to compute radial label link color.',
type: 'string | object | Function',
required: false,
defaultValue: defaults.radialLabelsLinkColor,
controlType: 'inheritedColor',
group: 'Radial labels',
},
{
key: 'enableSliceLabels',
help: 'Enable/disable slices labels.',
type: 'boolean',
required: false,
defaultValue: defaults.enableSliceLabels,
controlType: 'switch',
group: 'Slice labels',
},
{
key: 'sliceLabel',
help:
'Defines how to get label text, can be a string (used to access current node data property) or a function which will receive the actual node data.',
type: 'string | Function',
required: false,
defaultValue: defaults.sliceLabel,
controlType: 'choices',
group: 'Slice labels',
controlOptions: {
choices: ['id', 'value', 'formattedValue', `d => \`\${d.id} (\${d.value})\``].map(
choice => ({
label: choice,
value: choice,
})
),
},
},
{
key: 'sliceLabelsRadiusOffset',
help: `
Define the radius to use to determine the label position, starting from inner radius,
this is expressed as a ratio.
`,
type: 'number',
required: false,
defaultValue: defaults.sliceLabelsRadiusOffset,
controlType: 'range',
group: 'Slice labels',
controlOptions: {
min: 0,
max: 2,
step: 0.05,
},
},
{
key: 'sliceLabelsSkipAngle',
help: `Skip label if corresponding slice's angle is lower than provided value.`,
type: 'number',
required: false,
defaultValue: defaults.sliceLabelsSkipAngle,
controlType: 'range',
group: 'Slice labels',
controlOptions: {
unit: '°',
min: 0,
max: 45,
step: 1,
},
},
{
key: 'sliceLabelsTextColor',
help: 'Defines how to compute slice label text color.',
type: 'string | object | Function',
required: false,
defaultValue: defaults.sliceLabelsTextColor,
controlType: 'inheritedColor',
group: 'Slice labels',
},
{
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 must be a function.
The layer component which will receive the chart's
context & computed data and must return a valid SVG element
for the \`Pie\` component.
When using the canvas implementation, the function
will receive the canvas 2d context as first argument
and the chart's context and computed data as second.
Please make sure to use \`context.save()\` and
\`context.restore()\` if you make some global
modifications to the 2d context inside this function
to avoid side effects.
The context passed to layers has the following structure:
\`\`\`
{
dataWithArc: DatumWithArc[],
arcGenerator: Function
centerX: number
centerY: number
radius: number
innerRadius: number
}
\`\`\`
`,
required: false,
type: 'Array<string | Function>',
defaultValue: defaults.layers,
},
{
key: 'isInteractive',
flavors: ['svg', 'canvas'],
group: 'Interactivity',
help: 'Enable/disable interactivity.',
type: 'boolean',
required: false,
defaultValue: defaults.isInteractive,
controlType: 'switch',
},
{
key: 'onMouseEnter',
flavors: ['svg'],
group: 'Interactivity',
help: 'onMouseEnter handler, it receives target node data and mouse event.',
type: '(node, event) => void',
required: false,
},
{
key: 'onMouseMove',
flavors: ['svg', 'canvas'],
group: 'Interactivity',
help: 'onMouseMove handler, it receives target node data and mouse event.',
type: '(node, event) => void',
required: false,
},
{
key: 'onMouseLeave',
flavors: ['svg'],
group: 'Interactivity',
help: 'onMouseLeave handler, it receives target node data and mouse event.',
type: '(node, event) => void',
required: false,
},
{
key: 'onClick',
flavors: ['svg', 'canvas'],
group: 'Interactivity',
help: 'onClick handler, it receives target node data and mouse event.',
type: '(node, event) => void',
required: false,
},
{
key: 'tooltip',
flavors: ['svg', 'canvas'],
group: 'Interactivity',
type: 'Function',
required: false,
help: 'Custom tooltip component',
description: `
A function allowing complete tooltip customisation,
it must return a valid HTML element and will receive
the following props:
\`\`\`
{
datum: PieComputedDatum
}
\`\`\`
You can also customize the style of the tooltip using
the \`theme.tooltip\` object.
`,
},
{
key: 'custom tooltip example',
flavors: ['svg', 'canvas'],
help: 'Showcase custom tooltip.',
type: 'boolean',
controlType: 'switch',
group: 'Interactivity',
},
]
export const groups = groupProperties(props)