From 09cf201fe64af2f97eb697f67b5f4d583de6395b Mon Sep 17 00:00:00 2001 From: RossGraeber Date: Thu, 5 Jul 2018 12:18:36 -0500 Subject: [PATCH] highcharts - Add interface for the wrapping and extension of tooltips. (#26962) * Add interfaces for the wrapping and extension of tooltips. * Add testing for wrapping tooltip behavior. --- types/highcharts/index.d.ts | 32 ++++++++++++++++++++++++++++++++ types/highcharts/test/index.ts | 8 ++++++++ 2 files changed, 40 insertions(+) diff --git a/types/highcharts/index.d.ts b/types/highcharts/index.d.ts index 66a1da7407..07a06256e5 100644 --- a/types/highcharts/index.d.ts +++ b/types/highcharts/index.d.ts @@ -6807,6 +6807,16 @@ declare namespace Highcharts { map(array: any[], fn: Function): any[]; + /** + * Wrap an existing behavior of a part of the chart to extend or replace it. + * @since 2.3.0 + * + * @see {@link https://www.highcharts.com/docs/extending-highcharts/extending-highcharts} + * + * @param prototype The prototype for the part of the chart to extend. + * @param type The type of behavior you are extending. + * @param cb The function that executes when the behavior occurs. + */ wrap(prototype: any, type: string, cb: (proceed: Function, ...args: any[]) => void): void; /** @@ -6838,6 +6848,15 @@ declare namespace Highcharts { type: string, eventArguments?: any, defaultFunction?: () => void): void; + + distribute(array: any[], value: number): void; + + /** + * Prototype used to extend tooltip behavior in a chart. + * + * @see {@link https://www.highcharts.com/docs/extending-highcharts/extending-highcharts} + */ + Tooltip: TooltipPrototype; } /** @@ -7079,6 +7098,19 @@ declare namespace Highcharts { */ update(options: LegendOptions, redraw?: boolean): void; } + + /** + * The Tooltip prototype is used to to wrap and extend tooltip behaviors. + * + * @see {@link https://www.highcharts.com/docs/extending-highcharts/extending-highcharts} + */ + interface TooltipPrototype { + /** + * The behavior prototypes for the tooltips in a chart. + * @since 2.3.0 + */ + prototype: any; + } } declare global { diff --git a/types/highcharts/test/index.ts b/types/highcharts/test/index.ts index 310886b585..d6eeaf8c52 100644 --- a/types/highcharts/test/index.ts +++ b/types/highcharts/test/index.ts @@ -2816,3 +2816,11 @@ function test_WordCloud() { } }; } + +// Test wrapping the tooltip refresh behavior. +function test_WrapTooltipBehavior() { + Highcharts.wrap(Highcharts.Tooltip.prototype, 'refresh', (proceed, points) => { + // When refresh is called, code inside this wrap is executed. + // Many prototype functions use this so arrow functions should only be used to replace behaviors. + }); +}