From e930438f4bb08be68e1b8149d3fb4200302ecd3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E7=94=B0=20=E6=86=B2=E5=A4=AA=E9=83=8E?= Date: Sun, 16 Jul 2017 16:45:38 +0900 Subject: [PATCH 1/6] use strictNullChecks mode --- types/chart.js/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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": [ "../" From e144f0643cd2ec6cdd71170e41ec08501a85a574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E7=94=B0=20=E6=86=B2=E5=A4=AA=E9=83=8E?= Date: Sun, 16 Jul 2017 16:50:37 +0900 Subject: [PATCH 2/6] chart instance has properties "ctx", "canvas", "chartArea" ctx, canvas https://github.com/chartjs/Chart.js/blob/master/src/core/core.controller.js#L78-L79 chartArea https://github.com/chartjs/Chart.js/blob/master/src/core/core.layoutService.js#L417-L423 --- types/chart.js/chart.js-tests.ts | 9 +++++++++ types/chart.js/index.d.ts | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/types/chart.js/chart.js-tests.ts b/types/chart.js/chart.js-tests.ts index b9ffd7a8f6..8e5588a232 100644 --- a/types/chart.js/chart.js-tests.ts +++ b/types/chart.js/chart.js-tests.ts @@ -26,3 +26,12 @@ let chart: Chart = new Chart(new CanvasRenderingContext2D(), { } }); 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..3620993688 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -26,6 +26,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 +83,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; From 6805914e4c78129b162350d375de465d89ce525f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E7=94=B0=20=E6=86=B2=E5=A4=AA=E9=83=8E?= Date: Sun, 16 Jul 2017 17:19:49 +0900 Subject: [PATCH 3/6] type of transformed data should be not only string but number. Some convenient function for label conversion (e.g. Math.floor) returns number. It is harmless because when displaying, toString() called implicitly. --- types/chart.js/chart.js-tests.ts | 3 +++ types/chart.js/index.d.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/types/chart.js/chart.js-tests.ts b/types/chart.js/chart.js-tests.ts index 8e5588a232..853d8e489d 100644 --- a/types/chart.js/chart.js-tests.ts +++ b/types/chart.js/chart.js-tests.ts @@ -20,6 +20,9 @@ let chart: Chart = new Chart(new CanvasRenderingContext2D(), { options: { scales: { xAxes: [{ + ticks: { + callback: Math.floor + }, gridLines: { display: false } }] } diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index 3620993688..b4e65ec12f 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -317,7 +317,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; From ff91164e03c91baee3483d0f84ae8f9cb469f83f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E7=94=B0=20=E6=86=B2=E5=A4=AA=E9=83=8E?= Date: Sun, 16 Jul 2017 18:13:55 +0900 Subject: [PATCH 4/6] add properties of ChartTooltipOptions http://www.chartjs.org/docs/latest/configuration/tooltip.html filter, intersect, itemSort, position, caretPadding, displayColors, borderColor, borderWidth --- types/chart.js/chart.js-tests.ts | 10 ++++++++++ types/chart.js/index.d.ts | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/types/chart.js/chart.js-tests.ts b/types/chart.js/chart.js-tests.ts index 853d8e489d..0d51870168 100644 --- a/types/chart.js/chart.js-tests.ts +++ b/types/chart.js/chart.js-tests.ts @@ -18,6 +18,16 @@ let chart: Chart = new Chart(new CanvasRenderingContext2D(), { ] }, options: { + 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: { diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index b4e65ec12f..bab754a821 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -201,6 +201,7 @@ declare namespace Chart { enabled?: boolean; custom?(a: any): void; mode?: string; + intersect?: boolean; backgroundColor?: ChartColor; titleFontFamily?: string; titleFontSize?: number; @@ -225,6 +226,13 @@ 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 { From 56d8e354be30391e3fa140610e3312d8202e23a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E7=94=B0=20=E6=86=B2=E5=A4=AA=E9=83=8E?= Date: Sun, 16 Jul 2017 18:25:26 +0900 Subject: [PATCH 5/6] Add property "intersect" to ChartHoverOptions http://www.chartjs.org/docs/latest/general/interactions/ --- types/chart.js/chart.js-tests.ts | 3 +++ types/chart.js/index.d.ts | 1 + 2 files changed, 4 insertions(+) diff --git a/types/chart.js/chart.js-tests.ts b/types/chart.js/chart.js-tests.ts index 0d51870168..5c2dab60f9 100644 --- a/types/chart.js/chart.js-tests.ts +++ b/types/chart.js/chart.js-tests.ts @@ -18,6 +18,9 @@ let chart: Chart = new Chart(new CanvasRenderingContext2D(), { ] }, options: { + hover: { + intersect: true + }, tooltips: { filter: data => Number(data.yLabel) > 0, intersect: true, diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index bab754a821..dab40d797e 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -238,6 +238,7 @@ declare namespace Chart { interface ChartHoverOptions { mode?: string; animationDuration?: number; + intersect?: boolean; onHover?(active: any): void; } From c402b5ed0e2650addac3122c7bfa4db6d80624f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E7=94=B0=20=E6=86=B2=E5=A4=AA=E9=83=8E?= Date: Sun, 16 Jul 2017 18:40:35 +0900 Subject: [PATCH 6/6] Bump version to chart.js 2.6 and add my credit --- types/chart.js/index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index dab40d797e..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