-
Notifications
You must be signed in to change notification settings - Fork 11.9k
/
index.d.ts
3678 lines (3286 loc) · 111 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
/* eslint-disable @typescript-eslint/ban-types */
import {DeepPartial, DistributiveArray, UnionToIntersection} from './utils.js';
import {TimeUnit} from '../core/core.adapters.js';
import PointElement from '../elements/element.point.js';
import {EasingFunction} from '../helpers/helpers.easing.js';
import {AnimationEvent} from './animation.js';
import {AnyObject, EmptyObject} from './basic.js';
import {Color} from './color.js';
import Element from '../core/core.element.js';
import {ChartArea, Padding, Point} from './geometric.js';
import {LayoutItem, LayoutPosition} from './layout.js';
import {RenderTextOpts} from './helpers/helpers.canvas.js';
import {CanvasFontSpec} from '../helpers/helpers.options.js';
import type {ColorsPluginOptions} from '../plugins/plugin.colors.js';
export {EasingFunction} from '../helpers/helpers.easing.js';
export {default as ArcElement, ArcProps} from '../elements/element.arc.js';
export {default as PointElement, PointProps} from '../elements/element.point.js';
export {Animation, Animations, Animator, AnimationEvent} from './animation.js';
export {Color} from './color.js';
export {ChartArea, Point} from './geometric.js';
export {LayoutItem, LayoutPosition} from './layout.js';
export interface ScriptableContext<TType extends ChartType> {
active: boolean;
chart: Chart;
dataIndex: number;
dataset: UnionToIntersection<ChartDataset<TType>>;
datasetIndex: number;
type: string;
mode: string;
parsed: UnionToIntersection<ParsedDataType<TType>>;
raw: unknown;
}
export interface ScriptableLineSegmentContext {
type: 'segment',
p0: PointElement,
p1: PointElement,
p0DataIndex: number,
p1DataIndex: number,
datasetIndex: number
}
export type Scriptable<T, TContext> = T | ((ctx: TContext, options: AnyObject) => T | undefined);
export type ScriptableOptions<T, TContext> = { [P in keyof T]: Scriptable<T[P], TContext> };
export type ScriptableAndScriptableOptions<T, TContext> = Scriptable<T, TContext> | ScriptableOptions<T, TContext>;
export type ScriptableAndArray<T, TContext> = readonly T[] | Scriptable<T, TContext>;
export type ScriptableAndArrayOptions<T, TContext> = { [P in keyof T]: ScriptableAndArray<T[P], TContext> };
export interface ParsingOptions {
/**
* How to parse the dataset. The parsing can be disabled by specifying parsing: false at chart options or dataset. If parsing is disabled, data must be sorted and in the formats the associated chart type and scales use internally.
*/
parsing:
{
[key: string]: string;
}
| false;
/**
* Chart.js is fastest if you provide data with indices that are unique, sorted, and consistent across datasets and provide the normalized: true option to let Chart.js know that you have done so.
*/
normalized: boolean;
}
export interface ControllerDatasetOptions extends ParsingOptions {
/**
* The base axis of the chart. 'x' for vertical charts and 'y' for horizontal charts.
* @default 'x'
*/
indexAxis: 'x' | 'y';
/**
* How to clip relative to chartArea. Positive value allows overflow, negative value clips that many pixels inside chartArea. 0 = clip at chartArea. Clipping can also be configured per side: `clip: {left: 5, top: false, right: -2, bottom: 0}`
*/
clip: number | ChartArea | false;
/**
* The label for the dataset which appears in the legend and tooltips.
*/
label: string;
/**
* The drawing order of dataset. Also affects order for stacking, tooltip and legend.
*/
order: number;
/**
* The ID of the group to which this dataset belongs to (when stacked, each group will be a separate stack).
*/
stack: string;
/**
* Configures the visibility state of the dataset. Set it to true, to hide the dataset from the chart.
* @default false
*/
hidden: boolean;
}
export interface BarControllerDatasetOptions
extends ControllerDatasetOptions,
ScriptableAndArrayOptions<BarOptions, ScriptableContext<'bar'>>,
ScriptableAndArrayOptions<CommonHoverOptions, ScriptableContext<'bar'>>,
AnimationOptions<'bar'> {
/**
* The ID of the x axis to plot this dataset on.
*/
xAxisID: string;
/**
* The ID of the y axis to plot this dataset on.
*/
yAxisID: string;
/**
* Percent (0-1) of the available width each bar should be within the category width. 1.0 will take the whole category width and put the bars right next to each other.
* @default 0.9
*/
barPercentage: number;
/**
* Percent (0-1) of the available width each category should be within the sample width.
* @default 0.8
*/
categoryPercentage: number;
/**
* Manually set width of each bar in pixels. If set to 'flex', it computes "optimal" sample widths that globally arrange bars side by side. If not set (default), bars are equally sized based on the smallest interval.
*/
barThickness: number | 'flex';
/**
* Set this to ensure that bars are not sized thicker than this.
*/
maxBarThickness: number;
/**
* Set this to ensure that bars have a minimum length in pixels.
*/
minBarLength: number;
/**
* Point style for the legend
* @default 'circle;
*/
pointStyle: PointStyle;
/**
* Should the bars be grouped on index axis
* @default true
*/
grouped: boolean;
}
export interface BarControllerChartOptions {
/**
* Should null or undefined values be omitted from drawing
*/
skipNull?: boolean;
}
export type BarController = DatasetController
export declare const BarController: ChartComponent & {
prototype: BarController;
new (chart: Chart, datasetIndex: number): BarController;
};
export interface BubbleControllerDatasetOptions
extends ControllerDatasetOptions,
ScriptableAndArrayOptions<PointOptions, ScriptableContext<'bubble'>>,
ScriptableAndArrayOptions<PointHoverOptions, ScriptableContext<'bubble'>> {
/**
* The ID of the x axis to plot this dataset on.
*/
xAxisID: string;
/**
* The ID of the y axis to plot this dataset on.
*/
yAxisID: string;
}
export interface BubbleDataPoint extends Point {
/**
* Bubble radius in pixels (not scaled).
*/
r: number;
}
export type BubbleController = DatasetController
export declare const BubbleController: ChartComponent & {
prototype: BubbleController;
new (chart: Chart, datasetIndex: number): BubbleController;
};
export interface LineControllerDatasetOptions
extends ControllerDatasetOptions,
ScriptableAndArrayOptions<PointPrefixedOptions, ScriptableContext<'line'>>,
ScriptableAndArrayOptions<PointPrefixedHoverOptions, ScriptableContext<'line'>>,
ScriptableOptions<Omit<LineOptions, keyof CommonElementOptions>, ScriptableContext<'line'>>,
ScriptableAndArrayOptions<CommonElementOptions, ScriptableContext<'line'>>,
ScriptableOptions<Omit<LineHoverOptions, keyof CommonHoverOptions>, ScriptableContext<'line'>>,
ScriptableAndArrayOptions<CommonHoverOptions, ScriptableContext<'line'>>,
AnimationOptions<'line'> {
/**
* The ID of the x axis to plot this dataset on.
*/
xAxisID: string;
/**
* The ID of the y axis to plot this dataset on.
*/
yAxisID: string;
/**
* If true, lines will be drawn between points with no or null data. If false, points with NaN data will create a break in the line. Can also be a number specifying the maximum gap length to span. The unit of the value depends on the scale used.
* @default false
*/
spanGaps: boolean | number;
showLine: boolean;
}
export interface LineControllerChartOptions {
/**
* If true, lines will be drawn between points with no or null data. If false, points with NaN data will create a break in the line. Can also be a number specifying the maximum gap length to span. The unit of the value depends on the scale used.
* @default false
*/
spanGaps: boolean | number;
/**
* If false, the lines between points are not drawn.
* @default true
*/
showLine: boolean;
}
export type LineController = DatasetController
export declare const LineController: ChartComponent & {
prototype: LineController;
new (chart: Chart, datasetIndex: number): LineController;
};
export type ScatterControllerDatasetOptions = LineControllerDatasetOptions;
export type ScatterDataPoint = Point
export type ScatterControllerChartOptions = LineControllerChartOptions;
export type ScatterController = LineController
export declare const ScatterController: ChartComponent & {
prototype: ScatterController;
new (chart: Chart, datasetIndex: number): ScatterController;
};
export interface DoughnutControllerDatasetOptions
extends ControllerDatasetOptions,
ScriptableAndArrayOptions<ArcOptions, ScriptableContext<'doughnut'>>,
ScriptableAndArrayOptions<ArcHoverOptions, ScriptableContext<'doughnut'>>,
AnimationOptions<'doughnut'> {
/**
* Sweep to allow arcs to cover.
* @default 360
*/
circumference: number;
/**
* Arc offset (in pixels).
*/
offset: number | number[];
/**
* Starting angle to draw this dataset from.
* @default 0
*/
rotation: number;
/**
* The relative thickness of the dataset. Providing a value for weight will cause the pie or doughnut dataset to be drawn with a thickness relative to the sum of all the dataset weight values.
* @default 1
*/
weight: number;
/**
* Similar to the `offset` option, but applies to all arcs. This can be used to to add spaces
* between arcs
* @default 0
*/
spacing: number;
}
export interface DoughnutAnimationOptions {
/**
* If true, the chart will animate in with a rotation animation. This property is in the options.animation object.
* @default true
*/
animateRotate: boolean;
/**
* If true, will animate scaling the chart from the center outwards.
* @default false
*/
animateScale: boolean;
}
export interface DoughnutControllerChartOptions {
/**
* Sweep to allow arcs to cover.
* @default 360
*/
circumference: number;
/**
* The portion of the chart that is cut out of the middle. ('50%' - for doughnut, 0 - for pie)
* String ending with '%' means percentage, number means pixels.
* @default 50
*/
cutout: Scriptable<number | string, ScriptableContext<'doughnut'>>;
/**
* Arc offset (in pixels).
*/
offset: number | number[];
/**
* The outer radius of the chart. String ending with '%' means percentage of maximum radius, number means pixels.
* @default '100%'
*/
radius: Scriptable<number | string, ScriptableContext<'doughnut'>>;
/**
* Starting angle to draw arcs from.
* @default 0
*/
rotation: number;
/**
* Spacing between the arcs
* @default 0
*/
spacing: number;
animation: false | DoughnutAnimationOptions;
}
export type DoughnutDataPoint = number;
export interface DoughnutController extends DatasetController {
readonly innerRadius: number;
readonly outerRadius: number;
readonly offsetX: number;
readonly offsetY: number;
calculateTotal(): number;
calculateCircumference(value: number): number;
}
export declare const DoughnutController: ChartComponent & {
prototype: DoughnutController;
new (chart: Chart, datasetIndex: number): DoughnutController;
};
export interface DoughnutMetaExtensions {
total: number;
}
export type PieControllerDatasetOptions = DoughnutControllerDatasetOptions;
export type PieControllerChartOptions = DoughnutControllerChartOptions;
export type PieAnimationOptions = DoughnutAnimationOptions;
export type PieDataPoint = DoughnutDataPoint;
export type PieMetaExtensions = DoughnutMetaExtensions;
export type PieController = DoughnutController
export declare const PieController: ChartComponent & {
prototype: PieController;
new (chart: Chart, datasetIndex: number): PieController;
};
export interface PolarAreaControllerDatasetOptions extends DoughnutControllerDatasetOptions {
/**
* Arc angle to cover. - for polar only
* @default circumference / (arc count)
*/
angle: number;
}
export type PolarAreaAnimationOptions = DoughnutAnimationOptions;
export interface PolarAreaControllerChartOptions {
/**
* Starting angle to draw arcs for the first item in a dataset. In degrees, 0 is at top.
* @default 0
*/
startAngle: number;
animation: false | PolarAreaAnimationOptions;
}
export interface PolarAreaController extends DoughnutController {
countVisibleElements(): number;
}
export declare const PolarAreaController: ChartComponent & {
prototype: PolarAreaController;
new (chart: Chart, datasetIndex: number): PolarAreaController;
};
export interface RadarControllerDatasetOptions
extends ControllerDatasetOptions,
ScriptableAndArrayOptions<PointOptions & PointHoverOptions & PointPrefixedOptions & PointPrefixedHoverOptions, ScriptableContext<'radar'>>,
ScriptableAndArrayOptions<LineOptions & LineHoverOptions, ScriptableContext<'radar'>>,
AnimationOptions<'radar'> {
/**
* The ID of the x axis to plot this dataset on.
*/
xAxisID: string;
/**
* The ID of the y axis to plot this dataset on.
*/
yAxisID: string;
/**
* If true, lines will be drawn between points with no or null data. If false, points with NaN data will create a break in the line. Can also be a number specifying the maximum gap length to span. The unit of the value depends on the scale used.
*/
spanGaps: boolean | number;
/**
* If false, the line is not drawn for this dataset.
*/
showLine: boolean;
}
export type RadarControllerChartOptions = LineControllerChartOptions;
export type RadarController = DatasetController
export declare const RadarController: ChartComponent & {
prototype: RadarController;
new (chart: Chart, datasetIndex: number): RadarController;
};
interface ChartMetaCommon<TElement extends Element = Element, TDatasetElement extends Element = Element> {
type: string;
controller: DatasetController;
order: number;
label: string;
index: number;
visible: boolean;
stack: number;
indexAxis: 'x' | 'y';
data: TElement[];
dataset?: TDatasetElement;
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 | 'single';
_parsed: unknown[];
}
export type ChartMeta<
TType extends ChartType = ChartType,
TElement extends Element = Element,
TDatasetElement extends Element = Element,
> = DeepPartial<
{ [key in ChartType]: ChartTypeRegistry[key]['metaExtensions'] }[TType]
> & ChartMetaCommon<TElement, TDatasetElement>;
export interface ActiveDataPoint {
datasetIndex: number;
index: number;
}
export interface ActiveElement extends ActiveDataPoint {
element: Element;
}
export declare class Chart<
TType extends ChartType = ChartType,
TData = DefaultDataPoint<TType>,
TLabel = unknown
> {
readonly platform: BasePlatform;
readonly id: string;
readonly canvas: HTMLCanvasElement;
readonly ctx: CanvasRenderingContext2D;
readonly config: ChartConfiguration<TType, TData, TLabel> | ChartConfigurationCustomTypesPerDataset<TType, TData, TLabel>;
readonly width: number;
readonly height: number;
readonly aspectRatio: number;
readonly boxes: LayoutItem[];
readonly currentDevicePixelRatio: number;
readonly chartArea: ChartArea;
readonly scales: { [key: string]: Scale };
readonly attached: boolean;
readonly legend?: LegendElement<TType>; // Only available if legend plugin is registered and enabled
readonly tooltip?: TooltipModel<TType>; // Only available if tooltip plugin is registered and enabled
data: ChartData<TType, TData, TLabel>;
options: ChartOptions<TType>;
constructor(item: ChartItem, config: ChartConfiguration<TType, TData, TLabel> | ChartConfigurationCustomTypesPerDataset<TType, TData, TLabel>);
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;
isPointInArea(point: Point): boolean;
getElementsAtEventForMode(e: Event, mode: string, options: InteractionOptions, useFinalPosition: boolean): InteractionItem[];
getSortedVisibleDatasetMetas(): ChartMeta[];
getDatasetMeta(datasetIndex: number): ChartMeta;
getVisibleDatasetCount(): number;
isDatasetVisible(datasetIndex: number): boolean;
setDatasetVisibility(datasetIndex: number, visible: boolean): void;
toggleDataVisibility(index: number): void;
getDataVisibility(index: number): boolean;
hide(datasetIndex: number, dataIndex?: number): void;
show(datasetIndex: number, dataIndex?: number): void;
getActiveElements(): ActiveElement[];
setActiveElements(active: ActiveDataPoint[]): void;
destroy(): void;
toBase64Image(type?: string, quality?: unknown): string;
bindEvents(): void;
unbindEvents(): void;
updateHoverStyle(items: InteractionItem[], mode: 'dataset', enabled: boolean): void;
notifyPlugins(hook: string, args?: AnyObject): boolean | void;
isPluginEnabled(pluginId: string): boolean;
static readonly defaults: Defaults;
static readonly overrides: Overrides;
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: ChartComponentLike[]): void;
static unregister(...items: ChartComponentLike[]): void;
}
export declare const registerables: readonly ChartComponentLike[];
export declare type ChartItem =
| string
| CanvasRenderingContext2D
| HTMLCanvasElement
| { canvas: HTMLCanvasElement }
| ArrayLike<CanvasRenderingContext2D | HTMLCanvasElement>;
export declare enum UpdateModeEnum {
resize = 'resize',
reset = 'reset',
none = 'none',
hide = 'hide',
show = 'show',
default = 'default',
active = 'active'
}
export type UpdateMode = keyof typeof UpdateModeEnum;
export declare class DatasetController<
TType extends ChartType = ChartType,
TElement extends Element = Element,
TDatasetElement extends Element = Element,
TParsedData = ParsedDataType<TType>,
> {
constructor(chart: Chart, datasetIndex: number);
readonly chart: Chart;
readonly index: number;
readonly _cachedMeta: ChartMeta<TType, TElement, TDatasetElement>;
enableOptionSharing: boolean;
// If true, the controller supports the decimation
// plugin. Defaults to `false` for all controllers
// except the LineController
supportsDecimation: boolean;
linkScales(): void;
getAllParsedValues(scale: Scale): number[];
protected getLabelAndValue(index: number): { label: string; value: string };
updateElements(elements: TElement[], start: number, count: number, mode: UpdateMode): void;
update(mode: UpdateMode): void;
updateIndex(datasetIndex: number): void;
protected getMaxOverflow(): boolean | number;
draw(): void;
reset(): void;
getDataset(): ChartDataset;
getMeta(): ChartMeta<TType, TElement, TDatasetElement>;
getScaleForId(scaleID: string): Scale | undefined;
configure(): void;
initialize(): void;
addElements(): void;
buildOrUpdateElements(resetNewElements?: boolean): void;
getStyle(index: number, active: boolean): AnyObject;
protected resolveDatasetElementOptions(mode: UpdateMode): AnyObject;
protected resolveDataElementOptions(index: number, mode: UpdateMode): AnyObject;
/**
* Utility for checking if the options are shared and should be animated separately.
* @protected
*/
protected getSharedOptions(options: AnyObject): undefined | AnyObject;
/**
* Utility for determining if `options` should be included in the updated properties
* @protected
*/
protected includeOptions(mode: UpdateMode, sharedOptions: AnyObject): boolean;
/**
* Utility for updating an element with new properties, using animations when appropriate.
* @protected
*/
protected updateElement(element: TElement | TDatasetElement, index: number | undefined, properties: AnyObject, mode: UpdateMode): void;
/**
* Utility to animate the shared options, that are potentially affecting multiple elements.
* @protected
*/
protected updateSharedOptions(sharedOptions: AnyObject, mode: UpdateMode, newOptions: AnyObject): void;
removeHoverStyle(element: TElement, datasetIndex: number, index: number): void;
setHoverStyle(element: TElement, datasetIndex: number, index: number): void;
parse(start: number, count: number): void;
protected parsePrimitiveData(meta: ChartMeta<TType, TElement, TDatasetElement>, data: AnyObject[], start: number, count: number): AnyObject[];
protected parseArrayData(meta: ChartMeta<TType, TElement, TDatasetElement>, data: AnyObject[], start: number, count: number): AnyObject[];
protected parseObjectData(meta: ChartMeta<TType, TElement, TDatasetElement>, data: AnyObject[], start: number, count: number): AnyObject[];
protected getParsed(index: number): TParsedData;
protected applyStack(scale: Scale, parsed: unknown[]): number;
protected updateRangeFromParsed(
range: { min: number; max: number },
scale: Scale,
parsed: unknown[],
stack: boolean | string
): void;
protected getMinMax(scale: Scale, canStack?: boolean): { min: number; max: number };
}
export interface DatasetControllerChartComponent extends ChartComponent {
defaults: {
datasetElementType?: string | null | false;
dataElementType?: string | null | false;
};
}
export interface Defaults extends CoreChartOptions<ChartType>, ElementChartOptions<ChartType>, PluginChartOptions<ChartType> {
scale: ScaleOptionsByType;
scales: {
[key in ScaleType]: ScaleOptionsByType<key>;
};
set(values: AnyObject): AnyObject;
set(scope: string, values: AnyObject): AnyObject;
get(scope: string): AnyObject;
describe(scope: string, values: AnyObject): AnyObject;
override(scope: string, values: AnyObject): AnyObject;
/**
* 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 type Overrides = {
[key in ChartType]:
CoreChartOptions<key> &
ElementChartOptions<key> &
PluginChartOptions<key> &
DatasetChartOptions<ChartType> &
ScaleChartOptions<key> &
ChartTypeRegistry[key]['chartOptions'];
}
export declare const defaults: Defaults;
export interface InteractionOptions {
axis?: string;
intersect?: boolean;
includeInvisible?: boolean;
}
export interface InteractionItem {
element: Element;
datasetIndex: number;
index: number;
}
export type InteractionModeFunction = (
chart: Chart,
e: ChartEvent,
options: InteractionOptions,
useFinalPosition?: boolean
) => InteractionItem[];
export interface InteractionModeMap {
/**
* 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 InteractionModeMap;
export declare const Interaction: {
modes: InteractionModeMap;
/**
* Helper function to select candidate elements for interaction
*/
evaluateInteractionItems(
chart: Chart,
axis: InteractionAxis,
position: Point,
handler: (element: Element & VisualElement, datasetIndex: number, index: number) => void,
intersect?: boolean
): InteractionItem[];
};
export declare 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 {LayoutItem} item - the item to add to be laid out
*/
addBox(chart: Chart, item: LayoutItem): void;
/**
* Remove a layoutItem from a chart
* @param {Chart} chart - the chart to remove the box from
* @param {LayoutItem} layoutItem - the item to remove from the layout
*/
removeBox(chart: Chart, layoutItem: LayoutItem): 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 {LayoutItem} item - the item to configure with the given options
* @param options - the new item options.
*/
configure(
chart: Chart,
item: LayoutItem,
options: { fullSize?: 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 Plugin<TType extends ChartType = ChartType, O = AnyObject> extends ExtendedPlugin<TType, O> {
id: string;
/**
* @desc Called when plugin is installed for this chart instance. This hook is also invoked for disabled plugins (options === false).
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {object} options - The plugin options.
* @since 3.0.0
*/
install?(chart: Chart, args: EmptyObject, options: O): void;
/**
* @desc Called when a plugin is starting. This happens when chart is created or plugin is enabled.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {object} options - The plugin options.
* @since 3.0.0
*/
start?(chart: Chart, args: EmptyObject, options: O): void;
/**
* @desc Called when a plugin stopping. This happens when chart is destroyed or plugin is disabled.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {object} options - The plugin options.
* @since 3.0.0
*/
stop?(chart: Chart, args: EmptyObject, options: O): void;
/**
* @desc Called before initializing `chart`.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {object} options - The plugin options.
*/
beforeInit?(chart: Chart, args: EmptyObject, options: O): void;
/**
* @desc Called after `chart` has been initialized and before the first update.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {object} options - The plugin options.
*/
afterInit?(chart: Chart, args: EmptyObject, 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} args - The call arguments.
* @param {UpdateMode} args.mode - The update mode
* @param {object} options - The plugin options.
* @returns {boolean} `false` to cancel the chart update.
*/
beforeUpdate?(chart: Chart, args: { mode: UpdateMode, cancelable: true }, 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} args - The call arguments.
* @param {UpdateMode} args.mode - The update mode
* @param {object} options - The plugin options.
*/
afterUpdate?(chart: Chart, args: { mode: UpdateMode }, options: O): void;
/**
* @desc Called during the update process, before any chart elements have been created.
* This can be used for data decimation by changing the data array inside a dataset.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {object} options - The plugin options.
*/
beforeElementsUpdate?(chart: Chart, args: EmptyObject, options: O): void;
/**
* @desc Called during chart reset
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {object} options - The plugin options.
* @since version 3.0.0
*/
reset?(chart: Chart, args: EmptyObject, 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, cancelable: true }, 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: ChartMeta, mode: UpdateMode, cancelable: true }, 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: ChartMeta, mode: UpdateMode, cancelable: false }, 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} args - The call arguments.
* @param {object} options - The plugin options.
* @returns {boolean} `false` to cancel the chart layout.
*/
beforeLayout?(chart: Chart, args: { cancelable: true }, options: O): boolean | void;
/**
* @desc Called before scale data limits are calculated. This hook is called separately for each scale in the chart.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {Scale} args.scale - The scale.
* @param {object} options - The plugin options.
*/
beforeDataLimits?(chart: Chart, args: { scale: Scale }, options: O): void;
/**
* @desc Called after scale data limits are calculated. This hook is called separately for each scale in the chart.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {Scale} args.scale - The scale.
* @param {object} options - The plugin options.
*/
afterDataLimits?(chart: Chart, args: { scale: Scale }, options: O): void;
/**
* @desc Called before scale builds its ticks. This hook is called separately for each scale in the chart.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {Scale} args.scale - The scale.
* @param {object} options - The plugin options.
*/
beforeBuildTicks?(chart: Chart, args: { scale: Scale }, options: O): void;
/**
* @desc Called after scale has build its ticks. This hook is called separately for each scale in the chart.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {Scale} args.scale - The scale.
* @param {object} options - The plugin options.
*/
afterBuildTicks?(chart: Chart, args: { scale: Scale }, options: O): 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} args - The call arguments.
* @param {object} options - The plugin options.
*/
afterLayout?(chart: Chart, args: EmptyObject, 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} args - The call arguments.
* @param {object} options - The plugin options.
* @returns {boolean} `false` to cancel the chart rendering.
*/
beforeRender?(chart: Chart, args: { cancelable: true }, 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} args - The call arguments.
* @param {object} options - The plugin options.
*/