From e2858b0099d09fed4462ea6c0bfc1c1d4923578b Mon Sep 17 00:00:00 2001 From: Sergey Khomushin Date: Mon, 7 Sep 2020 16:58:59 +0300 Subject: [PATCH 01/11] interfaces.d: added plugins for the chart configuration --- types/interfaces.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/interfaces.d.ts b/types/interfaces.d.ts index d9d9d99a7a8..9af48778290 100644 --- a/types/interfaces.d.ts +++ b/types/interfaces.d.ts @@ -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 extends {} @@ -81,6 +81,7 @@ export interface IChartConfiguration< type: TYPE; data: IChartData; options?: IChartOptions; + plugins?: IPlugin[]; } export type IBarControllerConfiguration = IChartConfiguration< From f314f6a01d721e2688b2e374aa9527c0057da57e Mon Sep 17 00:00:00 2001 From: Sergey Khomushin Date: Mon, 7 Sep 2020 17:00:10 +0300 Subject: [PATCH 02/11] index.d: allow to set data --- types/core/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/core/index.d.ts b/types/core/index.d.ts index 10d063e2810..dd2569c9206 100644 --- a/types/core/index.d.ts +++ b/types/core/index.d.ts @@ -248,12 +248,12 @@ export interface Chart< readonly boxes: ILayoutItem[]; readonly currentDevicePixelRatio: number; readonly chartArea: IChartArea; - readonly data: ConfigurationData; readonly scales: { [key: string]: Scale }; readonly scale: Scale | undefined; readonly attached: boolean; options: ConfigurationOptions; + data: ConfigurationData; clear(): this; stop(): this; From 828e3d2116d6010eb02b5686fbc631851627e1d0 Mon Sep 17 00:00:00 2001 From: Sergey Khomushin Date: Mon, 7 Sep 2020 17:01:30 +0300 Subject: [PATCH 03/11] index.d: improve type for the update method --- types/core/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/core/index.d.ts b/types/core/index.d.ts index dd2569c9206..9cf7d07d0c8 100644 --- a/types/core/index.d.ts +++ b/types/core/index.d.ts @@ -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; From 6dfa0af5b56b6dbd607ff4c25d896d0f9491d61c Mon Sep 17 00:00:00 2001 From: Sergey Khomushin Date: Mon, 7 Sep 2020 17:22:17 +0300 Subject: [PATCH 04/11] interfaces.d: improve type of generic chart type --- types/interfaces.d.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/types/interfaces.d.ts b/types/interfaces.d.ts index 9af48778290..24b6a4ecbaa 100644 --- a/types/interfaces.d.ts +++ b/types/interfaces.d.ts @@ -71,8 +71,23 @@ export type IChartOptions = DeepPartial< O >; +/** + * Well-known chart types + */ +export type IChartKnownTypes = + | 'line' + | 'bar' + | 'radar' + | 'doughnut' + | 'pie' + | 'polarArea' + | 'bubble' + | 'scatter'; + +export type IChartTypes = IChartKnownTypes | string; + export interface IChartConfiguration< - TYPE = string, + TYPE extends IChartTypes = string, T = unknown, L = string, DS extends IChartDataset = IChartDataset, @@ -140,10 +155,10 @@ export type IRadarControllerConfiguration = IChartConfig IRadarControllerChartOptions >; -export type ConfigurationOptions = O extends IChartConfiguration ? O : never; -export type ConfigurationData = O extends IChartConfiguration +export type ConfigurationOptions = O extends IChartConfiguration ? O : never; +export type ConfigurationData = O extends IChartConfiguration ? IChartData : never; -export type ConfigurationDataset = O extends IChartConfiguration +export type ConfigurationDataset = O extends IChartConfiguration ? DS : never; From d1d8d0fca89c7d452d1554df2661ccd8af37c640 Mon Sep 17 00:00:00 2001 From: Sergey Khomushin Date: Mon, 7 Sep 2020 19:20:24 +0300 Subject: [PATCH 05/11] interfaces.d: alphabetical sort --- types/interfaces.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/interfaces.d.ts b/types/interfaces.d.ts index 24b6a4ecbaa..be72c682a6a 100644 --- a/types/interfaces.d.ts +++ b/types/interfaces.d.ts @@ -75,13 +75,13 @@ export type IChartOptions = DeepPartial< * Well-known chart types */ export type IChartKnownTypes = - | 'line' | 'bar' - | 'radar' + | 'bubble' | 'doughnut' + | 'line' | 'pie' | 'polarArea' - | 'bubble' + | 'radar' | 'scatter'; export type IChartTypes = IChartKnownTypes | string; From 3ffdb775e402e315403aa87c83e2afd902722e83 Mon Sep 17 00:00:00 2001 From: Sergey Khomushin Date: Mon, 7 Sep 2020 19:20:59 +0300 Subject: [PATCH 06/11] index.d: set fields in alphabetical sort --- types/core/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/core/index.d.ts b/types/core/index.d.ts index 9cf7d07d0c8..3bd4c9d31ed 100644 --- a/types/core/index.d.ts +++ b/types/core/index.d.ts @@ -252,8 +252,8 @@ export interface Chart< readonly scale: Scale | undefined; readonly attached: boolean; - options: ConfigurationOptions; data: ConfigurationData; + options: ConfigurationOptions; clear(): this; stop(): this; From a9dd422085ad889806c0fae591da88dc9cf6feda Mon Sep 17 00:00:00 2001 From: Sergey Khomushin Date: Tue, 8 Sep 2020 09:33:11 +0300 Subject: [PATCH 07/11] interfaces.d: remove custom type (string) --- types/interfaces.d.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/types/interfaces.d.ts b/types/interfaces.d.ts index be72c682a6a..7542a1ace57 100644 --- a/types/interfaces.d.ts +++ b/types/interfaces.d.ts @@ -74,7 +74,7 @@ export type IChartOptions = DeepPartial< /** * Well-known chart types */ -export type IChartKnownTypes = +export type IChartTypes = | 'bar' | 'bubble' | 'doughnut' @@ -84,10 +84,8 @@ export type IChartKnownTypes = | 'radar' | 'scatter'; -export type IChartTypes = IChartKnownTypes | string; - export interface IChartConfiguration< - TYPE extends IChartTypes = string, + TYPE = IChartTypes, T = unknown, L = string, DS extends IChartDataset = IChartDataset, From 56be047e5d781f8184ce00ff4c5530def3498071 Mon Sep 17 00:00:00 2001 From: Sergey Khomushin Date: Tue, 8 Sep 2020 09:50:14 +0300 Subject: [PATCH 08/11] core/index.d: importve "chart type" type --- types/core/index.d.ts | 6 +++--- types/interfaces.d.ts | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/types/core/index.d.ts b/types/core/index.d.ts index 3bd4c9d31ed..c1e1fc76d55 100644 --- a/types/core/index.d.ts +++ b/types/core/index.d.ts @@ -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 = IChartConfiguration + C extends IChartConfiguration = IChartConfiguration > { readonly platform: BasePlatform; readonly id: string; @@ -301,7 +301,7 @@ export declare type ChartItem = export const Chart: { prototype: Chart; - new = IChartConfiguration>( + new = IChartConfiguration>( item: ChartItem, config: C ): Chart; diff --git a/types/interfaces.d.ts b/types/interfaces.d.ts index 7542a1ace57..db4931f071c 100644 --- a/types/interfaces.d.ts +++ b/types/interfaces.d.ts @@ -74,7 +74,7 @@ export type IChartOptions = DeepPartial< /** * Well-known chart types */ -export type IChartTypes = +export type IChartType = | 'bar' | 'bubble' | 'doughnut' @@ -85,7 +85,7 @@ export type IChartTypes = | 'scatter'; export interface IChartConfiguration< - TYPE = IChartTypes, + TYPE = IChartType, T = unknown, L = string, DS extends IChartDataset = IChartDataset, @@ -153,10 +153,10 @@ export type IRadarControllerConfiguration = IChartConfig IRadarControllerChartOptions >; -export type ConfigurationOptions = O extends IChartConfiguration ? O : never; -export type ConfigurationData = O extends IChartConfiguration +export type ConfigurationOptions = O extends IChartConfiguration ? O : never; +export type ConfigurationData = O extends IChartConfiguration ? IChartData : never; -export type ConfigurationDataset = O extends IChartConfiguration +export type ConfigurationDataset = O extends IChartConfiguration ? DS : never; From 828262ec28296c7e10a553090a529398414f7499 Mon Sep 17 00:00:00 2001 From: Sergey Khomushin Date: Tue, 8 Sep 2020 18:03:10 +0300 Subject: [PATCH 09/11] interfaces.d: added extends for TYPE --- types/interfaces.d.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/types/interfaces.d.ts b/types/interfaces.d.ts index db4931f071c..46a9a5d2be9 100644 --- a/types/interfaces.d.ts +++ b/types/interfaces.d.ts @@ -75,17 +75,17 @@ export type IChartOptions = DeepPartial< * Well-known chart types */ export type IChartType = - | 'bar' - | 'bubble' - | 'doughnut' - | 'line' - | 'pie' - | 'polarArea' - | 'radar' - | 'scatter'; + | 'bar' + | 'bubble' + | 'doughnut' + | 'line' + | 'pie' + | 'polarArea' + | 'radar' + | 'scatter'; export interface IChartConfiguration< - TYPE = IChartType, + TYPE extends IChartType = IChartType, T = unknown, L = string, DS extends IChartDataset = IChartDataset, From 0dc2a1af196853a67ac56232524f71c7776980aa Mon Sep 17 00:00:00 2001 From: Sergey Khomushin Date: Tue, 8 Sep 2020 18:45:09 +0300 Subject: [PATCH 10/11] interfaces.d: move chart types to enum --- types/interfaces.d.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/types/interfaces.d.ts b/types/interfaces.d.ts index 46a9a5d2be9..9aa1e750edb 100644 --- a/types/interfaces.d.ts +++ b/types/interfaces.d.ts @@ -71,18 +71,18 @@ export type IChartOptions = DeepPartial< O >; -/** - * Well-known chart types - */ -export type IChartType = - | 'bar' - | 'bubble' - | 'doughnut' - | 'line' - | 'pie' - | 'polarArea' - | 'radar' - | 'scatter'; +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 extends IChartType = IChartType, From 57f5654d1420f36c124a0d1d476b1cfa09de89c7 Mon Sep 17 00:00:00 2001 From: Sergey Khomushin Date: Tue, 8 Sep 2020 18:54:41 +0300 Subject: [PATCH 11/11] core/index.d: move the update mode to enum --- types/core/index.d.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/types/core/index.d.ts b/types/core/index.d.ts index c1e1fc76d55..1739fcde71c 100644 --- a/types/core/index.d.ts +++ b/types/core/index.d.ts @@ -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 { constructor(chart: Chart, datasetIndex: number);