mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 12:19:08 +02:00
Improve types (#7767)
* interfaces.d: added plugins for the chart configuration * index.d: allow to set data * index.d: improve type for the update method * interfaces.d: improve type of generic chart type * interfaces.d: alphabetical sort * index.d: set fields in alphabetical sort * interfaces.d: remove custom type (string) * core/index.d: import "chart type" type * interfaces.d: added extends for TYPE * interfaces.d: move chart types to enum * core/index.d: move the update mode to enum Co-authored-by: Sergey Khomushin <sergey@placer.io>
This commit is contained in:
parent
fd34e786ab
commit
1ec6f1da71
22
types/core/index.d.ts
vendored
22
types/core/index.d.ts
vendored
@ -10,7 +10,7 @@ import {
|
||||
TimeUnit,
|
||||
IEvent,
|
||||
} from './interfaces';
|
||||
import { IChartDataset, IChartConfiguration, ConfigurationOptions, ConfigurationData } from '../interfaces';
|
||||
import { IChartDataset, IChartConfiguration, ConfigurationOptions, ConfigurationData, IChartType } from '../interfaces';
|
||||
|
||||
export interface IDateAdapter {
|
||||
/**
|
||||
@ -235,7 +235,7 @@ export interface IParsingOptions {
|
||||
export interface Chart<
|
||||
T = unknown,
|
||||
L = string,
|
||||
C extends IChartConfiguration<string, T, L> = IChartConfiguration<string, T, L>
|
||||
C extends IChartConfiguration<IChartType, T, L> = IChartConfiguration<IChartType, T, L>
|
||||
> {
|
||||
readonly platform: BasePlatform;
|
||||
readonly id: string;
|
||||
@ -248,11 +248,11 @@ export interface Chart<
|
||||
readonly boxes: ILayoutItem[];
|
||||
readonly currentDevicePixelRatio: number;
|
||||
readonly chartArea: IChartArea;
|
||||
readonly data: ConfigurationData<C>;
|
||||
readonly scales: { [key: string]: Scale };
|
||||
readonly scale: Scale | undefined;
|
||||
readonly attached: boolean;
|
||||
|
||||
data: ConfigurationData<C>;
|
||||
options: ConfigurationOptions<C>;
|
||||
|
||||
clear(): this;
|
||||
@ -263,7 +263,7 @@ export interface Chart<
|
||||
buildOrUpdateScales(): void;
|
||||
buildOrUpdateControllers(): void;
|
||||
reset(): void;
|
||||
update(mode?: string): void;
|
||||
update(mode?: UpdateMode): void;
|
||||
render(): void;
|
||||
draw(): void;
|
||||
|
||||
@ -301,7 +301,7 @@ export declare type ChartItem =
|
||||
|
||||
export const Chart: {
|
||||
prototype: Chart;
|
||||
new <T = unknown, L = string, C extends IChartConfiguration<string, T, L> = IChartConfiguration<string, T, L>>(
|
||||
new <T = unknown, L = string, C extends IChartConfiguration<IChartType, T, L> = IChartConfiguration<IChartType, T, L>>(
|
||||
item: ChartItem,
|
||||
config: C
|
||||
): Chart<T, L, C>;
|
||||
@ -313,7 +313,17 @@ export const Chart: {
|
||||
unregister(...items: IChartComponentLike[]): void;
|
||||
};
|
||||
|
||||
export type UpdateMode = 'resize' | 'reset' | 'none' | 'hide' | 'show' | 'normal' | 'active' | undefined;
|
||||
export 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);
|
||||
|
24
types/interfaces.d.ts
vendored
24
types/interfaces.d.ts
vendored
@ -28,7 +28,7 @@ import {
|
||||
ILegendChartOptions,
|
||||
ITitleChartOptions,
|
||||
} from './plugins';
|
||||
import { IChartAnimationOptions, IParsingOptions } from './core';
|
||||
import { IChartAnimationOptions, IParsingOptions, IPlugin } from './core';
|
||||
import { IScaleChartOptions } from './scales';
|
||||
|
||||
export type DeepPartial<T> = T extends {}
|
||||
@ -71,8 +71,21 @@ export type IChartOptions<O = {}> = DeepPartial<
|
||||
O
|
||||
>;
|
||||
|
||||
export enum ChartTypeEnum {
|
||||
bar = 'bar',
|
||||
bubble = 'bubble',
|
||||
doughnut = 'doughnut',
|
||||
line = 'line',
|
||||
pie = 'pie',
|
||||
polarArea = 'polarArea',
|
||||
radar = 'radar',
|
||||
scatter = 'scatter',
|
||||
}
|
||||
|
||||
export type IChartType = keyof typeof ChartTypeEnum;
|
||||
|
||||
export interface IChartConfiguration<
|
||||
TYPE = string,
|
||||
TYPE extends IChartType = IChartType,
|
||||
T = unknown,
|
||||
L = string,
|
||||
DS extends IChartDataset<T> = IChartDataset<T>,
|
||||
@ -81,6 +94,7 @@ export interface IChartConfiguration<
|
||||
type: TYPE;
|
||||
data: IChartData<T, L, DS>;
|
||||
options?: IChartOptions<O>;
|
||||
plugins?: IPlugin[];
|
||||
}
|
||||
|
||||
export type IBarControllerConfiguration<T = number, L = string> = IChartConfiguration<
|
||||
@ -139,10 +153,10 @@ export type IRadarControllerConfiguration<T = number, L = string> = IChartConfig
|
||||
IRadarControllerChartOptions
|
||||
>;
|
||||
|
||||
export type ConfigurationOptions<O> = O extends IChartConfiguration<unknown, unknown, unknown, infer O> ? O : never;
|
||||
export type ConfigurationData<O> = O extends IChartConfiguration<unknown, infer T, infer L, infer DS, unknown>
|
||||
export type ConfigurationOptions<O> = O extends IChartConfiguration<IChartType, unknown, unknown, infer O> ? O : never;
|
||||
export type ConfigurationData<O> = O extends IChartConfiguration<IChartType, infer T, infer L, infer DS, unknown>
|
||||
? IChartData<T, L, DS>
|
||||
: never;
|
||||
export type ConfigurationDataset<O> = O extends IChartConfiguration<unknown, unknown, unknown, infer DS, unknown>
|
||||
export type ConfigurationDataset<O> = O extends IChartConfiguration<IChartType, unknown, unknown, infer DS, unknown>
|
||||
? DS
|
||||
: never;
|
||||
|
Loading…
Reference in New Issue
Block a user