-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
props.ts
388 lines (385 loc) · 10.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
import { timeRangeDefaultProps as defaults } from '@nivo/calendar'
import { themeProperty, getLegendsProps, groupProperties } from '../../../lib/componentProperties'
import { chartDimensions, isInteractive } from '../../../lib/chart-properties'
import { ChartProperty, Flavor } from '../../../types'
const allFlavors: Flavor[] = ['svg']
const props: ChartProperty[] = [
{
key: 'data',
group: 'Base',
help: 'Chart data.',
flavors: allFlavors,
description: `
Chart data, which must conform to this structure:
\`\`\`
Array<{
day: string, // format must be YYYY-MM-DD
value: number
}>
\`\`\`
You can also add arbitrary data to this structure
to be used in tooltips or event handlers.
`,
type: 'object[]',
required: true,
},
{
key: 'from',
group: 'Base',
flavors: allFlavors,
help: 'start date',
type: 'string | Date',
required: false,
},
{
key: 'to',
group: 'Base',
help: 'end date',
flavors: allFlavors,
type: 'string | Date',
required: false,
},
...chartDimensions(allFlavors),
{
key: 'direction',
help: 'defines calendar layout direction.',
flavors: allFlavors,
type: 'string',
required: false,
defaultValue: defaults.direction,
group: 'Base',
control: {
type: 'radio',
choices: [
{ label: 'horizontal', value: 'horizontal' },
{ label: 'vertical', value: 'vertical' },
],
},
},
{
key: 'align',
help: 'defines how calendar should be aligned inside chart container.',
flavors: allFlavors,
type: 'string',
required: false,
defaultValue: defaults.align,
group: 'Base',
control: {
type: 'boxAnchor',
},
},
{
key: 'minValue',
help: 'Minimum value.',
flavors: allFlavors,
description: `
Minimum value. If 'auto', will pick the lowest value
in the provided data set.
Should be overriden if your data set does not contain
desired lower bound value.
`,
required: false,
defaultValue: defaults.minValue,
type: `number | 'auto'`,
group: 'Base',
control: {
type: 'switchableRange',
disabledValue: 'auto',
defaultValue: 0,
min: -300,
max: 300,
},
},
{
key: 'maxValue',
help: 'Maximum value.',
flavors: allFlavors,
description: `
Maximum value. If 'auto', will pick the highest value
in the provided data set.
Should be overriden if your data set does not contain
desired higher bound value.
`,
required: false,
defaultValue: defaults.maxValue,
type: `number | 'auto'`,
group: 'Base',
control: {
type: 'switchableRange',
disabledValue: 'auto',
defaultValue: 100,
min: 0,
max: 600,
},
},
themeProperty(['svg']),
{
key: 'colors',
group: 'Style',
flavors: allFlavors,
help: 'Cell colors.',
description: `
An array of colors to be used in conjunction with
\`domain\` to compute days' color.
It applies to days having a value defined, otherwise,
\`emptyColor\` will be used.
`,
type: 'string[]',
required: false,
defaultValue: defaults.colors,
},
{
key: 'emptyColor',
help: 'color to use to fill days without available value.',
flavors: allFlavors,
type: 'string',
required: false,
defaultValue: defaults.emptyColor,
control: { type: 'colorPicker' },
group: 'Style',
},
// Months
{
key: 'monthLegend',
help: `can be used to customize months label, returns abbreviated month name (english) by default. This can be used to use a different language`,
flavors: allFlavors,
type: '(year: number, month: number, date: Date) => string | number',
required: false,
group: 'Months',
},
{
key: 'monthLegendPosition',
help: 'defines month legends position.',
flavors: allFlavors,
type: `'before' | 'after'`,
required: false,
defaultValue: defaults.monthLegendPosition,
group: 'Months',
control: {
type: 'radio',
choices: [
{ label: 'before', value: 'before' },
{ label: 'after', value: 'after' },
],
},
},
{
key: 'monthLegendOffset',
help: 'define offset from month edge to its label.',
flavors: allFlavors,
type: 'number',
required: false,
defaultValue: defaults.monthLegendOffset,
group: 'Months',
control: {
type: 'range',
unit: 'px',
min: 0,
max: 36,
},
},
// Weekday
{
key: 'weekdayLegendOffset',
help: 'define offset from weekday edge to its label.',
flavors: allFlavors,
type: 'number',
required: false,
defaultValue: defaults.weekdayLegendOffset,
group: 'Weekday',
control: {
type: 'range',
unit: 'px',
min: 0,
max: 100,
},
},
{
key: 'weekdays',
help: 'define labels for weekdays',
flavors: allFlavors,
type: 'Array<string>',
required: false,
defaultValue: defaults.weekdays,
group: 'Weekday',
},
{
key: 'weekdayTicks',
help: 'define weekday tickmarks to show',
flavors: allFlavors,
type: '(0 | 1 | 2 | 3 | 4 | 5 | 6)[]',
required: false,
defaultValue: [1, 3, 5],
group: 'Weekday',
description: `
Array of weekday tickmarks to display:\n
0 = Sunday\n
1 = Monday\n
2 = Tuesday\n
3 = Wednesday\n
4 = Thursday\n
5 = Friday\n
6 = Saturday\n
`,
},
{
key: 'firstWeekday',
help: `define the first weekday: 'sunday', 'monday', etc.`,
flavors: allFlavors,
type: 'Weekday',
required: false,
defaultValue: defaults.firstWeekday,
group: 'Weekday',
control: {
type: 'radio',
choices: [
{ label: `'sunday'`, value: 'sunday' },
{ label: `'monday'`, value: 'monday' },
],
},
},
// Days
{
key: 'square',
help: 'force day cell into square shape',
flavors: allFlavors,
type: 'boolean',
required: false,
defaultValue: defaults.square,
control: { type: 'switch' },
group: 'Days',
},
{
key: 'dayRadius',
help: 'define border radius of each day cell.',
flavors: allFlavors,
type: 'number',
required: false,
defaultValue: defaults.dayRadius,
group: 'Days',
control: {
type: 'range',
unit: 'px',
min: 0,
max: 20,
},
},
{
key: 'daySpacing',
help: 'define spacing between each day cell.',
flavors: allFlavors,
type: 'number',
required: false,
defaultValue: defaults.daySpacing,
group: 'Days',
control: {
type: 'range',
unit: 'px',
min: 0,
max: 20,
},
},
{
key: 'dayBorderWidth',
help: 'width of days border.',
flavors: allFlavors,
type: 'number',
required: false,
defaultValue: defaults.dayBorderWidth,
control: { type: 'lineWidth' },
group: 'Days',
},
{
key: 'dayBorderColor',
help: 'color to use for days border.',
flavors: allFlavors,
type: 'string',
required: false,
defaultValue: defaults.dayBorderColor,
control: { type: 'colorPicker' },
group: 'Days',
},
isInteractive({
flavors: ['svg'],
defaultValue: defaults.isInteractive,
}),
{
key: 'onClick',
group: 'Interactivity',
flavors: allFlavors,
help: 'onClick handler, it receives clicked day data and mouse event.',
type: '(day, event) => void',
required: false,
},
{
key: 'tooltip',
group: 'Interactivity',
flavors: allFlavors,
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 data:
\`\`\`
{
day: string,
date: {Date},
value: number,
color: string,
coordinates: {
x: number,
y: number,
},
height: number
width: number
}
\`\`\`
You can also customize the tooltip style
using the \`theme.tooltip\` object.
`,
},
{
key: 'custom tooltip example',
help: 'Showcase custom tooltip.',
flavors: allFlavors,
type: 'boolean',
required: false,
control: { type: 'switch' },
group: 'Interactivity',
},
{
key: 'legends',
flavors: ['svg'],
type: 'LegendProps[]',
help: `Optional chart's legends.`,
group: 'Legends',
required: false,
control: {
type: 'array',
props: getLegendsProps(['svg']),
shouldCreate: true,
addLabel: 'add legend',
shouldRemove: true,
getItemTitle: (index, legend: any) =>
`legend[${index}]: ${legend.anchor}, ${legend.direction}`,
defaults: {
anchor: 'bottom-right',
direction: 'row',
justify: false,
itemCount: 4,
itemWidth: 42,
itemHeight: 36,
itemsSpacing: 14,
itemDirection: 'right-to-left',
translateX: -85,
translateY: -240,
symbolSize: 20,
onClick: (data: any) => {
console.log(JSON.stringify(data, null, ' '))
},
},
},
},
]
export const groups = groupProperties(props)