forked from carbon-design-system/carbon-charts
/
charts.ts
548 lines (520 loc) · 10.7 KB
/
charts.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
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
import {
GaugeTypes,
Statuses,
ArrowDirections,
Alignments,
ChartTypes,
TreeTypes,
DividerStatus,
ColorLegendType,
ChartTheme,
} from './enums';
import {
LegendOptions,
TooltipOptions,
GridOptions,
AxesOptions,
ZoomBarsOptions,
} from './index';
import { BarOptions, StackedBarOptions, ToolbarOptions } from './components';
import {
AxisOptions,
BinnedAxisOptions,
ComboChartAxisOptions,
TimeScaleOptions,
} from './axis-scales';
/**
* Base chart options common to any chart
*/
export interface BaseChartOptions {
/**
* Optionally specify a title for the chart
*/
title?: string;
/**
* boolean to disable animations (enabled by default)
*/
animations?: boolean;
/**
* boolean to prevent the container from resizing
*/
resizable?: boolean;
/**
* Optionally specify a width for the chart
*/
width?: string;
/**
* Optionally specify a height for the chart
*/
height?: string;
/**
* Optionally specify a theme for the chart
*/
theme?: ChartTheme;
/**
* tooltip configuration
*/
tooltip?: TooltipOptions;
/**
* legend configuration
*/
legend?: LegendOptions;
/**
* toolbar configurations
*/
toolbar?: ToolbarOptions;
/**
* Optional function to determine whether is filled based on datasetLabel, label, and/or data
*/
getIsFilled?: (
datasetLabel: any,
label?: any,
data?: any,
defaultFilled?: boolean
) => boolean;
/**
* Optional function to generate the fill color based on datasetLabel, label, and/or data
*/
getFillColor?: (
group: string,
label?: string,
data?: any,
defaultFillColor?: string
) => string;
/**
* Optional function to generate the stroke color based on datasetLabel, label, and/or data
* (note) - not all chart types support the stroke color (e.g. wordcloud)
*/
getStrokeColor?: (
group: string,
label?: any,
data?: any,
defaultStrokeColor?: string
) => string;
/**
* stylesheet options
*/
style?: {
/**
* optional prefixing string for css classes (defaults to 'cc')
*/
prefix?: string;
};
/**
* options related to charting data
*/
data?: {
/**
* identifier for data groups
*/
groupMapsTo?: string;
/**
* used to simulate data loading in skeleton way
*/
loading?: boolean;
/**
* options related to pre-selected data groups
* Remains empty if every legend item is active or dataset doesn't have the data groups.
*/
selectedGroups?: string[];
};
/**
* options related to color scales
*/
color?: {
/**
* e.g. { 'Dataset 1': 'blue' }
*/
scale?: object;
/**
* use a carbon dataviz preset color palette
* put the index (selection of which variant)
*/
pairing?: {
/**
* the number of color variants in the palette (defaults to using the number of data groups in the given data)
*/
numberOfVariants?: number;
/**
* the option number of the color paring
*/
option?: number;
};
/*
* options related to gradient
* e.g. { enabled: true }
*/
gradient?: {
enabled?: boolean;
/**
* hex color array
* e.g. ['#fff', '#000', ...]
*/
colors?: Array<String>;
};
};
}
/**
* Options common to any chart with an axis
*/
export interface AxisChartOptions extends BaseChartOptions {
axes?: AxesOptions<AxisOptions>;
grid?: GridOptions;
timeScale?: TimeScaleOptions;
/**
* zoombar configuration
*/
zoomBar?: ZoomBarsOptions;
}
/**
* Options common to binned charts with an axis
*/
export interface BinnedAxisChartOptions extends AxisChartOptions {
axes?: AxesOptions<BinnedAxisOptions>;
grid?: GridOptions;
timeScale?: TimeScaleOptions;
/**
* zoombar configuration
*/
zoomBar?: ZoomBarsOptions;
}
/**
* options specific to boxplot charts
*/
export interface BoxplotChartOptions extends AxisChartOptions {}
/**
* options specific to bar charts
*/
export interface BarChartOptions extends AxisChartOptions {
bars?: BarOptions;
}
/**
* options specific to stacked bar charts
*/
export interface StackedBarChartOptions extends BarChartOptions {
bars?: StackedBarOptions;
}
/**
* options specific to scatter charts
*/
export interface ScatterChartOptions extends AxisChartOptions {
/**
* options for the points
*/
points?: {
/**
* sets the radius of the point
*/
radius: number;
fillOpacity?: number;
filled?: boolean;
enabled?: boolean;
};
}
/**
* options specific to lollipop charts
*/
export interface LollipopChartOptions extends ScatterChartOptions {}
/**
* options specific to bubble charts
*/
export interface BubbleChartOptions extends AxisChartOptions {
/**
* options for the individual bubbles
*/
bubble?: {
/**
* the key to lookup in charting data for the bubble radius value
*/
radiusMapsTo?: string;
/**
* options for what the bubble radius value maps to
*/
radiusLabel?: string;
/**
* A function that would determine the range of the bubble radius to use
* Returns an array with the 1st value being the min and the 2nd value being the max radius
*/
radiusRange?: Function;
/**
* Opacity of the fills used within each circle
*/
fillOpacity?: number;
/**
* enabled scatter dot or not
*/
enabled?: boolean;
};
}
/**
* options specific to bullet charts
*/
export interface BulletChartOptions extends AxisChartOptions {
/**
* options for the individual bullets
*/
bullet?: {
performanceAreaTitles?: string[];
};
}
/**
* options specific to histogram charts
*/
export interface HistogramChartOptions extends AxisChartOptions {
/**
* options related to bins
*/
bins?: {
rangeLabel?: string;
};
}
/**
* options specific to line charts
*/
export interface LineChartOptions extends ScatterChartOptions {
/**
* options for the curve of the line
*/
curve?: string | { name: string };
}
/**
* options specific to area charts
*/
export interface AreaChartOptions extends AxisChartOptions {
/**
* options for the curve of the line
*/
curve?: string | { name: string };
/**
* options to bound the area of the chart
*/
bounds?: {
upperBoundMapsTo?: string;
lowerBoundMapsTo?: string;
};
}
/**
* options specific to area charts
*/
export interface StackedAreaChartOptions extends ScatterChartOptions {
/**
* options for the curve of the line
*/
curve?: string | { name: string };
}
/**
* options specific to world cloud charts
*/
export interface WordCloudChartTooltipOptions extends TooltipOptions {
/** the label that shows up by the highlighted word in the tooltip */
wordLabel?: string;
/** the label that shows up by the value of the highlighted word in the tooltip */
valueLabel?: string;
}
export interface WorldCloudChartOptions extends BaseChartOptions {
wordCloud?: {
/** what key in your charting data will the font sizes map to? */
fontSizeMapsTo?: string;
/** a function (chartSize, data) => {} that'll decide the range of font sizes, e.g. [10, 80] */
fontSizeRange?: Function;
/** what key in your charting data will the words map to? */
wordMapsTo?: string;
};
/**
* tooltip configuration
*/
tooltip?: WordCloudChartTooltipOptions;
}
/**
* options specific to pie charts
*/
export interface PieChartOptions extends BaseChartOptions {
pie?: {
labels?: {
formatter?: Function;
enabled?: Boolean;
};
alignment?: Alignments;
/**
* identifier for value key in your charting data
* defaults to value
*/
valueMapsTo?: string;
sortFunction?: (a: any, b: any) => number;
};
}
/**
* options specific to gauge charts
*/
export interface GaugeChartOptions extends BaseChartOptions {
gauge?: {
arcWidth?: number;
deltaArrow?: {
direction?: ArrowDirections;
size?: Function;
enabled: Boolean;
};
showPercentageSymbol?: Boolean;
status?: Statuses;
deltaFontSize?: Function;
numberSpacing?: number;
numberFormatter?: Function;
valueFontSize?: Function;
type?: GaugeTypes;
alignment?: Alignments;
};
}
/**
* options specific to donut charts
*/
export interface DonutChartOptions extends PieChartOptions {
donut?: {
center?: {
label?: string;
number?: number;
numberFontSize?: Function;
titleFontSize?: Function;
titleYPosition?: Function;
numberFormatter?: Function;
};
alignment?: Alignments;
};
}
export interface MeterChartOptions extends BaseChartOptions {
meter?: {
showLabels?: boolean;
proportional?: {
total?: number;
unit?: string;
};
peak?: number;
status?: {
ranges: Array<{
range: [number, number];
status: Statuses;
}>;
};
height?: number;
title?: {
percentageIndicator?: {
/**
* rendering of the percentage value relative to the dataset within title
*/
enabled?: boolean;
};
};
};
}
export interface ProportionalMeterChartOptions extends BaseChartOptions {
meter?: {
proportional?: {
total?: number;
unit?: string;
};
};
}
/**
* options specific to radar charts
*/
export interface RadarChartOptions extends BaseChartOptions {
radar?: {
axes: {
angle: string;
value: string;
};
alignment?: Alignments;
};
}
/**
* options specific to combo charts
*/
export interface ComboChartOptions extends AxisChartOptions {
axes?: AxesOptions<ComboChartAxisOptions>;
comboChartTypes: Array<{
type: ChartTypes | any;
options?: object;
correspondingDatasets: Array<string>;
}>;
}
/*
* options specific to treemap charts
*/
export interface TreemapChartOptions extends BaseChartOptions {}
/*
* options specific to tree charts
*/
export interface TreeChartOptions extends BaseChartOptions {
tree?: {
type?: TreeTypes;
rootTitle?: string;
};
}
/*
* options specific to circle pack charts
*/
export interface CirclePackChartOptions extends BaseChartOptions {
circlePack?: {
circles: {
fillOpacity: number;
};
// depth of nodes to display
hierachyLevel: number;
padding?: {
outer?: number;
inner?: number;
};
};
}
/**
* options specific to Alluvial charts
*/
export interface AlluvialChartOptions extends BaseChartOptions {
alluvial: {
units?: string;
/**
* List of nodes to draw
*/
nodes: Array<{
name: string;
category?: string;
}>;
/**
* Node alignment (Default is center)
*/
nodeAlignment?: Alignments;
/**
* Set the node padding
*/
nodePadding?: number;
/**
* Enable single color usage for lines
*/
monochrome?: boolean;
};
}
/**
* options specific to Heatmap charts
*/
export interface HeatmapChartOptions extends BaseChartOptions {
heatmap: {
/**
* Divider width state - will default to auto
* No cell divider for cell dimensions less than 16
*/
divider?: {
state?: DividerStatus;
};
/**
* customize color legend
* enabled by default on select charts
*/
colorLegend?: {
/**
* Text to display beside or on top of the legend
* Position is determined by text length
*/
title?: string;
type: ColorLegendType;
};
};
}