UNPKG

28.2 kBTypeScriptView Raw
1/**
2 * Copyright (c) 2017 ~ present NAVER Corp.
3 * billboard.js project is licensed under the MIT license
4 */
5import { Axis } from "./axis";
6import { ChartTypes, d3Selection, DataItem, PrimitiveArray } from "./types";
7
8export interface ChartOptions {
9 /**
10 * Specify the CSS selector or the element which the chart will be set to. D3 selection object can be specified also.
11 * If other chart is set already, it will be replaced with the new one (only one chart can be set in one element).
12 * If this option is not specified, the chart will be generated but not be set.
13 * Instead, we can access the element by chart.element and set it by ourselves.
14 */
15 bindto?: string | HTMLElement | d3Selection | null | {
16 /**
17 * Specify the element where chart will be drawn.
18 */
19 element?: string | HTMLElement | d3Selection;
20
21 /**
22 * Specify the class name of bind element.
23 * NOTE: When class name isn't bb, then you also need to update the default CSS to be rendered correctly.
24 */
25 classname?: string;
26 };
27
28 size?: {
29 /**
30 * The desired width of the chart element.
31 * If this option is not specified, the width of the chart will be calculated by the size of the parent element it's appended to.
32 * Note: This option should be specified if possible because it can improve its performance because some size calculations will be skipped by an explicit value.
33 */
34 width?: number;
35
36 /**
37 * The desired height of the chart element.
38 * If this option is not specified, the height of the chart will be calculated by the size of the parent element it's appended to.
39 */
40 height?: number;
41 };
42
43 padding?: {
44 /**
45 * The padding on the top of the chart.
46 */
47 top?: number;
48
49 /**
50 * The padding on the right of the chart.
51 */
52 right?: number;
53
54 /**
55 * The padding on the bottom of the chart.
56 */
57
58 bottom?: number;
59
60 /**
61 * The padding on the left of the chart.
62 */
63 left?: number;
64 };
65
66 resize?: {
67 /**
68 * Indicate if the chart should automatically get resized when the window gets resized.
69 */
70 auto?: boolean;
71 };
72
73 color?: {
74 /**
75 * Set custom color pattern.
76 */
77 pattern?: string[];
78
79 /**
80 * color threshold for gauge and tooltip color
81 */
82 threshold?: {
83 /**
84 * If set to value, the threshold will be based on the data value.
85 * Otherwise it'll be based on equation of the threshold.max option value.
86 */
87 unit?: string;
88
89 /**
90 * Threshold values for each steps
91 */
92 values?: number[];
93
94 /**
95 * The base value to determine threshold step value condition.
96 * When the given value is 15 and max 10, then the value for threshold is 15*100/10
97 */
98 max?: number;
99 };
100
101 /**
102 * if defined, allows use svg's patterns to fill data area. It should return an array of SVGPatternElement.
103 * - NOTE: The pattern element's id will be defined as bb-colorize-pattern-$COLOR-VALUE.
104 * ex. When color pattern value is ['red', '#fff'] and defined 2 patterns,then ids for pattern elements are:
105 * - bb-colorize-pattern-red
106 * - bb-colorize-pattern-fff
107 */
108 tiles?: () => SVGPathElement[];
109 };
110
111 interaction?: {
112 /**
113 * Indicate if the chart should have interactions.
114 * If false is set, all of interactions (showing/hiding tooltip, selection, mouse events, etc) will be disabled.
115 */
116 enabled?: boolean;
117
118 /**
119 * Make brighter for the selected area (ex. 'pie' type data selected area)
120 */
121 brighten?: boolean;
122
123 inputType?: {
124 /**
125 * enable or disable mouse interaction
126 */
127 mouse?: boolean;
128
129 /**
130 * enable or disable touch interaction
131 */
132 touch?: boolean | {
133 /**
134 * enable or disable to call event.preventDefault on touchstart & touchmove event.
135 * It's usually used to prevent document scrolling.
136 */
137 preventDefault?: boolean | number;
138 };
139 }
140 };
141
142 transition?: {
143 /**
144 * Set duration of transition (in milliseconds) for chart animation.
145 * Note: If 0 or null set, transition will be skipped. So, this makes initial rendering faster especially in case you have a lot of data.
146 */
147 duration?: number;
148 };
149
150 data?: Data;
151
152 axis?: Axis;
153
154 grid?: Grid;
155
156 /**
157 * Show rectangles inside the chart.
158 * This option accepts array including object that has axis, start, end and class. The keys start, end and class are optional.
159 * axis must be x, y or y2. start and end should be the value where regions start and end. If not specified, the edge values will be used.
160 * If timeseries x axis, date string, Date object and unixtime integer can be used. If class is set, the region element will have it as class.
161 */
162 regions?: RegionOptions[];
163
164 legend?: LegendOptions;
165
166 tooltip?: TooltipOptions;
167
168 subchart?: SubchartOptions;
169
170 zoom?: ZoomOptions;
171
172 point?: PointOptions;
173
174 line?: {
175 /**
176 * Set if null data point will be connected or not.
177 * If true set, the region of null data will be connected without any data point.
178 * If false set, the region of null data will not be connected and get empty.
179 */
180 connectNull?: boolean;
181
182 /**
183 * Change step type for step chart.
184 * 'step', 'step-before' and 'step-after' can be used.
185 */
186 step?: {
187 type: "step" | "step-before" | "step-after";
188 };
189
190 /**
191 * If set, used to set a css class on each line.
192 */
193 classes?: string[];
194
195 /**
196 * Set to false to not draw points on linecharts. Or pass an array of line ids to draw points for.
197 */
198 point?: boolean | string[];
199 };
200
201 area?: {
202 /**
203 * Set if min or max value will be 0 on area chart.
204 */
205 zerobased?: boolean;
206 };
207
208 bar?: {
209 /**
210 * Change the width of bar chart. If ratio is specified, change the width of bar chart by ratio.
211 */
212 width?: number | {
213 /**
214 * Set the width of each bar by ratio
215 */
216 ratio: number;
217
218 /**
219 * Set max width of each bar
220 */
221 max?: number;
222 };
223
224 /**
225 * Set if min or max value will be 0 on bar chart.
226 */
227 zerobased?: boolean;
228
229 /**
230 * Set space between bars in bar charts
231 */
232 space?: number;
233
234 /**
235 * The padding pixel value between each bar.
236 */
237 padding?: number;
238
239 /**
240 * Set the radius of bar edge in pixel.
241 * - NOTE: Only for non-stacking bars.
242 */
243 radius?: number | {
244 /**
245 * Set the radius ratio of bar edge in relative the bar's width.
246 */
247 ratio?: number;
248 };
249 };
250
251 bubble?: {
252 /**
253 * Set the max bubble radius value
254 */
255 maxR?: (d: {}) => number | number;
256 };
257
258 radar?: {
259 axis?: {
260 /**
261 * The max value of axis. If not given, it'll take the max value from the given data.
262 */
263 max?: number;
264
265 line?: {
266 /**
267 * Show or hide axis line.
268 */
269 show?: boolean;
270 };
271
272 text?: {
273 /**
274 * Show or hide axis text.
275 */
276 show?: boolean;
277 };
278
279 direction?: {
280 /**
281 * Set the direction to be drawn.
282 */
283 clockwise: boolean;
284 };
285
286 level?: {
287 /**
288 * Set the level depth.
289 */
290 depth?: number;
291
292 /**
293 * Show or hide level.
294 */
295 show?: boolean;
296
297 text?: {
298 /**
299 * Set format function for the level value.
300 */
301 format?: (x: string) => string;
302
303 /**
304 * Show or hide level text.
305 */
306 show?: boolean;
307 };
308 }
309
310 size?: {
311 /**
312 * Set size ratio.
313 */
314 ratio?: number;
315 }
316 }
317 };
318
319 pie?: {
320 label?: {
321 /**
322 * Show or hide label on each pie piece.
323 */
324 show?: boolean;
325
326 /**
327 * Set threshold to show/hide labels.
328 */
329 threshold?: number;
330
331 /**
332 * Set formatter for the label on each pie piece.
333 */
334 format?(value: number, ratio: number, id: string): string;
335
336 /**
337 * Set ratio of labels position.
338 */
339 ratio?: (d: DataItem, radius: number, h: number) => void | number
340 };
341 /**
342 * Enable or disable expanding pie pieces.
343 */
344 expand?: boolean | {
345 /**
346 * Set expand transition time in ms.
347 */
348 duration?: number;
349 };
350
351 /**
352 * Sets the inner radius of pie arc.
353 */
354 innerRadius?: number;
355
356 /**
357 * Set padding between data.
358 */
359 padAngle?: number;
360
361 /**
362 * Sets the gap between pie arcs.
363 */
364 padding?: number;
365 };
366
367 donut?: {
368 label?: {
369 /**
370 * Show or hide label on each donut piece.
371 */
372 show?: boolean;
373
374 /**
375 * Set threshold to show/hide labels.
376 */
377 threshold?: number;
378
379 /**
380 * Set formatter for the label on each donut piece.
381 */
382 format?(value: number, ratio: number, id: string): string;
383 };
384
385 /**
386 * Enable or disable expanding pie pieces.
387 */
388 expand?: boolean;
389
390 /**
391 * Set width of donut chart.
392 */
393 width?: number;
394
395 /**
396 * Set title of donut chart.
397 */
398 title?: string;
399 };
400
401 gauge?: {
402 label?: {
403 /**
404 * Show or hide label on gauge.
405 */
406 show?: boolean;
407
408 /**
409 * Set formatter for the label on gauge.
410 */
411 format?(value: any, ratio: number): string;
412 };
413
414 /**
415 * Enable or disable expanding gauge.
416 */
417 expand?: boolean;
418
419 /**
420 * Set min value of the gauge.
421 */
422 min?: number;
423
424 /**
425 * Set max value of the gauge.
426 */
427 max?: number;
428
429 /**
430 * Set units of the gauge.
431 */
432 units?: string;
433
434 /**
435 * Set width of gauge chart.
436 */
437 width?: number;
438
439 /**
440 * Whether this should be displayed
441 * as a full circle instead of a
442 * half circle.
443 */
444 fullCircle?: boolean;
445 };
446
447 spline?: {
448 interpolation?: {
449 /**
450 * Set custom spline interpolation
451 */
452 type?: "basis"
453 | "basis-open"
454 | "bundle"
455 | "cardinal"
456 | "cardinal-closed"
457 | "cardinal-open"
458 | "catmull-rom"
459 | "catmull-rom-closed"
460 | "catmull-rom-open"
461 | "monotone-x"
462 | "monotone-y"
463 | "natural"
464 | "linear-closed"
465 | "linear"
466 | "step"
467 | "step-after"
468 | "step-before"
469 };
470 };
471
472 /**
473 * Set a callback to execute when the chart is initialized.
474 */
475 oninit?(): void;
476
477 /**
478 * Set a callback to execute after the chart is initialized
479 */
480 onafterinit?(): void;
481
482 /**
483 * Set a callback to execute before the chart is initialized
484 */
485 onbeforeinit?(): void;
486
487 /**
488 * Set a callback which is executed when the chart is rendered. Basically, this callback will be called in each time when the chart is redrawed.
489 */
490 onrendered?(): void;
491
492 /**
493 * Set a callback to execute when mouse/touch enters the chart.
494 */
495 onover?(): void;
496
497 /**
498 * Set a callback to execute when mouse/touch leaves the chart.
499 */
500 onout?(): void;
501
502 /**
503 * Set a callback to execute when user resizes the screen.
504 */
505 onresize?(): void;
506
507 /**
508 * Set a callback to execute when screen resize finished.
509 */
510 onresized?(): void;
511
512 /**
513 * Set 'clip-path' attribute for chart element.
514 * When is false, chart node element is positioned after the axis node in DOM tree hierarchy.
515 * Is to make chart element positioned over axis element.
516 */
517 clipPath?: boolean;
518}
519
520export interface RegionOptions {
521 axis?: string;
522 start?: string | number | Date;
523 end?: string | number | Date;
524 class?: string;
525}
526
527export interface LegendOptions {
528 /**
529 * Show or hide legend.
530 */
531 show?: boolean;
532
533 /**
534 * Hide legend
535 * If true given, all legend will be hidden. If string or array given, only the legend that has the id will be hidden.
536 */
537 hide?: boolean | string[] | string;
538
539 /**
540 * Change the position of legend.
541 * Currently bottom, right and inset are supported.
542 */
543 position?: string;
544
545 /**
546 * Change inset legend attributes.
547 * This option accepts object that has the keys anchor, x, y and step.
548 * - anchor: decides the position of the legend. These anchors are available: top-left, top-right, bottom-left, bottom-right
549 * - x and y: set the position of the legend based on the anchor.
550 * - step: defines the max step the lagend has (e.g. If 2 set and legend has 3 legend item, the legend 2 columns).
551 */
552 inset?: {
553 anchor?: string;
554 x?: number;
555 y?: number;
556 step?: number;
557 };
558 /**
559 * Padding between legend elements.
560 */
561 padding?: number;
562
563 item?: {
564 /**
565 * Tile settings for legend color display.
566 */
567 tile?: {
568 /**
569 * Tile width.
570 */
571 width?: number;
572
573 /**
574 * Tile height
575 */
576 height?: number;
577 };
578 /**
579 * Set click event handler to the legend item.
580 */
581 onclick?(id: DataItem): void;
582
583 /**
584 * Set mouseover event handler to the legend item.
585 */
586 onover?(id: DataItem): void;
587
588 /**
589 * Set mouseout event handler to the legend item.
590 */
591 onout?(id: DataItem): void;
592 };
593
594 /**
595 * Set legend templates
596 */
597 contents?: {
598 /**
599 * Set CSS selector or element reference to bind legend items.
600 */
601 bindto?: string | HTMLElement;
602
603 /**
604 * Set item's template.
605 * If set string value, within template the 'color' and 'title' can be replaced using template-like syntax string:
606 * {=COLOR}: data color value
607 * {=TITLE}: data title value
608 * If set function value, will pass following arguments to the given function:
609 * title {String}: data's id value
610 * color {String}: color string
611 * data {Array}: data array
612 */
613 template?: (title: string, color: string, data: DataItem[]) => void | string;
614 };
615
616 /**
617 * Whether to use custom points in legend.
618 */
619 usePoint?: boolean;
620}
621
622export interface TooltipOptions {
623 /**
624 * Show or hide tooltip.
625 */
626 show?: boolean;
627
628 /**
629 * Set if tooltip is grouped or not for the data points.
630 */
631 grouped?: boolean;
632 format?: {
633 /**
634 * Set format for the title of tooltip. Specified function receives x of the data point to show.
635 */
636 title?(x: any): string;
637
638 /**
639 * Set format for the name of each data in tooltip.
640 * Specified function receives name, ratio, id and index of the data point to show.
641 * ratio will be undefined if the chart is not donut/pie/gauge.
642 */
643 name?(name: string, ratio: number, id: string, index: number): string;
644
645 /**
646 * Set format for the value of each data in tooltip.
647 * Specified function receives name, ratio, id and index of the data point to show.
648 * ratio will be undefined if the chart is not donut/pie/gauge.
649 * If undefined returned, the row of that value will be skipped.
650 */
651 value?(value: any, ratio: number, id: string, index: number): string;
652 };
653 /**
654 * Set tooltip values order
655 * Available Values: desc, asc, any[], function (data1, data2) { ... }, null
656 */
657 order?: string | any[] | ((data1: any, data2: any) => number) | null;
658
659 /**
660 * Set custom position for the tooltip.
661 * This option can be used to modify the tooltip position by returning object that has top and left.
662 */
663 position?(
664 data: any,
665 width: number,
666 height: number,
667 element: any
668 ): { top: number; left: number };
669
670 /**
671 * Set custom HTML for the tooltip.
672 * Specified function receives data, defaultTitleFormat, defaultValueFormat and color of the data point to show.
673 * If tooltip.grouped is true, data includes multiple data points.
674 */
675 contents?(
676 data: any,
677 defaultTitleFormat: string,
678 defaultValueFormat: string,
679 color: any
680 ): string;
681
682 init?: {
683 /**
684 * Show tooltip at the initialization.
685 */
686 show?: boolean;
687
688 /**
689 * Set x Axis index to be shown at the initialization.
690 */
691 x?: number;
692
693 /**
694 * Set the position of tooltip at the initialization.
695 */
696 position?: {
697 top?: string;
698 left?: string;
699 }
700 };
701
702 /**
703 * Set a callback that will be invoked before the tooltip is shown.
704 */
705 onshow?(): void;
706
707 /**
708 * Set a callback that will be invoked before the tooltip is hidden.
709 */
710 onhide?(): void;
711
712 /**
713 * Set a callback that will be invoked after the tooltip is shown
714 */
715 onshown?(): void;
716
717 /**
718 * Set a callback that will be invoked after the tooltip is hidden.
719 */
720 onhidden?(): void;
721
722 /**
723 * Set if tooltips on all visible charts with like x points are shown together when one is shown.
724 */
725 linked?: boolean | {
726 /**
727 * Groping name for linked tooltip.
728 * If specified, linked tooltip will be groped interacting to be worked only with the same name.
729 */
730 name?: string;
731 };
732}
733
734export interface SubchartOptions {
735 /**
736 * Show sub chart on the bottom of the chart.
737 */
738 show?: boolean;
739 size?: {
740 /**
741 * Change the height of the subchart.
742 */
743 height: number;
744 };
745
746 /**
747 * Set callback for brush event.
748 * Specified function receives the current zoomed x domain.
749 */
750 onbrush?(domain: any): void;
751}
752
753export interface ZoomOptions {
754 /**
755 * Enable zooming.
756 */
757 enabled?: boolean | {
758 /**
759 * Set zoom interaction type.
760 */
761 type?: "scroll" | "drag";
762 };
763
764 /**
765 * Enable to rescale after zooming.
766 * If true set, y domain will be updated according to the zoomed region.
767 */
768 rescale?: boolean;
769
770 /**
771 * Change zoom extent.
772 */
773 extent?: [number, number];
774
775 x?: {
776 /**
777 * Set x Axis minimum zoom range
778 */
779 min?: number;
780
781 /**
782 * Set x Axis maximum zoom range
783 */
784 max?: number;
785 };
786
787 /**
788 * Set callback that is called when zooming starts.
789 * Specified function receives the zoom event.
790 */
791 onzoomstart?(event: Event): void;
792
793 /**
794 * Set callback that is called when the chart is zooming.
795 * Specified function receives the zoomed domain.
796 */
797 onzoom?(domain: any): void;
798
799 /**
800 * Set callback that is called when zooming ends.
801 * Specified function receives the zoomed domain.
802 */
803 onzoomend?(domain: any): void;
804
805 /**
806 * Set to display zoom reset button for 'drag' type zoom
807 */
808 resetButton?: boolean | {
809 /**
810 * Text value for zoom reset button.
811 */
812 text?: string;
813 };
814}
815
816export interface PointOptions {
817 /**
818 * Whether to show each point in line.
819 */
820 show?: boolean;
821
822 /**
823 * The radius size of each point.
824 */
825 r?: number | ((d: DataItem) => number);
826
827 focus?: {
828 expand: {
829 /**
830 * Whether to expand each point on focus.
831 */
832 enabled?: boolean;
833
834 /**
835 * The radius size of each point on focus.
836 */
837 r?: number;
838 };
839 };
840
841 select?: {
842 /**
843 * The radius size of each point on selected.
844 */
845 r?: number;
846 };
847
848 /**
849 * The type of point to be drawn
850 * - NOTE: If chart has 'bubble' type, only circle can be used.
851 * For IE, non circle point expansions are not supported due to lack of transform support.
852 *
853 * - Available Values:
854 * - circle
855 * - rectangle
856 */
857 type?: string;
858
859 /**
860 * The type of point or svg shape as string, to be drawn for each line
861 * - NOTE:
862 * This is an experimental feature and can have some unexpected behaviors.
863 * If chart has 'bubble' type, only circle can be used.
864 * For IE, non circle point expansions are not supported due to lack of transform support.
865 *
866 * - Available Values:
867 * - circle
868 * - rectangle
869 * - svg shape tag interpreted as string (ex. <polygon points='2.5 0 0 5 5 5'></polygon>)
870 */
871 pattern?: string[];
872}
873
874export interface Grid {
875 /**
876 * Set 'grid & focus lines' to be positioned over grid lines and chart elements.
877 */
878 front?: boolean;
879
880 focus?: {
881 /**
882 * Show grids when focus.
883 */
884 show?: boolean;
885 };
886
887 lines?: {
888 /**
889 * Set grid lines to be positioned over chart elements.
890 */
891 front?: boolean;
892 };
893
894 x?: {
895 /**
896 * Show grids along x axis.
897 */
898 show?: boolean;
899
900 /**
901 * Show additional grid lines along x axis.
902 * This option accepts array including object that has value, text, position and class.
903 * text, position and class are optional. For position, start, middle and end (default) are available.
904 * If x axis is category axis, value can be category name.
905 * If x axis is timeseries axis, value can be date string, Date object and unixtime integer.
906 */
907 lines?: LineOptions[];
908 };
909
910 y?: {
911 /**
912 * Show grids along y axis.
913 */
914 show?: boolean;
915
916 /**
917 * Show additional grid lines along y axis.
918 * This option accepts array including object that has value, text, position and class.
919 */
920 lines?: LineOptions[];
921
922 /**
923 * Number of y grids to be shown.
924 */
925 ticks?: number;
926 };
927}
928
929export interface LineOptions {
930 value: string | number | Date;
931 text?: string;
932 axis?: string;
933 position?: string;
934 class?: string;
935}
936
937export interface Data {
938 /**
939 * Load a CSV or JSON file from a URL.
940 * Note that this will not work if loading via the "file://" protocol as most browsers with block XMLHTTPRequests.
941 */
942 url?: string;
943
944 /**
945 * Load data from a multidimensional array, with the first element containing the data names, the following containing related data in that order.
946 */
947 rows?: PrimitiveArray[];
948
949 /*
950 * Load data from a multidimensional array, with each element containing an array consisting of a datum name and associated data values.
951 */
952 columns?: PrimitiveArray[];
953
954 /**
955 * XHR header value
956 * - NOTE: Should be used with data.url option
957 */
958 headers?: Array<{ [key: string]: string; }>;
959
960 /**
961 * Hide each data when the chart appears.
962 * If true specified, all of data will be hidden. If multiple ids specified as an array, those will be hidden.
963 */
964 hide?: boolean | string[];
965
966 /**
967 * Converts data id value
968 */
969 idConverter?: (id: string) => string;
970
971 /**
972 * Parse a JSON object for data.
973 */
974 json?: {};
975
976 /**
977 * Used if loading JSON via data.url
978 */
979 mimeType?: string;
980
981 /**
982 * Choose which JSON object keys correspond to desired data.
983 */
984 keys?: { x?: string; value: string[] };
985
986 /**
987 * Specify the key of x values in the data.
988 * We can show the data with non-index x values by th is option. This option is required when the type of x axis is timeseries.
989 * If this option is set on category axis, the values of the data
990 * on the key will be used for category names.
991 */
992 x?: string;
993
994 /**
995 * Specify the keys of the x values for each data.
996 * This option can be used if we want to show the data that has different x values.
997 */
998 xs?: { [key: string]: string };
999
1000 /**
1001 * Set a format to parse string specifed as x.
1002 * Default is %Y-%m-%d
1003 */
1004 xFormat?: string;
1005 /**
1006 * Set localtime format to parse x axis.
1007 */
1008 xLocaltime?: boolean;
1009
1010 /**
1011 * Sort on x axis.
1012 */
1013 xSort?: boolean;
1014
1015 /**
1016 * Set custom data name.
1017 */
1018 names?: { [key: string]: string };
1019 /**
1020 * Set custom data class.
1021 * If this option is specified, the element g for the data has an additional class that has the prefix billboard-target- (e.g. billboard-target-additional-data1-class).
1022 */
1023 classes?: { [key: string]: string };
1024
1025 /**
1026 * Set groups for the data for stacking.
1027 */
1028 groups?: string[][];
1029
1030 /**
1031 * Set y axis the data related to. y and y2 can be used.
1032 */
1033 axes?: { [key: string]: string };
1034
1035 /**
1036 * Set chart type at once.
1037 * If this option is specified, the type will be applied to every data. This setting can be overwritten by data.types.
1038 * - Available Values: area, area-line-range, area-spline, area-spline-range, area-step, bar, bubble, donut, gauge, line, pie, radar, scatter, spline, step
1039 */
1040 type?: ChartTypes;
1041
1042 /**
1043 * Set chart type for each data.
1044 * This setting overwrites data.type setting.
1045 */
1046 types?: { [key: string]: ChartTypes };
1047
1048 /**
1049 * Show labels on each data points or set formatter function for data labels.
1050 * The formatter function receives 4 arguments such as v, id, i, j and it must return a string that will be shown as the label. The arguments are:
1051 * - v is the value of the data point where the label is shown.
1052 * - id is the id of the data where the label is shown.
1053 * - i is the index of the data point where the label is shown.
1054 * - j is the sub index of the data point where the label is shown.
1055 * Formatter function can be defined for each data by specifying as an object and D3 formatter function can be set (e.g. d3.format('$'))
1056 */
1057 labels?: boolean
1058 | { format: FormatFunction }
1059 | { format: { [key: string]: FormatFunction } }
1060 | {
1061 position: {
1062 x?: number;
1063 y?: number;
1064 }
1065 };
1066
1067 /**
1068 * Define the order of the data.
1069 * This option changes the order of stacking the data and pieces of pie/donut. If null specified, it will be the order the data loaded.
1070 * If function specified, it will be used to sort the data and it will recieve the data as argument.
1071 * Available Values: desc, asc, function (data1, data2) { ... }, null
1072 */
1073 order?: string | ((...data: string[]) => void) | null;
1074
1075 /**
1076 * Define regions for each data.
1077 * The values must be an array for each data and it should include an object that has start, end, style.
1078 * If start is not set, the start will be the first data point. If end is not set, the end will be the last data point.
1079 * Currently this option supports only line chart and dashed style. If this option specified, the line will be dashed only in the regions.
1080 */
1081 regions?: { [key: string]: Array<{
1082 start?: number;
1083 end?: number;
1084 style?: {
1085 dasharray?: string;
1086 };
1087 }> };
1088
1089 /**
1090 * Set color converter function.
1091 * This option should a function and the specified function receives color (e.g. '#ff0000') and d that has data parameters like id, value, index, etc.
1092 * And it must return a string that represents color (e.g. '#00ff00').
1093 */
1094 color?(color: string, d: DataItem): string;
1095
1096 /**
1097 * Set color for each data.
1098 */
1099 colors?: {
1100 [key: string]: string | ((d: DataItem) => string);
1101 };
1102
1103 /**
1104 * Set text displayed when empty data.
1105 */
1106 empty?: { label: { text: string } };
1107
1108 selection?: {
1109 /**
1110 * Set data selection enabled
1111 * If this option is set true, we can select the data points and get/set its state of selection by API (e.g. select, unselect, selected).
1112 */
1113 enabled?: boolean;
1114
1115 /**
1116 * Set grouped selection enabled.
1117 * If this option set true, multiple data points that have same x value will be selected by one selection.
1118 */
1119 grouped?: boolean;
1120
1121 /**
1122 * Set multiple data points selection enabled.
1123 * If this option set true, multile data points can have the selected state at the same time.
1124 * If false set, only one data point can have the selected state and the others will be unselected when the new data point is selected.
1125 */
1126 multiple?: boolean;
1127
1128 /**
1129 * Enable to select data points by dragging. If this option set true, data points can be selected by dragging.
1130 * NOTE: If this option set true, scrolling on the chart will be disabled because dragging event will handle the event.
1131 */
1132 draggable?: boolean;
1133
1134 /**
1135 * Set a callback for each data point to determine if it's selectable or not.
1136 * The callback will receive d as an argument and it has some parameters like id, value, index. This callback should return boolean.
1137 * @param d Data object
1138 */
1139 isselectable?(d?: any): boolean;
1140 };
1141
1142 filter?: (v: Array<{
1143 id: string;
1144 id_org: string;
1145 values: Array<{
1146 x: number;
1147 value: number;
1148 id: string;
1149 index: number;
1150 }>
1151 }>) => boolean;
1152
1153 stack?: {
1154 /**
1155 * Set the stacking to be normalized
1156 * - NOTE: For stacking, 'data.groups' option should be set
1157 * - y Axis will be set in percentage value (0 ~ 100%)
1158 * - Must have postive values
1159 */
1160 normalize?: boolean;
1161 };
1162
1163 /**
1164 * Set a callback for click event on each data point.
1165 * This callback will be called when each data point clicked and will receive d and element as the arguments.
1166 * - d is the data clicked and element is the element clicked. In this callback, this will be the Chart object.
1167 */
1168 onclick?(d: DataItem, element: any): void;
1169
1170 /**
1171 * Set a callback for mouse/touch over event on each data point.
1172 * This callback will be called when mouse cursor or via touch moves onto each data point and will receive d as the argument.
1173 * - d is the data where mouse cursor moves onto. In this callback, this will be the Chart object.
1174 */
1175 onover?(d: DataItem, element?: any): void;
1176
1177 /**
1178 * Set a callback for mouse/touch event on each data point.
1179 * This callback will be called when mouse cursor moves out each data point and will receive d as the argument.
1180 * - d is the data where mouse cursor moves out. In this callback, this will be the Chart object.
1181 */
1182 onout?(d: DataItem, element?: any): void;
1183
1184 /**
1185 * Set a callback for on data selection.
1186 */
1187 onselected?(d: DataItem, element?: any): void;
1188
1189 /**
1190 * Set a callback for on data un-selection.
1191 */
1192 onunselected?(d: DataItem, element?: any): void;
1193
1194 /**
1195 * Set a callback for minimum data
1196 * - NOTE: For 'area-line-range' and 'area-spline-range', mid data will be taken for the comparison
1197 */
1198 onmin?(d: DataItem[]): void;
1199
1200 /**
1201 * Set a callback for maximum data
1202 * - NOTE: For 'area-line-range' and 'area-spline-range', mid data will be taken for the comparison
1203 */
1204 onmax?(d: DataItem[]): void;
1205}
1206
1207export type FormatFunction = (
1208 v: any,
1209 id: string,
1210 i: number,
1211 j: number
1212) => void;