1
- // @ts -ignore
2
- import { HeatMapDefaultProps as defaults } from '@nivo/heatmap'
1
+ import { commonDefaultProps as defaults , svgDefaultProps as svgDefaults } from '@nivo/heatmap'
3
2
import { themeProperty , motionProperties , groupProperties } from '../../../lib/componentProperties'
4
- import { chartDimensions , chartGrid , axes , isInteractive } from '../../../lib/chart-properties'
3
+ import {
4
+ chartDimensions ,
5
+ chartGrid ,
6
+ axes ,
7
+ isInteractive ,
8
+ commonAccessibilityProps ,
9
+ } from '../../../lib/chart-properties'
5
10
import { ChartProperty , Flavor } from '../../../types'
6
11
7
12
const allFlavors : Flavor [ ] = [ 'svg' , 'canvas' , 'api' ]
@@ -10,48 +15,18 @@ const props: ChartProperty[] = [
10
15
{
11
16
key : 'data' ,
12
17
group : 'Base' ,
13
- flavors : allFlavors ,
14
18
help : 'Chart data.' ,
15
- type : 'object []' ,
19
+ type : 'HeatMapSerie<Datum, ExtraProps> []' ,
16
20
required : true ,
17
21
} ,
18
- {
19
- key : 'indexBy' ,
20
- group : 'Base' ,
21
- flavors : allFlavors ,
22
- help : 'Key to use to index the data.' ,
23
- description : `
24
- Key to use to index the data,
25
- this key must exist in each data item.
26
- You can also provide a function which will
27
- receive the data item and must return
28
- the desired index
29
- ` ,
30
- type : 'string | Function' ,
31
- required : false ,
32
- defaultValue : defaults . indexBy ,
33
- } ,
34
- {
35
- key : 'keys' ,
36
- group : 'Base' ,
37
- flavors : allFlavors ,
38
- help : 'Keys to use to determine each serie.' ,
39
- type : 'string[]' ,
40
- required : false ,
41
- defaultValue : defaults . keys ,
42
- } ,
43
22
{
44
23
key : 'minValue' ,
45
- help : 'Minimum value.' ,
46
- flavors : allFlavors ,
47
24
description : `
48
- Minimum value.
49
25
If 'auto', will pick the lowest value
50
26
in the provided data set. Should be overriden
51
27
if your data set does not contain desired
52
28
lower bound value.
53
29
` ,
54
- required : false ,
55
30
defaultValue : defaults . minValue ,
56
31
type : `number | 'auto'` ,
57
32
group : 'Base' ,
@@ -65,15 +40,13 @@ const props: ChartProperty[] = [
65
40
} ,
66
41
{
67
42
key : 'maxValue' ,
68
- help : 'Maximum value.' ,
69
43
flavors : allFlavors ,
70
44
description : `
71
- Maximum value. If 'auto', will pick the highest value
45
+ If 'auto', will pick the highest value
72
46
in the provided data set. Should be overriden
73
47
if your data set does not contain desired
74
48
higher bound value.
75
49
` ,
76
- required : false ,
77
50
defaultValue : defaults . maxValue ,
78
51
type : `number | 'auto'` ,
79
52
group : 'Base' ,
@@ -85,149 +58,176 @@ const props: ChartProperty[] = [
85
58
max : 100 ,
86
59
} ,
87
60
} ,
61
+ {
62
+ key : 'valueFormat' ,
63
+ group : 'Base' ,
64
+ help : 'Optional formatter for values.' ,
65
+ description : `
66
+ The formatted value can then be used for labels & tooltips.
67
+
68
+ Under the hood, nivo uses [d3-format](https://github.com/d3/d3-format),
69
+ please have a look at it for available formats, you can also pass a function
70
+ which will receive the raw value and should return the formatted one.
71
+ ` ,
72
+ type : 'string | (value: number) => string | number' ,
73
+ control : { type : 'valueFormat' } ,
74
+ } ,
75
+ ...chartDimensions ( allFlavors ) ,
88
76
{
89
77
key : 'forceSquare' ,
90
78
help : 'Force square cells (width = height).' ,
91
- flavors : allFlavors ,
92
- required : false ,
93
79
defaultValue : defaults . forceSquare ,
94
80
type : 'boolean' ,
95
81
control : { type : 'switch' } ,
96
82
group : 'Base' ,
97
83
} ,
98
84
{
99
- key : 'sizeVariation' ,
100
- help : 'Cell size variation.' ,
101
- flavors : allFlavors ,
102
- description : `Size variation (0~1), if value is 0 size won't be affected. If you use for example the value 0.3, cell width/height will vary between 0.7~1 according to its corresponding value.` ,
103
- required : false ,
104
- defaultValue : defaults . sizeVariation ,
85
+ key : 'xOuterPadding' ,
86
+ defaultValue : defaults . xOuterPadding ,
105
87
type : 'number' ,
106
88
group : 'Base' ,
107
89
control : {
108
90
type : 'range' ,
109
91
min : 0 ,
110
92
max : 1 ,
111
- step : 0.02 ,
93
+ step : 0.05 ,
112
94
} ,
113
95
} ,
114
96
{
115
- key : 'padding' ,
116
- help : 'Padding.' ,
117
- flavors : allFlavors ,
118
- required : false ,
119
- defaultValue : defaults . padding ,
97
+ key : 'xInnerPadding' ,
98
+ defaultValue : defaults . xInnerPadding ,
120
99
type : 'number' ,
121
100
group : 'Base' ,
122
101
control : {
123
102
type : 'range' ,
124
103
min : 0 ,
125
- max : 36 ,
126
- unit : 'px' ,
104
+ max : 1 ,
105
+ step : 0.05 ,
127
106
} ,
128
107
} ,
129
- ...chartDimensions ( allFlavors ) ,
130
- themeProperty ( [ 'svg' , 'canvas' , 'api' ] ) ,
131
108
{
132
- key : 'cellShape' ,
133
- help : `Cell shape/component.` ,
109
+ key : 'yOuterPadding' ,
134
110
flavors : allFlavors ,
135
- description : `
136
- Cell shape, can be one of: \`'rect'\`, \`'circle'\`,
137
- if a function is provided, it must return
138
- a valid SVG element and will receive
139
- the following props:
140
- \`\`\`
141
- {
142
- value: number,
143
- x: number,
144
- y: number,
145
- width: number,
146
- height: number,
147
- color: string,
148
- opacity: number,
149
- borderWidth: number,
150
- borderColor: string,
151
- textColor: string,
152
- }
153
- \`\`\`
154
- ` ,
155
- type : 'string | Function' ,
156
- required : false ,
157
- defaultValue : defaults . cellShape ,
158
- group : 'Style' ,
111
+ defaultValue : defaults . yOuterPadding ,
112
+ type : 'number' ,
113
+ group : 'Base' ,
159
114
control : {
160
- type : 'choices' ,
161
- choices : [ 'rect' , 'circle' , 'Custom(props) => (…)' ] . map ( key => ( {
162
- label : key ,
163
- value : key ,
164
- } ) ) ,
115
+ type : 'range' ,
116
+ min : 0 ,
117
+ max : 1 ,
118
+ step : 0.05 ,
119
+ } ,
120
+ } ,
121
+ {
122
+ key : 'yInnerPadding' ,
123
+ defaultValue : defaults . yInnerPadding ,
124
+ type : 'number' ,
125
+ group : 'Base' ,
126
+ control : {
127
+ type : 'range' ,
128
+ min : 0 ,
129
+ max : 1 ,
130
+ step : 0.05 ,
165
131
} ,
166
132
} ,
133
+ {
134
+ key : 'sizeVariation' ,
135
+ help : 'Cell size variation.' ,
136
+ description : `Size variation (0~1), if value is 0 size won't be affected. If you use for example the value 0.3, cell width/height will vary between 0.7~1 according to its corresponding value.` ,
137
+ defaultValue : defaults . sizeVariation ,
138
+ type : 'number' ,
139
+ group : 'Base' ,
140
+ control : {
141
+ type : 'range' ,
142
+ min : 0 ,
143
+ max : 1 ,
144
+ step : 0.02 ,
145
+ } ,
146
+ } ,
147
+ themeProperty ( allFlavors ) ,
167
148
{
168
149
key : 'colors' ,
169
- help : 'Defines color range.' ,
170
- flavors : allFlavors ,
171
- type : 'string | Function | string[]' ,
172
- required : false ,
173
- defaultValue : 'nivo' ,
174
- control : { type : 'quantizeColors' } ,
175
150
group : 'Style' ,
151
+ type : 'ContinuousColorScaleConfig | ((datum) => string)' ,
152
+ control : {
153
+ type : 'continuous_colors' ,
154
+ } ,
176
155
} ,
177
156
{
178
157
key : 'cellOpacity' ,
179
- help : 'Cell opacity (0~1).' ,
180
- flavors : allFlavors ,
181
- required : false ,
158
+ group : 'Style' ,
159
+ defaultValue : defaults . cellOpacity ,
160
+ type : 'number' ,
161
+ control : { type : 'opacity' } ,
162
+ } ,
163
+ {
164
+ key : 'activeCellOpacity' ,
165
+ group : 'Style' ,
166
+ flavors : [ 'svg' , 'canvas' ] ,
167
+ defaultValue : defaults . cellOpacity ,
168
+ type : 'number' ,
169
+ control : { type : 'opacity' } ,
170
+ } ,
171
+ {
172
+ key : 'inactiveCellOpacity' ,
173
+ group : 'Style' ,
174
+ flavors : [ 'svg' , 'canvas' ] ,
182
175
defaultValue : defaults . cellOpacity ,
183
176
type : 'number' ,
184
177
control : { type : 'opacity' } ,
178
+ } ,
179
+ {
180
+ key : 'borderRadius' ,
185
181
group : 'Style' ,
182
+ help : 'Cell border radius, when using `rect`.' ,
183
+ flavors : [ 'svg' , 'api' ] ,
184
+ defaultValue : svgDefaults . borderRadius ,
185
+ type : 'number' ,
186
+ control : { type : 'range' , min : 0 , max : 16 } ,
186
187
} ,
187
188
{
188
- key : 'cellBorderWidth' ,
189
+ key : 'borderWidth' ,
190
+ group : 'Style' ,
189
191
help : 'Cell border width.' ,
190
- flavors : allFlavors ,
191
- required : false ,
192
- defaultValue : defaults . cellBorderWidth ,
192
+ defaultValue : defaults . borderWidth ,
193
193
type : 'number' ,
194
194
control : { type : 'lineWidth' } ,
195
- group : 'Style' ,
196
195
} ,
197
196
{
198
- key : 'cellBorderColor' ,
197
+ key : 'borderColor' ,
198
+ group : 'Style' ,
199
199
help : 'Method to compute cell border color.' ,
200
- flavors : allFlavors ,
201
200
description : `
202
201
how to compute cell border color,
203
202
[see dedicated documentation](self:/guides/colors).
204
203
` ,
205
- type : 'string | object | Function' ,
206
- required : false ,
207
- defaultValue : defaults . cellBorderColor ,
204
+ type : 'InheritedColorConfig<ComputedCell>' ,
205
+ defaultValue : defaults . borderColor ,
208
206
control : { type : 'inheritedColor' } ,
209
- group : 'Style' ,
210
207
} ,
211
208
{
212
209
key : 'enableLabels' ,
213
210
help : 'Enable/disable labels.' ,
214
- flavors : allFlavors ,
215
211
type : 'boolean' ,
216
- required : false ,
217
212
defaultValue : defaults . enableLabels ,
218
213
control : { type : 'switch' } ,
219
214
group : 'Labels' ,
220
215
} ,
216
+ {
217
+ key : 'label' ,
218
+ help : 'Define what to use as a label.' ,
219
+ type : 'PropertyAccessor' ,
220
+ defaultValue : defaults . label ,
221
+ group : 'Labels' ,
222
+ } ,
221
223
{
222
224
key : 'labelTextColor' ,
223
225
help : 'Method to compute label text color.' ,
224
- flavors : allFlavors ,
225
226
description : `
226
227
how to compute label text color,
227
228
[see dedicated documentation](self:/guides/colors).
228
229
` ,
229
230
type : 'string | object | Function' ,
230
- required : false ,
231
231
defaultValue : defaults . labelTextColor ,
232
232
control : { type : 'inheritedColor' } ,
233
233
group : 'Labels' ,
@@ -238,6 +238,189 @@ const props: ChartProperty[] = [
238
238
yDefault : defaults . enableGridY ,
239
239
} ) ,
240
240
...axes ( { flavors : allFlavors } ) ,
241
+ {
242
+ key : 'legends' ,
243
+ group : 'Legends' ,
244
+ type : `ContinuousColorsLegendProps[]` ,
245
+ control : {
246
+ type : 'array' ,
247
+ shouldCreate : true ,
248
+ shouldRemove : true ,
249
+ props : [
250
+ {
251
+ key : 'anchor' ,
252
+ type : 'LegendAnchor' ,
253
+ control : { type : 'boxAnchor' } ,
254
+ } ,
255
+ {
256
+ key : 'translateX' ,
257
+ type : 'number' ,
258
+ control : {
259
+ type : 'range' ,
260
+ min : - 200 ,
261
+ max : 200 ,
262
+ } ,
263
+ } ,
264
+ {
265
+ key : 'translateY' ,
266
+ type : 'number' ,
267
+ control : {
268
+ type : 'range' ,
269
+ min : - 200 ,
270
+ max : 200 ,
271
+ } ,
272
+ } ,
273
+ {
274
+ key : 'length' ,
275
+ type : 'number' ,
276
+ control : {
277
+ type : 'range' ,
278
+ min : 60 ,
279
+ max : 500 ,
280
+ } ,
281
+ } ,
282
+ {
283
+ key : 'thickness' ,
284
+ type : 'number' ,
285
+ control : {
286
+ type : 'range' ,
287
+ min : 6 ,
288
+ max : 32 ,
289
+ } ,
290
+ } ,
291
+ {
292
+ key : 'direction' ,
293
+ type : `'row' | 'column'` ,
294
+ control : {
295
+ type : 'radio' ,
296
+ choices : [
297
+ {
298
+ label : 'row' ,
299
+ value : 'row' ,
300
+ } ,
301
+ {
302
+ label : 'column' ,
303
+ value : 'column' ,
304
+ } ,
305
+ ] ,
306
+ } ,
307
+ } ,
308
+ {
309
+ key : 'tickPosition' ,
310
+ type : `'before' | 'after'` ,
311
+ control : {
312
+ type : 'radio' ,
313
+ choices : [
314
+ {
315
+ label : 'before' ,
316
+ value : 'before' ,
317
+ } ,
318
+ {
319
+ label : 'after' ,
320
+ value : 'after' ,
321
+ } ,
322
+ ] ,
323
+ } ,
324
+ } ,
325
+ {
326
+ key : 'tickSize' ,
327
+ type : 'number' ,
328
+ control : {
329
+ type : 'range' ,
330
+ min : 0 ,
331
+ max : 12 ,
332
+ } ,
333
+ } ,
334
+ {
335
+ key : 'tickSpacing' ,
336
+ type : 'number' ,
337
+ control : {
338
+ type : 'range' ,
339
+ min : 0 ,
340
+ max : 12 ,
341
+ } ,
342
+ } ,
343
+ {
344
+ key : 'tickOverlap' ,
345
+ type : 'boolean' ,
346
+ control : { type : 'switch' } ,
347
+ } ,
348
+ {
349
+ key : 'title' ,
350
+ type : 'string' ,
351
+ control : { type : 'text' } ,
352
+ } ,
353
+ {
354
+ key : 'titleAlign' ,
355
+ type : `'start' | 'middle' | 'end'` ,
356
+ control : {
357
+ type : 'radio' ,
358
+ choices : [
359
+ {
360
+ label : 'start' ,
361
+ value : 'start' ,
362
+ } ,
363
+ {
364
+ label : 'middle' ,
365
+ value : 'middle' ,
366
+ } ,
367
+ {
368
+ label : 'end' ,
369
+ value : 'end' ,
370
+ } ,
371
+ ] ,
372
+ } ,
373
+ } ,
374
+ {
375
+ key : 'titleOffset' ,
376
+ type : 'number' ,
377
+ control : {
378
+ type : 'range' ,
379
+ min : 0 ,
380
+ max : 12 ,
381
+ } ,
382
+ } ,
383
+ ] ,
384
+ } ,
385
+ } ,
386
+ {
387
+ key : 'layers' ,
388
+ type : `('grid' | 'axes' | 'cells' | CustomLayer | CustomCanvasLayer)[]` ,
389
+ group : 'Customization' ,
390
+ help : 'Defines the order of layers and add custom layers, please use the appropriate variant for custom layers.' ,
391
+ defaultValue : defaults . layers ,
392
+ flavors : [ 'svg' , 'canvas' ] ,
393
+ } ,
394
+ {
395
+ key : 'cellComponent' ,
396
+ group : 'Customization' ,
397
+ type : `'rect' | 'circle' | CellComponent` ,
398
+ help : 'Cell component, the API does not support `CellComponent`.' ,
399
+ flavors : [ 'svg' , 'api' ] ,
400
+ defaultValue : 'rect' ,
401
+ control : {
402
+ type : 'choices' ,
403
+ choices : [ 'rect' , 'circle' , 'CustomCell' ] . map ( key => ( {
404
+ label : key ,
405
+ value : key ,
406
+ } ) ) ,
407
+ } ,
408
+ } ,
409
+ {
410
+ key : 'renderCell' ,
411
+ group : 'Customization' ,
412
+ type : `'rect' | 'circle' | CellCanvasRenderer` ,
413
+ help : 'Cell renderer for canvas implementation.' ,
414
+ flavors : [ 'canvas' ] ,
415
+ defaultValue : 'rect' ,
416
+ control : {
417
+ type : 'choices' ,
418
+ choices : [ 'rect' , 'circle' , 'customRenderCell' ] . map ( key => ( {
419
+ label : key ,
420
+ value : key ,
421
+ } ) ) ,
422
+ } ,
423
+ } ,
241
424
isInteractive ( {
242
425
flavors : [ 'svg' , 'canvas' ] ,
243
426
defaultValue : defaults . isInteractive ,
@@ -247,7 +430,6 @@ const props: ChartProperty[] = [
247
430
flavors : [ 'svg' , 'canvas' ] ,
248
431
group : 'Interactivity' ,
249
432
type : '(cell, event) => void' ,
250
- required : false ,
251
433
help : 'onClick handler.' ,
252
434
description : `
253
435
onClick handler, will receive node data
@@ -280,7 +462,6 @@ const props: ChartProperty[] = [
280
462
- **column**: highlight the current cell's column
281
463
- **rowColumn**: highlight the current cell's row & column
282
464
` ,
283
- required : false ,
284
465
defaultValue : defaults . hoverTarget ,
285
466
type : 'string' ,
286
467
group : 'Interactivity' ,
@@ -292,26 +473,7 @@ const props: ChartProperty[] = [
292
473
} ) ) ,
293
474
} ,
294
475
} ,
295
- {
296
- key : 'cellHoverOpacity' ,
297
- flavors : [ 'svg' , 'canvas' ] ,
298
- help : 'Cell opacity on hover.' ,
299
- required : false ,
300
- defaultValue : defaults . cellHoverOpacity ,
301
- type : 'number' ,
302
- control : { type : 'opacity' } ,
303
- group : 'Interactivity' ,
304
- } ,
305
- {
306
- key : 'cellHoverOthersOpacity' ,
307
- flavors : [ 'svg' , 'canvas' ] ,
308
- help : 'Cell opacity when not hovered.' ,
309
- required : false ,
310
- defaultValue : defaults . cellHoverOthersOpacity ,
311
- type : 'number' ,
312
- control : { type : 'opacity' } ,
313
- group : 'Interactivity' ,
314
- } ,
476
+ ...commonAccessibilityProps ( allFlavors ) ,
315
477
...motionProperties ( [ 'svg' ] , defaults , 'react-spring' ) ,
316
478
]
317
479
0 commit comments