/
index.d.ts
1129 lines (1028 loc) · 35.5 KB
/
index.d.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
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
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { BasePlatform } from '../platform';
import {
Color,
EasingFunction,
IChartArea,
IChartComponent,
IFontSpec,
IPoint,
Scriptable,
TimeUnit,
IEvent,
} from './interfaces';
import {
DefaultDataPoint,
IChartConfiguration,
IChartData,
IChartDataset,
IChartOptions,
IChartType,
IScaleOptions
} from '../interfaces';
export interface IDateAdapter {
/**
* Returns a map of time formats for the supported formatting units defined
* in Unit as well as 'datetime' representing a detailed date/time string.
* @returns {{string: string}}
*/
formats(): { [key: string]: string };
/**
* Parses the given `value` and return the associated timestamp.
* @param {any} value - the value to parse (usually comes from the data)
* @param {string} [format] - the expected data format
*/
parse(value: any, format?: TimeUnit): number | null;
/**
* Returns the formatted date in the specified `format` for a given `timestamp`.
* @param {number} timestamp - the timestamp to format
* @param {string} format - the date/time token
* @return {string}
*/
format(timestamp: number, format: TimeUnit): string;
/**
* Adds the specified `amount` of `unit` to the given `timestamp`.
* @param {number} timestamp - the input timestamp
* @param {number} amount - the amount to add
* @param {Unit} unit - the unit as string
* @return {number}
*/
add(timestamp: number, amount: number, unit: TimeUnit): number;
/**
* Returns the number of `unit` between the given timestamps.
* @param {number} a - the input timestamp (reference)
* @param {number} b - the timestamp to subtract
* @param {Unit} unit - the unit as string
* @return {number}
*/
diff(a: number, b: number, unit: TimeUnit): number;
/**
* Returns start of `unit` for the given `timestamp`.
* @param {number} timestamp - the input timestamp
* @param {Unit|'isoWeek'} unit - the unit as string
* @param {number} [weekday] - the ISO day of the week with 1 being Monday
* and 7 being Sunday (only needed if param *unit* is `isoWeek`).
* @return {number}
*/
startOf(timestamp: number, unit: TimeUnit | 'isoWeek', weekday?: number): number;
/**
* Returns end of `unit` for the given `timestamp`.
* @param {number} timestamp - the input timestamp
* @param {Unit|'isoWeek'} unit - the unit as string
* @return {number}
*/
endOf(timestamp: number, unit: TimeUnit | 'isoWeek'): number;
}
export interface DateAdapter extends IDateAdapter {
readonly options: any;
}
export const DateAdapter: {
prototype: DateAdapter;
new(options: any): DateAdapter;
override(members: Partial<IDateAdapter>): void;
};
export const _adapters: {
_date: DateAdapter;
};
export class Animation {
constructor(cfg: any, target: any, prop: string, to?: any);
active(): boolean;
update(cfg: any, to: any, date: number): void;
cancel(): void;
tick(date: number): void;
}
export interface IAnimationEvent {
chart: Chart;
numSteps: number;
currentState: number;
}
export class Animator {
listen(chart: Chart, event: 'complete' | 'progress', cb: (event: IAnimationEvent) => void): void;
add(chart: Chart, items: readonly Animation[]): void;
has(chart: Chart): boolean;
start(chart: Chart): void;
running(chart: Chart): boolean;
stop(chart: Chart): void;
remove(chart: Chart): boolean;
}
export class Animations {
constructor(chart: Chart, animations: {});
configure(animations: {}): void;
update(target: any, values: any): undefined | boolean;
}
export interface IAnimationCommonSpec {
/**
* The number of milliseconds an animation takes.
* @default 1000
*/
duration: number;
/**
* Easing function to use
* @default 'easeOutQuart'
*/
easing: EasingFunction;
/**
* Running animation count + FPS display in upper left corner of the chart.
* @default false
*/
debug: boolean;
/**
* Delay before starting the animations.
* @default 0
*/
delay: number;
/**
* If set to true, the animations loop endlessly.
* @default false
*/
loop: boolean;
}
export interface IAnimationPropertySpec extends IAnimationCommonSpec {
properties: string[];
/**
* Type of property, determines the interpolator used. Possible values: 'number', 'color' and 'boolean'. Only really needed for 'color', because typeof does not get that right.
*/
type: 'color' | 'number' | 'boolean';
fn: <T>(from: T, to: T, factor: number) => T;
/**
* Start value for the animation. Current value is used when undefined
*/
from: Color | number | boolean;
/**
*
*/
to: Color | number | boolean;
}
export type IAnimationSpecContainer = IAnimationCommonSpec & {
[prop: string]: IAnimationPropertySpec;
};
export type IAnimationOptions = IAnimationSpecContainer & {
/**
* Callback called on each step of an animation.
*/
onProgress: (this: Chart, event: IAnimationEvent) => void;
/**
*Callback called when all animations are completed.
*/
onComplete: (this: Chart, event: IAnimationEvent) => void;
active: IAnimationSpecContainer;
hide: IAnimationSpecContainer;
reset: IAnimationSpecContainer;
resize: IAnimationSpecContainer;
show: IAnimationSpecContainer;
};
export interface IChartAnimationOptions {
animation: Scriptable<IAnimationOptions>;
datasets: {
animation: Scriptable<IAnimationOptions>;
};
}
export interface IChartMeta<E extends Element = Element, DSE extends Element = Element> {
type: string;
controller: DatasetController;
order: number;
label: string;
index: number;
visible: boolean;
stack: number;
indexAxis: 'x' | 'y';
data: E[];
dataset?: DSE;
hidden: boolean;
xAxisID?: string;
yAxisID?: string;
rAxisID?: string;
iAxisID: string;
vAxisID: string;
xScale?: Scale;
yScale?: Scale;
rScale?: Scale;
iScale?: Scale;
vScale?: Scale;
_sorted: boolean;
_stacked: boolean;
_parsed: any[];
}
export interface IParsingOptions {
parsing:
| {
[key: string]: string;
}
| false;
}
export interface ActiveDataPoint {
datasetIndex: number;
index: number;
}
export interface ActiveElement extends ActiveDataPoint {
element: Element;
}
export declare class Chart<
TYPE extends IChartType = IChartType,
DATA extends unknown[] = DefaultDataPoint<TYPE>,
LABEL = string
> {
readonly platform: BasePlatform;
readonly id: string;
readonly canvas: HTMLCanvasElement;
readonly ctx: CanvasRenderingContext2D;
readonly config: IChartConfiguration<TYPE, DATA, LABEL>
readonly width: number;
readonly height: number;
readonly aspectRatio: number;
readonly boxes: ILayoutItem[];
readonly currentDevicePixelRatio: number;
readonly chartArea: IChartArea;
readonly scales: { [key: string]: Scale };
readonly scale: Scale | undefined;
readonly attached: boolean;
data: IChartData<TYPE, DATA, LABEL>;
options: IChartOptions<TYPE>;
constructor(item: ChartItem, config: IChartConfiguration<TYPE, DATA, LABEL>);
clear(): this;
stop(): this;
resize(width: number, height: number): void;
ensureScalesHaveIDs(): void;
buildOrUpdateScales(): void;
buildOrUpdateControllers(): void;
reset(): void;
update(mode?: UpdateMode): void;
render(): void;
draw(): void;
getElementsAtEventForMode(e: Event, mode: string, options: IInteractionOptions, useFinalPosition: boolean): InteractionItem[];
getSortedVisibleDatasetMetas(): IChartMeta[];
getDatasetMeta(datasetIndex: number): IChartMeta;
getVisibleDatasetCount(): number;
isDatasetVisible(datasetIndex: number): boolean;
setDatasetVisibility(datasetIndex: number, visible: boolean): void;
toggleDataVisibility(index: number): void;
getDataVisibility(index: number): boolean;
hide(datasetIndex: number): void;
show(datasetIndex: number): void;
getActiveElements(): ActiveElement[];
setActiveElements(active: ActiveDataPoint[]): void;
destroy(): void;
toBase64Image(type?: string, quality?: any): string;
bindEvents(): void;
unbindEvents(): void;
updateHoverStyle(items: Element, mode: 'dataset', enabled: boolean): void;
static readonly version: string;
static readonly instances: { [key: string]: Chart };
static readonly registry: Registry;
static getChart(key: string | CanvasRenderingContext2D | HTMLCanvasElement): Chart | undefined;
static register(...items: IChartComponentLike[]): void;
static unregister(...items: IChartComponentLike[]): void;
}
export declare type ChartItem =
| string
| CanvasRenderingContext2D
| OffscreenCanvasRenderingContext2D
| HTMLCanvasElement
| OffscreenCanvas
| { canvas: HTMLCanvasElement | OffscreenCanvas }
| ArrayLike<CanvasRenderingContext2D | HTMLCanvasElement | OffscreenCanvas>;
export declare enum UpdateModeEnum {
resize = 'resize',
reset = 'reset',
none = 'none',
hide = 'hide',
show = 'show',
normal = 'normal',
active = 'active'
}
export type UpdateMode = keyof typeof UpdateModeEnum;
export class DatasetController<E extends Element = Element, DSE extends Element = Element> {
constructor(chart: Chart, datasetIndex: number);
readonly chart: Chart;
readonly index: number;
readonly _cachedMeta: IChartMeta<E, DSE>;
enableOptionSharing: boolean;
linkScales(): void;
getAllParsedValues(scale: Scale): number[];
protected getLabelAndValue(index: number): { label: string; value: string };
updateElements(elements: E[], start: number, count: number, mode: UpdateMode): void;
update(mode: UpdateMode): void;
updateIndex(datasetIndex: number): void;
protected getMaxOverflow(): boolean | number;
draw(): void;
reset(): void;
getDataset(): IChartDataset;
getMeta(): IChartMeta<E, DSE>;
getScaleForId(scaleID: string): Scale | undefined;
configure(): void;
initialize(): void;
addElements(): void;
buildOrUpdateElements(): void;
getStyle(index: number, active: boolean): any;
protected resolveDatasetElementOptions(active: boolean): any;
protected resolveDataElementOptions(index: number, mode: UpdateMode): any;
/**
* Utility for checking if the options are shared and should be animated separately.
* @protected
*/
protected getSharedOptions(options: any): undefined | any;
/**
* Utility for determining if `options` should be included in the updated properties
* @protected
*/
protected includeOptions(mode: UpdateMode, sharedOptions: any): boolean;
/**
* Utility for updating an element with new properties, using animations when appropriate.
* @protected
*/
protected updateElement(element: E | DSE, index: number | undefined, properties: any, mode: UpdateMode): void;
/**
* Utility to animate the shared options, that are potentially affecting multiple elements.
* @protected
*/
protected updateSharedOptions(sharedOptions: any, mode: UpdateMode, newOptions: any): void;
removeHoverStyle(element: E, datasetIndex: number, index: number): void;
setHoverStyle(element: E, datasetIndex: number, index: number): void;
parse(start: number, count: number): void;
protected parsePrimitiveData(meta: IChartMeta<E, DSE>, data: any[], start: number, count: number): any[];
protected parseArrayData(meta: IChartMeta<E, DSE>, data: any[], start: number, count: number): any[];
protected parseObjectData(meta: IChartMeta<E, DSE>, data: any[], start: number, count: number): any[];
protected getParsed(index: number): any;
protected applyStack(scale: Scale, parsed: any[]): number;
protected updateRangeFromParsed(
range: { min: number; max: number },
scale: Scale,
parsed: any[],
stack: boolean
): void;
protected getMinMax(scale: Scale, canStack?: boolean): { min: number; max: number };
}
export interface IDatasetControllerChartComponent extends IChartComponent {
defaults: {
datasetElementType?: string | null | false;
dataElementType?: string | null | false;
dataElementOptions?: string[];
datasetElementOptions?: string[] | { [key: string]: string };
};
}
export interface Defaults {
readonly color: string;
readonly events: ('mousemove' | 'mouseout' | 'click' | 'touchstart' | 'touchmove')[];
readonly font: IFontSpec;
readonly interaction: {
mode: InteractionMode | string;
intersect: boolean;
};
readonly hover: {
onHover?: () => void;
mode?: InteractionMode | string;
intersect?: boolean;
};
readonly maintainAspectRatio: boolean;
readonly onClick?: () => void;
readonly onHover?: () => void;
readonly responsive: boolean;
readonly plugins: { [key: string]: any };
readonly scale?: IScaleOptions;
readonly doughnut: any;
readonly scales: { [key: string]: IScaleOptions };
readonly controllers: { [key: string]: any };
set(scope: string, values: any): any;
get(scope: string): any;
/**
* Routes the named defaults to fallback to another scope/name.
* This routing is useful when those target values, like defaults.color, are changed runtime.
* If the values would be copied, the runtime change would not take effect. By routing, the
* fallback is evaluated at each access, so its always up to date.
*
* Example:
*
* defaults.route('elements.arc', 'backgroundColor', '', 'color')
* - reads the backgroundColor from defaults.color when undefined locally
*
* @param scope Scope this route applies to.
* @param name Property name that should be routed to different namespace when not defined here.
* @param targetScope The namespace where those properties should be routed to.
* Empty string ('') is the root of defaults.
* @param targetName The target name in the target scope the property should be routed to.
*/
route(scope: string, name: string, targetScope: string, targetName: string): void;
}
export const defaults: Defaults;
export interface Element<T = {}, O = {}> {
readonly x: number;
readonly y: number;
readonly active: boolean;
readonly options: O;
tooltipPosition(useFinalPosition?: boolean): IPoint;
hasValue(): boolean;
getProps<P extends keyof T>(props: [P], final?: boolean): Pick<T, P>;
getProps<P extends keyof T, P2 extends keyof T>(props: [P, P2], final?: boolean): Pick<T, P | P2>;
getProps<P extends keyof T, P2 extends keyof T, P3 extends keyof T>(
props: [P, P2, P3],
final?: boolean
): Pick<T, P | P2 | P3>;
getProps<P extends keyof T, P2 extends keyof T, P3 extends keyof T, P4 extends keyof T>(
props: [P, P2, P3, P4],
final?: boolean
): Pick<T, P | P2 | P3 | P4>;
getProps<P extends keyof T, P2 extends keyof T, P3 extends keyof T, P4 extends keyof T, P5 extends keyof T>(
props: [P, P2, P3, P4, P5],
final?: boolean
): Pick<T, P | P2 | P3 | P4 | P5>;
getProps(props: (keyof T)[], final?: boolean): T;
}
export const Element: {
prototype: Element;
new <T = {}, O = {}>(): Element<T, O>;
};
export interface IInteractionOptions {
axis?: string;
intersect?: boolean;
}
export interface InteractionItem {
element: Element;
datasetIndex: number;
index: number;
}
export type InteractionModeFunction = (
chart: Chart,
e: IEvent,
options: IInteractionOptions,
useFinalPosition?: boolean
) => InteractionItem[];
export interface IInteractionMode {
/**
* Returns items at the same index. If the options.intersect parameter is true, we only return items if we intersect something
* If the options.intersect mode is false, we find the nearest item and return the items at the same index as that item
*/
index: InteractionModeFunction;
/**
* Returns items in the same dataset. If the options.intersect parameter is true, we only return items if we intersect something
* If the options.intersect is false, we find the nearest item and return the items in that dataset
*/
dataset: InteractionModeFunction;
/**
* Point mode returns all elements that hit test based on the event position
* of the event
*/
point: InteractionModeFunction;
/**
* nearest mode returns the element closest to the point
*/
nearest: InteractionModeFunction;
/**
* x mode returns the elements that hit-test at the current x coordinate
*/
x: InteractionModeFunction;
/**
* y mode returns the elements that hit-test at the current y coordinate
*/
y: InteractionModeFunction;
}
export type InteractionMode = keyof IInteractionMode;
export const Interaction: {
modes: IInteractionMode;
};
export type LayoutPosition = 'left' | 'top' | 'right' | 'chartArea';
export interface ILayoutItem {
/**
* The position of the item in the chart layout. Possible values are
*/
position: LayoutPosition;
/**
* The weight used to sort the item. Higher weights are further away from the chart area
*/
weight: number;
/**
* if true, and the item is horizontal, then push vertical boxes down
*/
fullWidth: boolean;
/**
* returns true if the layout item is horizontal (ie. top or bottom)
*/
isHorizontal(): boolean;
/**
* Takes two parameters: width and height. Returns size of item
* @param width
* @param height
*/
update(width: number, height: number): number;
/**
* Draws the element
*/
draw(): void;
/**
* Returns an object with padding on the edges
*/
getPadding?(): IChartArea;
/**
* Width of item. Must be valid after update()
*/
width: number;
/**
* Height of item. Must be valid after update()
*/
height: number;
/**
* Left edge of the item. Set by layout system and cannot be used in update
*/
left: number;
/**
* Top edge of the item. Set by layout system and cannot be used in update
*/
top: number;
/**
* Right edge of the item. Set by layout system and cannot be used in update
*/
right: number;
/**
* Bottom edge of the item. Set by layout system and cannot be used in update
*/
bottom: number;
}
export const layouts: {
/**
* Register a box to a chart.
* A box is simply a reference to an object that requires layout. eg. Scales, Legend, Title.
* @param {Chart} chart - the chart to use
* @param {ILayoutItem} item - the item to add to be laid out
*/
addBox(chart: Chart, item: ILayoutItem): void;
/**
* Remove a layoutItem from a chart
* @param {Chart} chart - the chart to remove the box from
* @param {ILayoutItem} layoutItem - the item to remove from the layout
*/
removeBox(chart: Chart, layoutItem: ILayoutItem): void;
/**
* Sets (or updates) options on the given `item`.
* @param {Chart} chart - the chart in which the item lives (or will be added to)
* @param {ILayoutItem} item - the item to configure with the given options
* @param options - the new item options.
*/
configure(
chart: Chart,
item: ILayoutItem,
options: { fullWidth?: number; position?: LayoutPosition; weight?: number }
): void;
/**
* Fits boxes of the given chart into the given size by having each box measure itself
* then running a fitting algorithm
* @param {Chart} chart - the chart
* @param {number} width - the width to fit into
* @param {number} height - the height to fit into
*/
update(chart: Chart, width: number, height: number): void;
};
export interface PluginService {
/**
* Calls enabled plugins for `chart` on the specified hook and with the given args.
* This method immediately returns as soon as a plugin explicitly returns false. The
* returned value can be used, for instance, to interrupt the current action.
* @param {Chart} chart - The chart instance for which plugins should be called.
* @param {string} hook - The name of the plugin method to call (e.g. 'beforeUpdate').
* @param {Array} [args] - Extra arguments to apply to the hook call.
* @returns {boolean} false if any of the plugins return false, else returns true.
*/
notify(chart: Chart, hook: string, args: any[]): boolean;
invalidate(): void;
}
export interface IPlugin<O = {}> {
id: string;
/**
* @desc Called before initializing `chart`.
* @param {Chart} chart - The chart instance.
* @param {object} options - The plugin options.
*/
beforeInit?(chart: Chart, options: O): void;
/**
* @desc Called after `chart` has been initialized and before the first update.
* @param {Chart} chart - The chart instance.
* @param {object} options - The plugin options.
*/
afterInit?(chart: Chart, options: O): void;
/**
* @desc Called before updating `chart`. If any plugin returns `false`, the update
* is cancelled (and thus subsequent render(s)) until another `update` is triggered.
* @param {Chart} chart - The chart instance.
* @param {object} options - The plugin options.
* @returns {boolean} `false` to cancel the chart update.
*/
beforeUpdate?(chart: Chart, args: { mode: UpdateMode }, options: O): boolean | void;
/**
* @desc Called after `chart` has been updated and before rendering. Note that this
* hook will not be called if the chart update has been previously cancelled.
* @param {Chart} chart - The chart instance.
* @param {object} options - The plugin options.
*/
afterUpdate?(chart: Chart, args: { mode: UpdateMode }, options: O): void;
/**
* @desc Called during chart reset
* @param {Chart} chart - The chart instance.
* @param {object} options - The plugin options.
* @since version 3.0.0
*/
reset?(chart: Chart, options: O): void;
/**
* @desc Called before updating the `chart` datasets. If any plugin returns `false`,
* the datasets update is cancelled until another `update` is triggered.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {UpdateMode} args.mode - The update mode.
* @param {object} options - The plugin options.
* @returns {boolean} false to cancel the datasets update.
* @since version 2.1.5
*/
beforeDatasetsUpdate?(chart: Chart, args: { mode: UpdateMode }, options: O): boolean | void;
/**
* @desc Called after the `chart` datasets have been updated. Note that this hook
* will not be called if the datasets update has been previously cancelled.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {UpdateMode} args.mode - The update mode.
* @param {object} options - The plugin options.
* @since version 2.1.5
*/
afterDatasetsUpdate?(chart: Chart, args: { mode: UpdateMode }, options: O): void;
/**
* @desc Called before updating the `chart` dataset at the given `args.index`. If any plugin
* returns `false`, the datasets update is cancelled until another `update` is triggered.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {number} args.index - The dataset index.
* @param {object} args.meta - The dataset metadata.
* @param {UpdateMode} args.mode - The update mode.
* @param {object} options - The plugin options.
* @returns {boolean} `false` to cancel the chart datasets drawing.
*/
beforeDatasetUpdate?(chart: Chart, args: { index: number; meta: IChartMeta, mode: UpdateMode }, options: O): boolean | void;
/**
* @desc Called after the `chart` datasets at the given `args.index` has been updated. Note
* that this hook will not be called if the datasets update has been previously cancelled.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {number} args.index - The dataset index.
* @param {object} args.meta - The dataset metadata.
* @param {UpdateMode} args.mode - The update mode.
* @param {object} options - The plugin options.
*/
afterDatasetUpdate?(chart: Chart, args: { index: number; meta: IChartMeta, mode: UpdateMode }, options: O): void;
/**
* @desc Called before laying out `chart`. If any plugin returns `false`,
* the layout update is cancelled until another `update` is triggered.
* @param {Chart} chart - The chart instance.
* @param {object} options - The plugin options.
* @returns {boolean} `false` to cancel the chart layout.
*/
beforeLayout?(chart: Chart, options: O): boolean | void;
/**
* @desc Called after the `chart` has been laid out. Note that this hook will not
* be called if the layout update has been previously cancelled.
* @param {Chart} chart - The chart instance.
* @param {object} options - The plugin options.
*/
afterLayout?(chart: Chart, options: O): void;
/**
* @desc Called before rendering `chart`. If any plugin returns `false`,
* the rendering is cancelled until another `render` is triggered.
* @param {Chart} chart - The chart instance.
* @param {object} options - The plugin options.
* @returns {boolean} `false` to cancel the chart rendering.
*/
beforeRender?(chart: Chart, options: O): boolean | void;
/**
* @desc Called after the `chart` has been fully rendered (and animation completed). Note
* that this hook will not be called if the rendering has been previously cancelled.
* @param {Chart} chart - The chart instance.
* @param {object} options - The plugin options.
*/
afterRender?(chart: Chart, options: O): void;
/**
* @desc Called before drawing `chart` at every animation frame. If any plugin returns `false`,
* the frame drawing is cancelled untilanother `render` is triggered.
* @param {Chart} chart - The chart instance.
* @param {object} options - The plugin options.
* @returns {boolean} `false` to cancel the chart drawing.
*/
beforeDraw?(chart: Chart, options: O): boolean | void;
/**
* @desc Called after the `chart` has been drawn. Note that this hook will not be called
* if the drawing has been previously cancelled.
* @param {Chart} chart - The chart instance.
* @param {object} options - The plugin options.
*/
afterDraw?(chart: Chart, options: O): void;
/**
* @desc Called before drawing the `chart` datasets. If any plugin returns `false`,
* the datasets drawing is cancelled until another `render` is triggered.
* @param {Chart} chart - The chart instance.
* @param {object} options - The plugin options.
* @returns {boolean} `false` to cancel the chart datasets drawing.
*/
beforeDatasetsDraw?(chart: Chart, options: O): boolean | void;
/**
* @desc Called after the `chart` datasets have been drawn. Note that this hook
* will not be called if the datasets drawing has been previously cancelled.
* @param {Chart} chart - The chart instance.
* @param {object} options - The plugin options.
*/
afterDatasetsDraw?(chart: Chart, options: O): void;
/**
* @desc Called before drawing the `chart` dataset at the given `args.index` (datasets
* are drawn in the reverse order). If any plugin returns `false`, the datasets drawing
* is cancelled until another `render` is triggered.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {number} args.index - The dataset index.
* @param {object} args.meta - The dataset metadata.
* @param {object} options - The plugin options.
* @returns {boolean} `false` to cancel the chart datasets drawing.
*/
beforeDatasetDraw?(chart: Chart, args: { index: number; meta: IChartMeta }, options: O): boolean | void;
/**
* @desc Called after the `chart` datasets at the given `args.index` have been drawn
* (datasets are drawn in the reverse order). Note that this hook will not be called
* if the datasets drawing has been previously cancelled.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {number} args.index - The dataset index.
* @param {object} args.meta - The dataset metadata.
* @param {object} options - The plugin options.
*/
afterDatasetDraw?(chart: Chart, args: { index: number; meta: IChartMeta }, options: O): void;
/**
* @desc Called before processing the specified `event`. If any plugin returns `false`,
* the event will be discarded.
* @param {Chart} chart - The chart instance.
* @param {IEvent} event - The event object.
* @param {object} options - The plugin options.
* @param {boolean} replay - True if this event is replayed from `Chart.update`
*/
beforeEvent?(chart: Chart, event: IEvent, options: O, replay: boolean): void;
/**
* @desc Called after the `event` has been consumed. Note that this hook
* will not be called if the `event` has been previously discarded.
* @param {Chart} chart - The chart instance.
* @param {IEvent} event - The event object.
* @param {object} options - The plugin options.
* @param {boolean} replay - True if this event is replayed from `Chart.update`
*/
afterEvent?(chart: Chart, event: IEvent, options: O, replay: boolean): void;
/**
* @desc Called after the chart as been resized.
* @param {Chart} chart - The chart instance.
* @param {number} size - The new canvas display size (eq. canvas.style width & height).
* @param {object} options - The plugin options.
*/
resize?(chart: Chart, size: number, options: O): void;
/**
* Called after the chart as been destroyed.
* @param {Chart} chart - The chart instance.
* @param {object} options - The plugin options.
*/
destroy?(chart: Chart, options: O): void;
}
export declare type IChartComponentLike = IChartComponent | IChartComponent[] | { [key: string]: IChartComponent };
/**
* Please use the module's default export which provides a singleton instance
* Note: class is exported for typedoc
*/
export interface Registry {
readonly controllers: TypedRegistry<DatasetController>;
readonly elements: TypedRegistry<Element>;
readonly plugins: TypedRegistry<IPlugin>;
readonly scales: TypedRegistry<Scale>;
add(...args: IChartComponentLike[]): void;
remove(...args: IChartComponentLike[]): void;
addControllers(...args: IChartComponentLike[]): void;
addElements(...args: IChartComponentLike[]): void;
addPlugins(...args: IChartComponentLike[]): void;
addScales(...args: IChartComponentLike[]): void;
getController(id: string): DatasetController | undefined;
getElement(id: string): Element | undefined;
getPlugin(id: string): IPlugin | undefined;
getScale(id: string): Scale | undefined;
}
export const registry: Registry;
export interface ITick {
value: number;
label?: string;
major?: boolean;
}
export interface ICoreScaleOptions {
/**
* Controls the axis global visibility (visible when true, hidden when false). When display: 'auto', the axis is visible only if at least one associated dataset is visible.
* @default true
*/
display: boolean | 'auto';
/**
* Reverse the scale.
* @default false
*/
reverse: boolean;
/**
* The weight used to sort the axis. Higher weights are further away from the chart area.
* @default true
*/
weight: number;
/**
* Callback called before the update process starts.
*/
beforeUpdate(axis: Scale): void;
/**
* Callback that runs before dimensions are set.
*/
beforeSetDimensions(axis: Scale): void;
/**
* Callback that runs after dimensions are set.
*/
afterSetDimensions(axis: Scale): void;
/**
* Callback that runs before data limits are determined.
*/
beforeDataLimits(axis: Scale): void;
/**
* Callback that runs after data limits are determined.
*/
afterDataLimits(axis: Scale): void;
/**
* Callback that runs before ticks are created.
*/
beforeBuildTicks(axis: Scale): void;
/**
* Callback that runs after ticks are created. Useful for filtering ticks.
*/
afterBuildTicks(axis: Scale): void;
/**
* Callback that runs before ticks are converted into strings.
*/
beforeTickToLabelConversion(axis: Scale): void;
/**
* Callback that runs after ticks are converted into strings.
*/
afterTickToLabelConversion(axis: Scale): void;
/**
* Callback that runs before tick rotation is determined.
*/
beforeCalculateTickRotation(axis: Scale): void;
/**
* Callback that runs after tick rotation is determined.
*/
afterCalculateTickRotation(axis: Scale): void;
/**
* Callback that runs before the scale fits to the canvas.
*/
beforeFit(axis: Scale): void;
/**
* Callback that runs after the scale fits to the canvas.
*/
afterFit(axis: Scale): void;
/**
* Callback that runs at the end of the update process.
*/
afterUpdate(axis: Scale): void;
}
export interface Scale<O extends ICoreScaleOptions = ICoreScaleOptions> extends Element<{}, O>, IChartArea {
readonly id: string;
readonly type: string;
readonly ctx: CanvasRenderingContext2D;
readonly chart: Chart;
width: number;
height: number;
maxWidth: number;
maxHeight: number;
paddingTop: number;
paddingBottom: number;
paddingLeft: number;
paddingRight: number;
axis: string;
labelRotation: number;
min: number;
max: number;
ticks: ITick[];
getMatchingVisibleMetas(type?: string): IChartMeta[];
draw(chartArea: IChartArea): void;
drawTitle(chartArea: IChartArea): void;
drawLabels(chartArea: IChartArea): void;
drawGrid(chartArea: IChartArea): void;
/**
* @param {number} pixel
* @return {number}
*/
getDecimalForPixel(pixel: number): number;