From 539d38aa82bc0617e9c32d07b601933d5a3505f3 Mon Sep 17 00:00:00 2001 From: Kiarash Date: Fri, 2 Feb 2018 17:29:45 +0100 Subject: [PATCH 1/8] Add support for Tooltip positioners for Chart.Js --- types/chart.js/chart.js-tests.ts | 20 ++++++++++++++++++++ types/chart.js/index.d.ts | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/types/chart.js/chart.js-tests.ts b/types/chart.js/chart.js-tests.ts index 8d2190478f..1075865992 100644 --- a/types/chart.js/chart.js-tests.ts +++ b/types/chart.js/chart.js-tests.ts @@ -65,3 +65,23 @@ if (chart.chartArea) { console.log(chart.chartArea.bottom); console.log(chart.chartArea.left); } + +// http://www.chartjs.org/docs/latest/configuration/tooltip.html#position-modes +/** + * Custom positioner + * @function Chart.Tooltip.positioners.custom + * @param elements {Chart.Element[]} the tooltip elements + * @param eventPosition {Point} the position of the event in canvas coordinates + * @returns {Point} the tooltip position + */ +Chart.Tooltip.positioners.custom = function(elements: any, eventPosition: any) { + /** @type {Chart.Tooltip} */ + var tooltip = this; + + /* ... */ + + return { + x: 0, + y: 0 + }; +} \ No newline at end of file diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index db20617c2d..a2d22dbd67 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -44,6 +44,9 @@ declare class Chart { static controllers: { [key: string]: any; }; + + // Tooltip Static Options + static Tooltip: Chart.ChartTooltipsStaticConfiguartion; } declare class PluginServiceStatic { register(plugin: PluginServiceRegistrationOptions): void; @@ -275,6 +278,10 @@ declare namespace Chart { borderWidth?: number; } + interface ChartTooltipsStaticConfiguartion { + positioners: any; + } + interface ChartHoverOptions { mode?: string; animationDuration?: number; From 7fc0863179e9380dd6b9947429d72bb53b14254a Mon Sep 17 00:00:00 2001 From: Kiarash Date: Fri, 2 Feb 2018 17:32:37 +0100 Subject: [PATCH 2/8] Increase version for Chart.Js --- types/chart.js/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index a2d22dbd67..a637c15cac 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Chart.js 2.7 +// Type definitions for Chart.js 2.7.1 // Project: https://github.com/nnnick/Chart.js // Definitions by: Alberto Nuti // Fabien Lavocat From cdcf2aca3c20112889476fcf2d3352994ea259c6 Mon Sep 17 00:00:00 2001 From: Kiarash Date: Fri, 2 Feb 2018 18:55:46 +0100 Subject: [PATCH 3/8] Remove comments --- types/chart.js/chart.js-tests.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/types/chart.js/chart.js-tests.ts b/types/chart.js/chart.js-tests.ts index 1075865992..3a1c3eb4a6 100644 --- a/types/chart.js/chart.js-tests.ts +++ b/types/chart.js/chart.js-tests.ts @@ -67,19 +67,8 @@ if (chart.chartArea) { } // http://www.chartjs.org/docs/latest/configuration/tooltip.html#position-modes -/** - * Custom positioner - * @function Chart.Tooltip.positioners.custom - * @param elements {Chart.Element[]} the tooltip elements - * @param eventPosition {Point} the position of the event in canvas coordinates - * @returns {Point} the tooltip position - */ Chart.Tooltip.positioners.custom = function(elements: any, eventPosition: any) { - /** @type {Chart.Tooltip} */ var tooltip = this; - - /* ... */ - return { x: 0, y: 0 From 81cd768d6314c4cfc2d99e9b22912aba5a5f3077 Mon Sep 17 00:00:00 2001 From: Kiarash Date: Fri, 2 Feb 2018 19:05:24 +0100 Subject: [PATCH 4/8] Fix TravisCI Bugs --- types/chart.js/chart.js-tests.ts | 4 ++-- types/chart.js/index.d.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/types/chart.js/chart.js-tests.ts b/types/chart.js/chart.js-tests.ts index 3a1c3eb4a6..8400fb5db7 100644 --- a/types/chart.js/chart.js-tests.ts +++ b/types/chart.js/chart.js-tests.ts @@ -68,9 +68,9 @@ if (chart.chartArea) { // http://www.chartjs.org/docs/latest/configuration/tooltip.html#position-modes Chart.Tooltip.positioners.custom = function(elements: any, eventPosition: any) { - var tooltip = this; + const tooltip = this; return { x: 0, y: 0 }; -} \ No newline at end of file +}; diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index a637c15cac..a2d22dbd67 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Chart.js 2.7.1 +// Type definitions for Chart.js 2.7 // Project: https://github.com/nnnick/Chart.js // Definitions by: Alberto Nuti // Fabien Lavocat From 657add1fa267257b9323e8c29e7fad63c3d6c4a8 Mon Sep 17 00:00:00 2001 From: Kiarash Date: Sat, 3 Feb 2018 21:11:43 +0100 Subject: [PATCH 5/8] #23371 Better definition for Chart.js --- types/chart.js/index.d.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index a2d22dbd67..83b164f15a 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -279,9 +279,11 @@ declare namespace Chart { } interface ChartTooltipsStaticConfiguartion { - positioners: any; + positioners: {[mode: string]: ChartTooltipPositioner}; } + type ChartTooltipPositioner = (elements: any[], eventPosition: Point) => Point; + interface ChartHoverOptions { mode?: string; animationDuration?: number; @@ -568,6 +570,11 @@ declare namespace Chart { pointLabels?: PointLabelOptions; ticks?: TickOptions; } + + interface Point { + x: number; + y: number; + } } export = Chart; From e28df7ba4a0c0147db37fa3b1a905e6d24246665 Mon Sep 17 00:00:00 2001 From: Kiarash Date: Sat, 3 Feb 2018 21:24:56 +0100 Subject: [PATCH 6/8] #23371 Fiy typo and updat test --- types/chart.js/chart.js-tests.ts | 9 ++++----- types/chart.js/index.d.ts | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/types/chart.js/chart.js-tests.ts b/types/chart.js/chart.js-tests.ts index 8400fb5db7..8bbbaab044 100644 --- a/types/chart.js/chart.js-tests.ts +++ b/types/chart.js/chart.js-tests.ts @@ -1,4 +1,4 @@ -import { Chart, ChartData } from 'chart.js'; +import { Chart, ChartData, Point } from 'chart.js'; // alternative: // import chartjs = require('chart.js'); @@ -67,10 +67,9 @@ if (chart.chartArea) { } // http://www.chartjs.org/docs/latest/configuration/tooltip.html#position-modes -Chart.Tooltip.positioners.custom = function(elements: any, eventPosition: any) { - const tooltip = this; +Chart.Tooltip.positioners.custom = function(elements: any[], eventPosition: Point) { return { - x: 0, - y: 0 + x: eventPosition.x, + y: eventPosition.y + 10 }; }; diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index 83b164f15a..25b579db7f 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -46,7 +46,7 @@ declare class Chart { }; // Tooltip Static Options - static Tooltip: Chart.ChartTooltipsStaticConfiguartion; + static Tooltip: Chart.ChartTooltipsStaticConfiguration; } declare class PluginServiceStatic { register(plugin: PluginServiceRegistrationOptions): void; @@ -278,7 +278,7 @@ declare namespace Chart { borderWidth?: number; } - interface ChartTooltipsStaticConfiguartion { + interface ChartTooltipsStaticConfiguration { positioners: {[mode: string]: ChartTooltipPositioner}; } From 2a5d98d3a4079475ab1fc67449729b296628dc13 Mon Sep 17 00:00:00 2001 From: Kiarash Date: Sat, 3 Feb 2018 21:35:53 +0100 Subject: [PATCH 7/8] #23371 Fix Travis error --- types/chart.js/chart.js-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/chart.js/chart.js-tests.ts b/types/chart.js/chart.js-tests.ts index 8bbbaab044..8ba81e8747 100644 --- a/types/chart.js/chart.js-tests.ts +++ b/types/chart.js/chart.js-tests.ts @@ -67,7 +67,7 @@ if (chart.chartArea) { } // http://www.chartjs.org/docs/latest/configuration/tooltip.html#position-modes -Chart.Tooltip.positioners.custom = function(elements: any[], eventPosition: Point) { +Chart.Tooltip.positioners.custom = (elements: any[], eventPosition: Point) => { return { x: eventPosition.x, y: eventPosition.y + 10 From d4fbe68f639cdd7cf28be72333d717c9ed3544c1 Mon Sep 17 00:00:00 2001 From: Kiarash Date: Sat, 3 Feb 2018 21:51:48 +0100 Subject: [PATCH 8/8] #23371 Change ChartTooltipOptions.position tpye to string --- types/chart.js/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index 25b579db7f..9a8269bee4 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -271,7 +271,7 @@ declare namespace Chart { callbacks?: ChartTooltipCallback; filter?(item: ChartTooltipItem): boolean; itemSort?(itemA: ChartTooltipItem, itemB: ChartTooltipItem): number; - position?: "average"|"nearest"; + position?: string; caretPadding?: number; displayColors?: boolean; borderColor?: ChartColor;