-
Notifications
You must be signed in to change notification settings - Fork 10
/
tooltip-delay.dist.js
65 lines (49 loc) · 1.59 KB
/
tooltip-delay.dist.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(function (factory) {
"use strict";
if (typeof module === "object" && module.exports) {
module.exports = factory;
} else {
factory(Highcharts);
}
}(function (H) {
let timerId = {};
const generatePointsUniqueKey = (points) => {
const generatePointKey = (point) => {
return point.category + " " + point.series.name + ": " + point.x + " " + point.y;
};
const result = points.map(generatePointKey).join(', ');
return result;
}
function inArray(value, arr) {
for (let i = 0; i < arr.length; i++) {
if (this[i] === value) {
return true;
}
}
return false;
}
H.wrap(H.Tooltip.prototype, 'refresh', function (proceed) {
let seriesName;
if (Array.isArray(arguments[1])) {
// Can be array in case that, it's shared tooltip
seriesName = generatePointsUniqueKey(arguments[1]);
} else {
seriesName = arguments[1].series.name;
}
const delayForDisplay = this.chart.options.tooltip.delayForDisplay ? this.chart.options.tooltip.delayForDisplay : 1000;
if (timerId[seriesName]) {
clearTimeout(timerId[seriesName]);
delete timerId[seriesName];
}
timerId[seriesName] = window.setTimeout(function () {
let pointOrPoints = this.refreshArguments[0];
if (pointOrPoints === this.chart.hoverPoint || inArray(this.chart.hoverPoint, pointOrPoints) > -1) {
proceed.apply(this.tooltip, this.refreshArguments);
}
}.bind({
refreshArguments: Array.prototype.slice.call(arguments, 1),
chart: this.chart,
tooltip: this
}), delayForDisplay);
});
}));