From 4936e07d7ce27f95e46845fa471c778de29a0a5b Mon Sep 17 00:00:00 2001 From: Daniel Luz Date: Sat, 2 Sep 2017 18:47:10 -0300 Subject: [PATCH 1/3] Update chart.js constructor declaration Any array-like value is accepted, not just jQuery; also, string[] is not actually supported --- types/chart.js/index.d.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index f04fbc1119..34f9f04020 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -7,12 +7,10 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 -/// - declare class Chart { static readonly Chart: typeof Chart; constructor( - context: string | JQuery | CanvasRenderingContext2D | HTMLCanvasElement | string[] | CanvasRenderingContext2D[] | HTMLCanvasElement[], + context: string | CanvasRenderingContext2D | HTMLCanvasElement | ArrayLike, options: Chart.ChartConfiguration ); config: Chart.ChartConfiguration; From ebb97ec70111bde2ff1e2de7d9eb46587eee41a8 Mon Sep 17 00:00:00 2001 From: Daniel Luz Date: Sat, 2 Sep 2017 20:17:11 -0300 Subject: [PATCH 2/3] Improve specificity of types in chart.js --- types/chart.js/index.d.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index 34f9f04020..ed8bded122 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -81,6 +81,8 @@ declare namespace Chart { type ScaleType = 'category' | 'linear' | 'logarithmic' | 'time' | 'radialLinear'; + type PointStyle = 'circle' | 'cross' | 'crossRot' | 'dash' | 'line' | 'rect' | 'rectRounded' | 'rectRot' | 'star' | 'triangle'; + type PositionType = 'left' | 'right' | 'top' | 'bottom'; interface ChartArea { @@ -173,7 +175,7 @@ declare namespace Chart { interface ChartTitleOptions { display?: boolean; - position?: string; + position?: PositionType; fullWdith?: boolean; fontSize?: number; fontFamily?: string; @@ -185,9 +187,9 @@ declare namespace Chart { interface ChartLegendOptions { display?: boolean; - position?: string; + position?: PositionType; fullWidth?: boolean; - onClick?(event: any, legendItem: any): void; + onClick?(event: MouseEvent, legendItem: ChartLegendItem): void; labels?: ChartLegendLabelOptions; } @@ -291,7 +293,7 @@ declare namespace Chart { interface ChartPointOptions { radius?: number; - pointStyle?: string; + pointStyle?: PointStyle; backgroundColor?: ChartColor; borderWidth?: number; borderColor?: ChartColor; @@ -384,7 +386,7 @@ declare namespace Chart { type ChartColor = string | CanvasGradient | CanvasPattern | string[]; interface ChartDataSets { - cubicInterpolationMode?: string; + cubicInterpolationMode?: 'default' | 'monotone'; backgroundColor?: ChartColor | ChartColor[]; borderWidth?: number; borderColor?: ChartColor; @@ -405,14 +407,14 @@ declare namespace Chart { pointHoverBackgroundColor?: ChartColor | ChartColor[]; pointHoverBorderColor?: ChartColor | ChartColor[]; pointHoverBorderWidth?: number | number[]; - pointStyle?: string | string[] | HTMLImageElement | HTMLImageElement[]; + pointStyle?: PointStyle | HTMLImageElement | Array; xAxisID?: string; yAxisID?: string; type?: string; hidden?: boolean; hideInLegendAndTooltip?: boolean; stack?: string; - spanGaps?: string; + spanGaps?: boolean; } interface ChartScales { From 4ab3919c4ec4345078c87bff7d6a5a025a42099b Mon Sep 17 00:00:00 2001 From: Daniel Luz Date: Sat, 2 Sep 2017 20:48:30 -0300 Subject: [PATCH 3/3] Add missing options to chart.js --- types/chart.js/index.d.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index ed8bded122..607f6924f8 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -4,6 +4,7 @@ // Fabien Lavocat // KentarouTakeda // Larry Bahr +// Daniel Luz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -190,7 +191,9 @@ declare namespace Chart { position?: PositionType; fullWidth?: boolean; onClick?(event: MouseEvent, legendItem: ChartLegendItem): void; + onHover?(event: MouseEvent, legendItem: ChartLegendItem): void; labels?: ChartLegendLabelOptions; + reverse?: boolean; } interface ChartLegendLabelOptions { @@ -332,6 +335,7 @@ declare namespace Chart { interface TickOptions { autoSkip?: boolean; + autoSkipPadding?: boolean; callback?(value: any, index: any, values: any): string|number; display?: boolean; fontColor?: ChartColor; @@ -394,10 +398,15 @@ declare namespace Chart { borderDash?: number[]; borderDashOffset?: number; borderJoinStyle?: string; + borderSkipped?: PositionType; data?: number[] | ChartPoint[]; - fill?: boolean; + fill?: boolean | number | string; + hoverBackgroundColor?: string | string[]; + hoverBorderColor?: string | string[]; + hoverBorderWidth?: number | number[]; label?: string; lineTension?: number; + steppedLine?: 'before' | 'after' | boolean; pointBorderColor?: ChartColor | ChartColor[]; pointBackgroundColor?: ChartColor | ChartColor[]; pointBorderWidth?: number | number[]; @@ -413,6 +422,7 @@ declare namespace Chart { type?: string; hidden?: boolean; hideInLegendAndTooltip?: boolean; + showLine?: boolean; stack?: string; spanGaps?: boolean; }