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.
This commit is contained in:
RossGraeber
2018-07-05 10:18:36 -07:00
committed by Mohamed Hegazy
parent 84c222d10b
commit 09cf201fe6
2 changed files with 40 additions and 0 deletions
+32
View File
@@ -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 {
+8
View File
@@ -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.
});
}