From ef08762ba252e4ac9088ebba22c04a8d4548189b Mon Sep 17 00:00:00 2001 From: Stephan Troyer Date: Wed, 7 Dec 2016 21:01:14 +0100 Subject: [PATCH 1/4] Added export, tests to chart.js fixes #12525 --- chart.js/chart.js-tests.ts | 26 ++++++++++++ chart.js/index.d.ts | 82 +++++++++++++++++++------------------- chart.js/tsconfig.json | 3 +- 3 files changed, 69 insertions(+), 42 deletions(-) create mode 100644 chart.js/chart.js-tests.ts diff --git a/chart.js/chart.js-tests.ts b/chart.js/chart.js-tests.ts new file mode 100644 index 0000000000..2b38efaa25 --- /dev/null +++ b/chart.js/chart.js-tests.ts @@ -0,0 +1,26 @@ +import { Chart, LinearChartData } from 'chart.js'; + +//alternative: +//import chartjs = require('chart.js'); +// => chartjs.Chart + +var chart = new Chart(new CanvasRenderingContext2D(), { + type: 'bar', + data: { + labels: ['group 1'], + datasets: [ + { + label: 'test', + data: [1] + } + ] + }, + options: { + scales: { + xAxes: [{ + gridLines: { display: false } + }] + } + } +}); +chart.update(); diff --git a/chart.js/index.d.ts b/chart.js/index.d.ts index e9186035c7..609fbeb338 100644 --- a/chart.js/index.d.ts +++ b/chart.js/index.d.ts @@ -3,15 +3,15 @@ // Definitions by: Alberto Nuti // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare enum ChartType { +export enum ChartType { line, bar, radar, doughnut, polarArea, bubble } -declare enum TimeUnit { +export enum TimeUnit { millisecond, second, minute, hour, day, week, month, quarter, year } -interface ChartLegendItem { +export interface ChartLegendItem { text?: string; fillStyle?: string; hidden?: boolean; @@ -22,13 +22,13 @@ interface ChartLegendItem { lineWidth?: number; strokeStyle?: string; } -interface ChartTooltipItem { +export interface ChartTooltipItem { xLabel?: string; yLabel?: string; datasetIndex?: number; index?: number; } -interface ChartTooltipCallback { +export interface ChartTooltipCallback { beforeTitle?: (item?: ChartTooltipItem[], data?: any) => void; title?: (item?: ChartTooltipItem[], data?: any) => void; afterTitle?: (item?: ChartTooltipItem[], data?: any) => void; @@ -41,31 +41,31 @@ interface ChartTooltipCallback { footer?: (item?: ChartTooltipItem[], data?: any) => void; afterfooter?: (item?: ChartTooltipItem[], data?: any) => void; } -interface ChartAnimationParameter { +export interface ChartAnimationParameter { chartInstance?: any; animationObject?: any; } -interface ChartPoint { +export interface ChartPoint { x?: number; y?: number; } -interface ChartConfiguration { +export interface ChartConfiguration { type?: string; data?: ChartData; options?: ChartOptions; } -interface ChartData { +export interface ChartData { } -interface LinearChartData extends ChartData { +export interface LinearChartData extends ChartData { labels?: string[]; datasets?: ChartDataSets[]; } -interface ChartOptions { +export interface ChartOptions { responsive?: boolean; responsiveAnimationDuration?: number; maintainAspectRatio?: boolean; @@ -80,14 +80,14 @@ interface ChartOptions { scales?: ChartScales; } -interface ChartFontOptions { +export interface ChartFontOptions { defaultFontColor?: ChartColor; defaultFontFamily?: string; defaultFontSize?: number; defaultFontStyle?: string; } -interface ChartTitleOptions { +export interface ChartTitleOptions { display?: boolean; position?: string; fullWdith?: boolean; @@ -99,7 +99,7 @@ interface ChartTitleOptions { text?: string; } -interface ChartLegendOptions { +export interface ChartLegendOptions { display?: boolean; position?: string; fullWidth?: boolean; @@ -107,7 +107,7 @@ interface ChartLegendOptions { labels?: ChartLegendLabelOptions; } -interface ChartLegendLabelOptions { +export interface ChartLegendLabelOptions { boxWidth?: number; fontSize?: number; fontStyle?: number; @@ -117,7 +117,7 @@ interface ChartLegendLabelOptions { generateLabels?: (chart: any) => any; } -interface ChartTooltipOptions { +export interface ChartTooltipOptions { enabled?: boolean; custom?: (a: any) => void; mode?: string; @@ -147,13 +147,13 @@ interface ChartTooltipOptions { callbacks?: ChartTooltipCallback; } -interface ChartHoverOptions { +export interface ChartHoverOptions { mode?: string; animationDuration?: number; onHover?: (active: any) => void; } -interface ChartAnimationObject { +export interface ChartAnimationObject { currentStep?: number; numSteps?: number; easing?: string; @@ -162,27 +162,27 @@ interface ChartAnimationObject { onAnimationComplete?: (arg: any) => void; } -interface ChartAnimationOptions { +export interface ChartAnimationOptions { duration?: number; easing?: string; onProgress?: (chart: any) => void; onComplete?: (chart: any) => void; } -interface ChartElementsOptions { +export interface ChartElementsOptions { point?: ChartPointOptions; line?: ChartLineOptions; arg?: ChartArcOtpions; rectangle?: ChartRectangleOptions; } -interface ChartArcOtpions { +export interface ChartArcOtpions { backgroundColor?: ChartColor; borderColor?: ChartColor; borderWidth?: number; } -interface ChartLineOptions { +export interface ChartLineOptions { tension?: number; backgroundColor?: ChartColor; borderWidth?: number; @@ -193,7 +193,7 @@ interface ChartLineOptions { borderJoinStyle?: string; } -interface ChartPointOptions { +export interface ChartPointOptions { radius?: number; pointStyle?: string; backgroundColor?: ChartColor; @@ -204,13 +204,13 @@ interface ChartPointOptions { hoverBorderWidth?: number; } -interface ChartRectangleOptions { +export interface ChartRectangleOptions { backgroundColor?: ChartColor; borderWidth?: number; borderColor?: ChartColor; borderSkipped?: string; } -interface GridLineOptions { +export interface GridLineOptions { display?: boolean; color?: ChartColor; lineWidth?: number; @@ -223,7 +223,7 @@ interface GridLineOptions { offsetGridLines?: boolean; } -interface ScaleTitleOptions { +export interface ScaleTitleOptions { display?: boolean; labelString?: string; fontColor?: ChartColor; @@ -232,7 +232,7 @@ interface ScaleTitleOptions { fontStyle?: string; } -interface TickOptions { +export interface TickOptions { autoSkip?: boolean; callback?: (value: any, index: any, values: any) => string; display?: boolean; @@ -249,13 +249,13 @@ interface TickOptions { min?: any; max?: any; } -interface AngleLineOptions { +export interface AngleLineOptions { display?: boolean; color?: ChartColor; lineWidth?: number; } -interface PointLabelOptions { +export interface PointLabelOptions { callback?: (arg: any) => any; fontColor?: ChartColor; fontFamily?: string; @@ -263,14 +263,14 @@ interface PointLabelOptions { fontStyle?: string; } -interface TickOptions { +export interface TickOptions { backdropColor?: ChartColor; backdropPaddingX?: number; backdropPaddingY?: number; maxTicksLimit?: number; showLabelBackdrop?: boolean; } -interface LinearTickOptions extends TickOptions { +export interface LinearTickOptions extends TickOptions { beginAtZero?: boolean; min?: number; max?: number; @@ -280,14 +280,14 @@ interface LinearTickOptions extends TickOptions { suggestedMax?: number; } -interface LogarithmicTickOptions extends TickOptions { +export interface LogarithmicTickOptions extends TickOptions { min?: number; max?: number; } type ChartColor = string | CanvasGradient | CanvasPattern; -interface ChartDataSets { +export interface ChartDataSets { backgroundColor?: ChartColor; borderWidth?: number; borderColor?: ChartColor; @@ -313,7 +313,7 @@ interface ChartDataSets { yAxisID?: string; } -interface ChartScales { +export interface ChartScales { type?: string; display?: boolean; position?: string; @@ -338,7 +338,7 @@ interface ChartScales { yAxes?: ChartYAxe[]; } -interface ChartXAxe { +export interface ChartXAxe { type?: string; display?: boolean; id?: string; @@ -353,7 +353,7 @@ interface ChartXAxe { scaleLabel?: ScaleTitleOptions; } -interface ChartYAxe { +export interface ChartYAxe { type?: string; display?: boolean; id?: string; @@ -363,15 +363,15 @@ interface ChartYAxe { scaleLabel?: ScaleTitleOptions; } -interface LinearScale extends ChartScales { +export interface LinearScale extends ChartScales { ticks?: LinearTickOptions; } -interface LogarithmicScale extends ChartScales { +export interface LogarithmicScale extends ChartScales { ticks?: LogarithmicTickOptions; } -interface TimeScale extends ChartScales { +export interface TimeScale extends ChartScales { format?: string; displayFormats?: string; isoWeekday?: boolean; @@ -384,14 +384,14 @@ interface TimeScale extends ChartScales { unitStepSize?: number; } -interface RadialLinearScale { +export interface RadialLinearScale { lineArc?: boolean; angleLines?: AngleLineOptions; pointLabels?: PointLabelOptions; ticks?: TickOptions; } -declare class Chart { +export class Chart { constructor (context: CanvasRenderingContext2D | HTMLCanvasElement, options: ChartConfiguration); config: ChartConfiguration; destroy: () => {}; diff --git a/chart.js/tsconfig.json b/chart.js/tsconfig.json index 79b9eb6b27..684beee72d 100644 --- a/chart.js/tsconfig.json +++ b/chart.js/tsconfig.json @@ -13,6 +13,7 @@ "forceConsistentCasingInFileNames": true }, "files": [ - "index.d.ts" + "index.d.ts", + "chart.js-tests.ts" ] } \ No newline at end of file From 6f5fed8bf3deba960e7d003d33bb5f2bf76932ea Mon Sep 17 00:00:00 2001 From: Stephan Troyer Date: Thu, 8 Dec 2016 00:14:19 +0100 Subject: [PATCH 2/4] adding export as namespace --- chart.js/index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chart.js/index.d.ts b/chart.js/index.d.ts index 609fbeb338..62dc61426b 100644 --- a/chart.js/index.d.ts +++ b/chart.js/index.d.ts @@ -410,3 +410,5 @@ export class Chart { global: ChartOptions; } } + +export as namespace Chart; \ No newline at end of file From 3215c7f6964f7a9898020c25e625b1f37d9675ea Mon Sep 17 00:00:00 2001 From: Stephan Date: Mon, 12 Dec 2016 12:19:00 +0100 Subject: [PATCH 3/4] Changed ChartType, TimeUnit, ScaleType, corrected TimeScale.displayFormats --- chart.js/index.d.ts | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/chart.js/index.d.ts b/chart.js/index.d.ts index 62dc61426b..413887601b 100644 --- a/chart.js/index.d.ts +++ b/chart.js/index.d.ts @@ -3,14 +3,12 @@ // Definitions by: Alberto Nuti // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export enum ChartType { - line, bar, radar, doughnut, polarArea, bubble -} -export enum TimeUnit { - millisecond, second, minute, - hour, day, week, - month, quarter, year -} +export declare type ChartType = 'line' | 'bar' | 'radar' | 'doughnut' | 'polarArea' | 'bubble'; + +export declare type TimeUnit = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year'; + +export declare type ScaleType = 'category' | 'linear' | 'logarithmic' | 'time' | 'radialLinear'; + export interface ChartLegendItem { text?: string; fillStyle?: string; @@ -51,7 +49,7 @@ export interface ChartPoint { } export interface ChartConfiguration { - type?: string; + type?: ChartType | string; data?: ChartData; options?: ChartOptions; } @@ -314,7 +312,7 @@ export interface ChartDataSets { } export interface ChartScales { - type?: string; + type?: ScaleType | string; display?: boolean; position?: string; beforeUpdate?: (scale?: any) => void; @@ -339,7 +337,7 @@ export interface ChartScales { } export interface ChartXAxe { - type?: string; + type?: ScaleType | string; display?: boolean; id?: string; stacked?: boolean; @@ -354,7 +352,7 @@ export interface ChartXAxe { } export interface ChartYAxe { - type?: string; + type?: ScaleType | string; display?: boolean; id?: string; stacked?: boolean; @@ -371,16 +369,28 @@ export interface LogarithmicScale extends ChartScales { ticks?: LogarithmicTickOptions; } +export interface TimeDisplayFormat { + millisecond?: string; + second?: string; + minute?: string; + hour?: string; + day?: string; + week?: string; + month?: string; + quarter?: string; + year?: string; +} + export interface TimeScale extends ChartScales { format?: string; - displayFormats?: string; + displayFormats?: TimeDisplayFormat; isoWeekday?: boolean; max?: string; min?: string; parser?: string | ((arg: any) => any); round?: string; tooltipFormat?: string; - unit?: string | TimeUnit; + unit?: TimeUnit; unitStepSize?: number; } From 50efc65b9f9213f84150035c3ac3cc3c0d277239 Mon Sep 17 00:00:00 2001 From: Stephan Date: Mon, 12 Dec 2016 12:33:16 +0100 Subject: [PATCH 4/4] export types as namespace so that it can be accessed via reference -> Chart, reference -> Chart.Chart, import ... from, import ... = require() --- chart.js/index.d.ts | 764 ++++++++++++++++++++++---------------------- 1 file changed, 386 insertions(+), 378 deletions(-) diff --git a/chart.js/index.d.ts b/chart.js/index.d.ts index 413887601b..56b832f572 100644 --- a/chart.js/index.d.ts +++ b/chart.js/index.d.ts @@ -3,422 +3,430 @@ // Definitions by: Alberto Nuti // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export declare type ChartType = 'line' | 'bar' | 'radar' | 'doughnut' | 'polarArea' | 'bubble'; +declare class Chart { + public static readonly Chart: typeof Chart; + constructor(context: CanvasRenderingContext2D | HTMLCanvasElement, options: Chart.ChartConfiguration); + config: Chart.ChartConfiguration; + destroy: () => {}; + update: (duration?: any, lazy?: any) => {}; + render: (duration?: any, lazy?: any) => {}; + stop: () => {}; + resize: () => {}; + clear: () => {}; + toBase64: () => string; + generateLegend: () => {}; + getElementAtEvent: (e: any) => {}; + getElementsAtEvent: (e: any) => {}[]; + getDatasetAtEvent: (e: any) => {}[]; -export declare type TimeUnit = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year'; - -export declare type ScaleType = 'category' | 'linear' | 'logarithmic' | 'time' | 'radialLinear'; - -export interface ChartLegendItem { - text?: string; - fillStyle?: string; - hidden?: boolean; - lineCap?: string; - lineDash?: number[]; - lineDashOffset?: number; - lineJoin?: string; - lineWidth?: number; - strokeStyle?: string; -} -export interface ChartTooltipItem { - xLabel?: string; - yLabel?: string; - datasetIndex?: number; - index?: number; -} -export interface ChartTooltipCallback { - beforeTitle?: (item?: ChartTooltipItem[], data?: any) => void; - title?: (item?: ChartTooltipItem[], data?: any) => void; - afterTitle?: (item?: ChartTooltipItem[], data?: any) => void; - beforeBody?: (item?: ChartTooltipItem[], data?: any) => void; - beforeLabel?: (tooltipItem?: ChartTooltipItem, data?: any) => void; - label?: (tooltipItem?: ChartTooltipItem, data?: any) => void; - afterLabel?: (tooltipItem?: ChartTooltipItem, data?: any) => void; - afterBody?: (item?: ChartTooltipItem[], data?: any) => void; - beforeFooter?: (item?: ChartTooltipItem[], data?: any) => void; - footer?: (item?: ChartTooltipItem[], data?: any) => void; - afterfooter?: (item?: ChartTooltipItem[], data?: any) => void; -} -export interface ChartAnimationParameter { - chartInstance?: any; - animationObject?: any; -} -export interface ChartPoint { - x?: number; - y?: number; + defaults: { + global: Chart.ChartOptions; + } } -export interface ChartConfiguration { - type?: ChartType | string; - data?: ChartData; - options?: ChartOptions; -} +declare namespace Chart { + export type ChartType = 'line' | 'bar' | 'radar' | 'doughnut' | 'polarArea' | 'bubble'; -export interface ChartData { + export type TimeUnit = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year'; -} + export type ScaleType = 'category' | 'linear' | 'logarithmic' | 'time' | 'radialLinear'; -export interface LinearChartData extends ChartData { - labels?: string[]; - datasets?: ChartDataSets[]; -} + export interface ChartLegendItem { + text?: string; + fillStyle?: string; + hidden?: boolean; + lineCap?: string; + lineDash?: number[]; + lineDashOffset?: number; + lineJoin?: string; + lineWidth?: number; + strokeStyle?: string; + } -export interface ChartOptions { - responsive?: boolean; - responsiveAnimationDuration?: number; - maintainAspectRatio?: boolean; - events?: string[]; - onClick?: (any?: any) => any; - title?: ChartTitleOptions; - legend?: ChartLegendOptions; - tooltips?: ChartTooltipOptions; - hover?: ChartHoverOptions; - animation?: ChartAnimationOptions; - elements?: ChartElementsOptions; - scales?: ChartScales; -} + export interface ChartTooltipItem { + xLabel?: string; + yLabel?: string; + datasetIndex?: number; + index?: number; + } -export interface ChartFontOptions { - defaultFontColor?: ChartColor; - defaultFontFamily?: string; - defaultFontSize?: number; - defaultFontStyle?: string; -} + export interface ChartTooltipCallback { + beforeTitle?: (item?: ChartTooltipItem[], data?: any) => void; + title?: (item?: ChartTooltipItem[], data?: any) => void; + afterTitle?: (item?: ChartTooltipItem[], data?: any) => void; + beforeBody?: (item?: ChartTooltipItem[], data?: any) => void; + beforeLabel?: (tooltipItem?: ChartTooltipItem, data?: any) => void; + label?: (tooltipItem?: ChartTooltipItem, data?: any) => void; + afterLabel?: (tooltipItem?: ChartTooltipItem, data?: any) => void; + afterBody?: (item?: ChartTooltipItem[], data?: any) => void; + beforeFooter?: (item?: ChartTooltipItem[], data?: any) => void; + footer?: (item?: ChartTooltipItem[], data?: any) => void; + afterfooter?: (item?: ChartTooltipItem[], data?: any) => void; + } -export interface ChartTitleOptions { - display?: boolean; - position?: string; - fullWdith?: boolean; - fontSize?: number; - fontFamily?: string; - fontColor?: ChartColor; - fontStyle?: string; - padding?: number; - text?: string; -} + export interface ChartAnimationParameter { + chartInstance?: any; + animationObject?: any; + } -export interface ChartLegendOptions { - display?: boolean; - position?: string; - fullWidth?: boolean; - onClick?: (event: any, legendItem: any) => void; - labels?: ChartLegendLabelOptions; -} + export interface ChartPoint { + x?: number; + y?: number; + } -export interface ChartLegendLabelOptions { - boxWidth?: number; - fontSize?: number; - fontStyle?: number; - fontColor?: ChartColor; - fontFamily?: string; - padding?: number; - generateLabels?: (chart: any) => any; -} + export interface ChartConfiguration { + type?: ChartType | string; + data?: ChartData; + options?: ChartOptions; + } -export interface ChartTooltipOptions { - enabled?: boolean; - custom?: (a: any) => void; - mode?: string; - backgroundColor?: ChartColor; - titleFontFamily?: string; - titleFontSize?: number; - titleFontStyle?: string; - titleFontColor?: ChartColor; - titleSpacing?: number; - titleMarginBottom?: number; - bodyFontFamily?: string; - bodyFontSize?: number; - bodyFontStyle?: string; - bodyFontColor?: ChartColor; - bodySpacing?: number; - footerFontFamily?: string; - footerFontSize?: number; - footerFontStyle?: string; - footerFontColor?: ChartColor; - footerSpacing?: number; - footerMarginTop?: number; - xPadding?: number; - yPadding?: number; - caretSize?: number; - cornerRadius?: number; - multiKeyBackground?: string; - callbacks?: ChartTooltipCallback; -} + export interface ChartData { -export interface ChartHoverOptions { - mode?: string; - animationDuration?: number; - onHover?: (active: any) => void; -} + } -export interface ChartAnimationObject { - currentStep?: number; - numSteps?: number; - easing?: string; - render?: (arg: any) => void; - onAnimationProgress?: (arg: any) => void; - onAnimationComplete?: (arg: any) => void; -} + export interface LinearChartData extends ChartData { + labels?: string[]; + datasets?: ChartDataSets[]; + } -export interface ChartAnimationOptions { - duration?: number; - easing?: string; - onProgress?: (chart: any) => void; - onComplete?: (chart: any) => void; -} + export interface ChartOptions { + responsive?: boolean; + responsiveAnimationDuration?: number; + maintainAspectRatio?: boolean; + events?: string[]; + onClick?: (any?: any) => any; + title?: ChartTitleOptions; + legend?: ChartLegendOptions; + tooltips?: ChartTooltipOptions; + hover?: ChartHoverOptions; + animation?: ChartAnimationOptions; + elements?: ChartElementsOptions; + scales?: ChartScales; + } -export interface ChartElementsOptions { - point?: ChartPointOptions; - line?: ChartLineOptions; - arg?: ChartArcOtpions; - rectangle?: ChartRectangleOptions; -} + export interface ChartFontOptions { + defaultFontColor?: ChartColor; + defaultFontFamily?: string; + defaultFontSize?: number; + defaultFontStyle?: string; + } -export interface ChartArcOtpions { - backgroundColor?: ChartColor; - borderColor?: ChartColor; - borderWidth?: number; -} + export interface ChartTitleOptions { + display?: boolean; + position?: string; + fullWdith?: boolean; + fontSize?: number; + fontFamily?: string; + fontColor?: ChartColor; + fontStyle?: string; + padding?: number; + text?: string; + } -export interface ChartLineOptions { - tension?: number; - backgroundColor?: ChartColor; - borderWidth?: number; - borderColor?: ChartColor; - borderCapStyle?: string; - borderDash?: any[]; - borderDashOffset?: number; - borderJoinStyle?: string; -} + export interface ChartLegendOptions { + display?: boolean; + position?: string; + fullWidth?: boolean; + onClick?: (event: any, legendItem: any) => void; + labels?: ChartLegendLabelOptions; + } -export interface ChartPointOptions { - radius?: number; - pointStyle?: string; - backgroundColor?: ChartColor; - borderWidth?: number; - borderColor?: ChartColor; - hitRadius?: number; - hoverRadius?: number; - hoverBorderWidth?: number; -} + export interface ChartLegendLabelOptions { + boxWidth?: number; + fontSize?: number; + fontStyle?: number; + fontColor?: ChartColor; + fontFamily?: string; + padding?: number; + generateLabels?: (chart: any) => any; + } -export interface ChartRectangleOptions { - backgroundColor?: ChartColor; - borderWidth?: number; - borderColor?: ChartColor; - borderSkipped?: string; -} -export interface GridLineOptions { - display?: boolean; - color?: ChartColor; - lineWidth?: number; - drawBorder?: boolean; - drawOnChartArea?: boolean; - drawticks?: boolean; - tickMarkLength?: number; - zeroLineWidth?: number; - zeroLineColor?: ChartColor; - offsetGridLines?: boolean; -} + export interface ChartTooltipOptions { + enabled?: boolean; + custom?: (a: any) => void; + mode?: string; + backgroundColor?: ChartColor; + titleFontFamily?: string; + titleFontSize?: number; + titleFontStyle?: string; + titleFontColor?: ChartColor; + titleSpacing?: number; + titleMarginBottom?: number; + bodyFontFamily?: string; + bodyFontSize?: number; + bodyFontStyle?: string; + bodyFontColor?: ChartColor; + bodySpacing?: number; + footerFontFamily?: string; + footerFontSize?: number; + footerFontStyle?: string; + footerFontColor?: ChartColor; + footerSpacing?: number; + footerMarginTop?: number; + xPadding?: number; + yPadding?: number; + caretSize?: number; + cornerRadius?: number; + multiKeyBackground?: string; + callbacks?: ChartTooltipCallback; + } -export interface ScaleTitleOptions { - display?: boolean; - labelString?: string; - fontColor?: ChartColor; - fontFamily?: string; - fontSize?: number; - fontStyle?: string; -} + export interface ChartHoverOptions { + mode?: string; + animationDuration?: number; + onHover?: (active: any) => void; + } -export interface TickOptions { - autoSkip?: boolean; - callback?: (value: any, index: any, values: any) => string; - display?: boolean; - fontColor?: ChartColor; - fontFamily?: string; - fontSize?: number; - fontStyle?: string; - labelOffset?: number; - maxRotation?: number; - minRotation?: number; - mirror?: boolean; - padding?: number; - reverse?: boolean; - min?: any; - max?: any; -} -export interface AngleLineOptions { - display?: boolean; - color?: ChartColor; - lineWidth?: number; -} + export interface ChartAnimationObject { + currentStep?: number; + numSteps?: number; + easing?: string; + render?: (arg: any) => void; + onAnimationProgress?: (arg: any) => void; + onAnimationComplete?: (arg: any) => void; + } -export interface PointLabelOptions { - callback?: (arg: any) => any; - fontColor?: ChartColor; - fontFamily?: string; - fontSize?: number; - fontStyle?: string; -} + export interface ChartAnimationOptions { + duration?: number; + easing?: string; + onProgress?: (chart: any) => void; + onComplete?: (chart: any) => void; + } -export interface TickOptions { - backdropColor?: ChartColor; - backdropPaddingX?: number; - backdropPaddingY?: number; - maxTicksLimit?: number; - showLabelBackdrop?: boolean; -} -export interface LinearTickOptions extends TickOptions { - beginAtZero?: boolean; - min?: number; - max?: number; - maxTicksLimit?: number; - stepSize?: number; - suggestedMin?: number; - suggestedMax?: number; -} + export interface ChartElementsOptions { + point?: ChartPointOptions; + line?: ChartLineOptions; + arg?: ChartArcOtpions; + rectangle?: ChartRectangleOptions; + } -export interface LogarithmicTickOptions extends TickOptions { - min?: number; - max?: number; -} + export interface ChartArcOtpions { + backgroundColor?: ChartColor; + borderColor?: ChartColor; + borderWidth?: number; + } -type ChartColor = string | CanvasGradient | CanvasPattern; + export interface ChartLineOptions { + tension?: number; + backgroundColor?: ChartColor; + borderWidth?: number; + borderColor?: ChartColor; + borderCapStyle?: string; + borderDash?: any[]; + borderDashOffset?: number; + borderJoinStyle?: string; + } -export interface ChartDataSets { - backgroundColor?: ChartColor; - borderWidth?: number; - borderColor?: ChartColor; - borderCapStyle?: string; - borderDash?: number[]; - borderDashOffset?: number; - borderJoinStyle?: string; - data?: number[] | ChartPoint[]; - fill?: boolean; - label?: string; - lineTension?: number; - pointBorderColor?: ChartColor | ChartColor[]; - pointBackgroundColor?: ChartColor | ChartColor[]; - pointBorderWidth?: number | number[]; - pointRadius?: number | number[]; - pointHoverRadius?: number | number[]; - pointHitRadius?: number | number[]; - pointHoverBackgroundColor?: ChartColor | ChartColor[]; - pointHoverBorderColor?: ChartColor | ChartColor[]; - pointHoverBorderWidth?: number | number[]; - pointStyle?: string | string[] | HTMLImageElement | HTMLImageElement[]; - xAxisID?: string; - yAxisID?: string; -} + export interface ChartPointOptions { + radius?: number; + pointStyle?: string; + backgroundColor?: ChartColor; + borderWidth?: number; + borderColor?: ChartColor; + hitRadius?: number; + hoverRadius?: number; + hoverBorderWidth?: number; + } -export interface ChartScales { - type?: ScaleType | string; - display?: boolean; - position?: string; - beforeUpdate?: (scale?: any) => void; - beforeSetDimension?: (scale?: any) => void; - beforeDataLimits?: (scale?: any) => void; - beforeBuildTicks?: (scale?: any) => void; - beforeTickToLabelConversion?: (scale?: any) => void; - beforeCalculateTickRotation?: (scale?: any) => void; - beforeFit?: (scale?: any) => void; - afterUpdate?: (scale?: any) => void; - afterSetDimension?: (scale?: any) => void; - afterDataLimits?: (scale?: any) => void; - afterBuildTicks?: (scale?: any) => void; - afterTickToLabelConversion?: (scale?: any) => void; - afterCalculateTickRotation?: (scale?: any) => void; - afterFit?: (scale?: any) => void; - gridLines?: GridLineOptions; - scaleLabel?: ScaleTitleOptions; - ticks?: TickOptions; - xAxes?: ChartXAxe[]; - yAxes?: ChartYAxe[]; -} + export interface ChartRectangleOptions { + backgroundColor?: ChartColor; + borderWidth?: number; + borderColor?: ChartColor; + borderSkipped?: string; + } + export interface GridLineOptions { + display?: boolean; + color?: ChartColor; + lineWidth?: number; + drawBorder?: boolean; + drawOnChartArea?: boolean; + drawticks?: boolean; + tickMarkLength?: number; + zeroLineWidth?: number; + zeroLineColor?: ChartColor; + offsetGridLines?: boolean; + } -export interface ChartXAxe { - type?: ScaleType | string; - display?: boolean; - id?: string; - stacked?: boolean; - categoryPercentage?: number; - barPercentage?: number; - barThickness?: number; - gridLines?: GridLineOptions; - position?: string; - ticks?: TickOptions; - time?: TimeScale; - scaleLabel?: ScaleTitleOptions; -} + export interface ScaleTitleOptions { + display?: boolean; + labelString?: string; + fontColor?: ChartColor; + fontFamily?: string; + fontSize?: number; + fontStyle?: string; + } -export interface ChartYAxe { - type?: ScaleType | string; - display?: boolean; - id?: string; - stacked?: boolean; - position?: string; - ticks?: TickOptions; - scaleLabel?: ScaleTitleOptions; -} + export interface TickOptions { + autoSkip?: boolean; + callback?: (value: any, index: any, values: any) => string; + display?: boolean; + fontColor?: ChartColor; + fontFamily?: string; + fontSize?: number; + fontStyle?: string; + labelOffset?: number; + maxRotation?: number; + minRotation?: number; + mirror?: boolean; + padding?: number; + reverse?: boolean; + min?: any; + max?: any; + } + export interface AngleLineOptions { + display?: boolean; + color?: ChartColor; + lineWidth?: number; + } -export interface LinearScale extends ChartScales { - ticks?: LinearTickOptions; -} + export interface PointLabelOptions { + callback?: (arg: any) => any; + fontColor?: ChartColor; + fontFamily?: string; + fontSize?: number; + fontStyle?: string; + } -export interface LogarithmicScale extends ChartScales { - ticks?: LogarithmicTickOptions; -} + export interface TickOptions { + backdropColor?: ChartColor; + backdropPaddingX?: number; + backdropPaddingY?: number; + maxTicksLimit?: number; + showLabelBackdrop?: boolean; + } + export interface LinearTickOptions extends TickOptions { + beginAtZero?: boolean; + min?: number; + max?: number; + maxTicksLimit?: number; + stepSize?: number; + suggestedMin?: number; + suggestedMax?: number; + } -export interface TimeDisplayFormat { - millisecond?: string; - second?: string; - minute?: string; - hour?: string; - day?: string; - week?: string; - month?: string; - quarter?: string; - year?: string; -} + export interface LogarithmicTickOptions extends TickOptions { + min?: number; + max?: number; + } -export interface TimeScale extends ChartScales { - format?: string; - displayFormats?: TimeDisplayFormat; - isoWeekday?: boolean; - max?: string; - min?: string; - parser?: string | ((arg: any) => any); - round?: string; - tooltipFormat?: string; - unit?: TimeUnit; - unitStepSize?: number; -} + type ChartColor = string | CanvasGradient | CanvasPattern; -export interface RadialLinearScale { - lineArc?: boolean; - angleLines?: AngleLineOptions; - pointLabels?: PointLabelOptions; - ticks?: TickOptions; -} + export interface ChartDataSets { + backgroundColor?: ChartColor; + borderWidth?: number; + borderColor?: ChartColor; + borderCapStyle?: string; + borderDash?: number[]; + borderDashOffset?: number; + borderJoinStyle?: string; + data?: number[] | ChartPoint[]; + fill?: boolean; + label?: string; + lineTension?: number; + pointBorderColor?: ChartColor | ChartColor[]; + pointBackgroundColor?: ChartColor | ChartColor[]; + pointBorderWidth?: number | number[]; + pointRadius?: number | number[]; + pointHoverRadius?: number | number[]; + pointHitRadius?: number | number[]; + pointHoverBackgroundColor?: ChartColor | ChartColor[]; + pointHoverBorderColor?: ChartColor | ChartColor[]; + pointHoverBorderWidth?: number | number[]; + pointStyle?: string | string[] | HTMLImageElement | HTMLImageElement[]; + xAxisID?: string; + yAxisID?: string; + } -export class Chart { - constructor (context: CanvasRenderingContext2D | HTMLCanvasElement, options: ChartConfiguration); - config: ChartConfiguration; - destroy: () => {}; - update: (duration?: any, lazy?: any) => {}; - render: (duration?: any, lazy?: any) => {}; - stop: () => {}; - resize: () => {}; - clear: () => {}; - toBase64: () => string; - generateLegend: () => {}; - getElementAtEvent: (e: any) => {}; - getElementsAtEvent: (e: any) => {}[]; - getDatasetAtEvent: (e: any) => {}[]; + export interface ChartScales { + type?: ScaleType | string; + display?: boolean; + position?: string; + beforeUpdate?: (scale?: any) => void; + beforeSetDimension?: (scale?: any) => void; + beforeDataLimits?: (scale?: any) => void; + beforeBuildTicks?: (scale?: any) => void; + beforeTickToLabelConversion?: (scale?: any) => void; + beforeCalculateTickRotation?: (scale?: any) => void; + beforeFit?: (scale?: any) => void; + afterUpdate?: (scale?: any) => void; + afterSetDimension?: (scale?: any) => void; + afterDataLimits?: (scale?: any) => void; + afterBuildTicks?: (scale?: any) => void; + afterTickToLabelConversion?: (scale?: any) => void; + afterCalculateTickRotation?: (scale?: any) => void; + afterFit?: (scale?: any) => void; + gridLines?: GridLineOptions; + scaleLabel?: ScaleTitleOptions; + ticks?: TickOptions; + xAxes?: ChartXAxe[]; + yAxes?: ChartYAxe[]; + } - defaults: { - global: ChartOptions; + export interface ChartXAxe { + type?: ScaleType | string; + display?: boolean; + id?: string; + stacked?: boolean; + categoryPercentage?: number; + barPercentage?: number; + barThickness?: number; + gridLines?: GridLineOptions; + position?: string; + ticks?: TickOptions; + time?: TimeScale; + scaleLabel?: ScaleTitleOptions; + } + + export interface ChartYAxe { + type?: ScaleType | string; + display?: boolean; + id?: string; + stacked?: boolean; + position?: string; + ticks?: TickOptions; + scaleLabel?: ScaleTitleOptions; + } + + export interface LinearScale extends ChartScales { + ticks?: LinearTickOptions; + } + + export interface LogarithmicScale extends ChartScales { + ticks?: LogarithmicTickOptions; + } + + export interface TimeDisplayFormat { + millisecond?: string; + second?: string; + minute?: string; + hour?: string; + day?: string; + week?: string; + month?: string; + quarter?: string; + year?: string; + } + + export interface TimeScale extends ChartScales { + format?: string; + displayFormats?: TimeDisplayFormat; + isoWeekday?: boolean; + max?: string; + min?: string; + parser?: string | ((arg: any) => any); + round?: string; + tooltipFormat?: string; + unit?: TimeUnit; + unitStepSize?: number; + } + + export interface RadialLinearScale { + lineArc?: boolean; + angleLines?: AngleLineOptions; + pointLabels?: PointLabelOptions; + ticks?: TickOptions; } } +export = Chart; export as namespace Chart; \ No newline at end of file