diff --git a/types/chart.js/chart.js-tests.ts b/types/chart.js/chart.js-tests.ts index b9ffd7a8f6..5c2dab60f9 100644 --- a/types/chart.js/chart.js-tests.ts +++ b/types/chart.js/chart.js-tests.ts @@ -18,11 +18,36 @@ let chart: Chart = new Chart(new CanvasRenderingContext2D(), { ] }, options: { + hover: { + intersect: true + }, + tooltips: { + filter: data => Number(data.yLabel) > 0, + intersect: true, + itemSort: (a, b) => Math.random() - 0.5, + position: "average", + caretPadding: 2, + displayColors: true, + borderColor: "rgba(0,0,0,0)", + borderWidth: 1, + }, scales: { xAxes: [{ + ticks: { + callback: Math.floor + }, gridLines: { display: false } }] } } }); chart.update(); + +console.log(chart.ctx && chart.ctx.font); +console.log(chart.canvas && chart.canvas.tagName); +if (chart.chartArea) { + console.log(chart.chartArea.top); + console.log(chart.chartArea.right); + console.log(chart.chartArea.bottom); + console.log(chart.chartArea.left); +} diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index 63c30a739b..f1a39c84c4 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -1,7 +1,8 @@ -// Type definitions for Chart.js 2.4 +// Type definitions for Chart.js 2.6 // Project: https://github.com/nnnick/Chart.js // Definitions by: Alberto Nuti // Fabien Lavocat +// KentarouTakeda // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -26,6 +27,9 @@ declare class Chart { getElementAtEvent: (e: any) => {}; getElementsAtEvent: (e: any) => Array<{}>; getDatasetAtEvent: (e: any) => Array<{}>; + ctx: CanvasRenderingContext2D|null; + canvas: HTMLCanvasElement|null; + chartArea: Chart.ChartArea; static pluginService: PluginServiceStatic; static defaults: { @@ -80,6 +84,13 @@ declare namespace Chart { type PositionType = 'left' | 'right' | 'top' | 'bottom'; + interface ChartArea { + top: number; + right: number; + bottom: number; + left: number; + } + interface ChartLegendItem { text?: string; fillStyle?: string; @@ -191,6 +202,7 @@ declare namespace Chart { enabled?: boolean; custom?(a: any): void; mode?: string; + intersect?: boolean; backgroundColor?: ChartColor; titleFontFamily?: string; titleFontSize?: number; @@ -215,11 +227,19 @@ declare namespace Chart { cornerRadius?: number; multiKeyBackground?: string; callbacks?: ChartTooltipCallback; + filter?(item: ChartTooltipItem): boolean; + itemSort?(itemA: ChartTooltipItem, itemB: ChartTooltipItem): number; + position?: "average"|"nearest"; + caretPadding?: number; + displayColors?: boolean; + borderColor?: ChartColor; + borderWidth?: number; } interface ChartHoverOptions { mode?: string; animationDuration?: number; + intersect?: boolean; onHover?(active: any): void; } @@ -307,7 +327,7 @@ declare namespace Chart { interface TickOptions { autoSkip?: boolean; - callback?(value: any, index: any, values: any): string; + callback?(value: any, index: any, values: any): string|number; display?: boolean; fontColor?: ChartColor; fontFamily?: string; diff --git a/types/chart.js/tsconfig.json b/types/chart.js/tsconfig.json index a798d69e23..aae63d6394 100644 --- a/types/chart.js/tsconfig.json +++ b/types/chart.js/tsconfig.json @@ -7,7 +7,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../"