Skip to content

Commit

Permalink
Improved performance when clearing timeouts, closes #7901.
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelfus authored and TorsteinHonsi committed Feb 27, 2018
1 parent f10d01e commit fa4d43e
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion js/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"globals": {
"clearInterval": true,
"clearTimeout": true,
"clearTimeout": false,
"console": true,
"module": true,
"setInterval": true,
Expand Down
2 changes: 1 addition & 1 deletion js/modules/boost-canvas.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ H.initCanvasBoost = function () {
opacity: 1
}
});
clearTimeout(destroyLoadingDiv);
H.clearTimeout(destroyLoadingDiv);
chart.showLoading('Drawing...');
chart.options.loading = loadingOptions; // reset
}
Expand Down
4 changes: 2 additions & 2 deletions js/modules/exporting.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ extend(Chart.prototype, /** @lends Highcharts.Chart.prototype */ {
menu.hideTimer = setTimeout(hide, 500);
}),
addEvent(menu, 'mouseenter', function () {
clearTimeout(menu.hideTimer);
H.clearTimeout(menu.hideTimer);
}),

// Hide it on clicking or touching outside the menu (#2258, #2335,
Expand Down Expand Up @@ -1513,7 +1513,7 @@ extend(Chart.prototype, /** @lends Highcharts.Chart.prototype */ {
each(exportDivElements, function (elem, i) {

// Remove the event handler
clearTimeout(elem.hideTimer); // #5427
H.clearTimeout(elem.hideTimer); // #5427
removeEvent(elem, 'mouseleave');

// Remove inline events
Expand Down
2 changes: 1 addition & 1 deletion js/modules/series-label.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ function drawLabels(proceed) {
chart.labelSeries = [];
chart.labelSeriesMaxSum = 0;

clearTimeout(chart.seriesLabelTimer);
H.clearTimeout(chart.seriesLabelTimer);

// Which series should have labels
each(chart.series, function (series) {
Expand Down
2 changes: 1 addition & 1 deletion js/parts-map/MapSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ seriesType('map', 'scatter', {
* Stop the fade-out
*/
onMouseOver: function (e) {
clearTimeout(this.colorInterval);
H.clearTimeout(this.colorInterval);
if (this.value !== null || this.series.options.nullInteraction) {
Point.prototype.onMouseOver.call(this, e);
} else { // #3401 Tooltip doesn't hide when hovering over null points
Expand Down
2 changes: 1 addition & 1 deletion js/parts/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ extend(Chart.prototype, /** @lends Highcharts.Chart.prototype */ {
width !== chart.containerWidth ||
height !== chart.containerHeight
) {
clearTimeout(chart.reflowTimeout);
H.clearTimeout(chart.reflowTimeout);
// When called from window.resize, e is set, else it's called
// directly (#2224)
chart.reflowTimeout = syncTimeout(function () {
Expand Down
2 changes: 1 addition & 1 deletion js/parts/Series.js
Original file line number Diff line number Diff line change
Expand Up @@ -4019,7 +4019,7 @@ H.Series = H.seriesType('line', null, { // base series options

// Clear the animation timeout if we are destroying the series during
// initial animation
clearTimeout(series.animationTimeout);
H.clearTimeout(series.animationTimeout);

// Destroy all SVGElements associated to the series
objectEach(series, function (val, prop) {
Expand Down
10 changes: 5 additions & 5 deletions js/parts/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ H.Tooltip.prototype = {
this.cleanSplit(this.chart, true);
this.tt = this.tt.destroy();
}
clearTimeout(this.hideTimer);
clearTimeout(this.tooltipTimeout);
H.clearTimeout(this.hideTimer);
H.clearTimeout(this.tooltipTimeout);
},

/**
Expand Down Expand Up @@ -235,7 +235,7 @@ H.Tooltip.prototype = {
if (animate) {

// Never allow two timeouts
clearTimeout(this.tooltipTimeout);
H.clearTimeout(this.tooltipTimeout);

// Set the fixed interval ticking for the smooth tooltip
this.tooltipTimeout = setTimeout(function () {
Expand All @@ -255,7 +255,7 @@ H.Tooltip.prototype = {
hide: function (delay) {
var tooltip = this;
// disallow duplicate timers (#1728, #1766)
clearTimeout(this.hideTimer);
H.clearTimeout(this.hideTimer);
delay = pick(delay, this.options.hideDelay, 500);
if (!this.isHidden) {
this.hideTimer = syncTimeout(function () {
Expand Down Expand Up @@ -493,7 +493,7 @@ H.Tooltip.prototype = {
return;
}

clearTimeout(this.hideTimer);
H.clearTimeout(this.hideTimer);

// get the reference point coordinates (pie charts use tooltipPos)
tooltip.followPointer = splat(point)[0].series.tooltipOptions
Expand Down
16 changes: 15 additions & 1 deletion js/parts/Utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ H.splat = function (obj) {
* @param {Number} delay - Delay in milliseconds.
* @param {Object} [context] - The context.
* @returns {Number} An identifier for the timeout that can later be cleared
* with clearTimeout.
* with H.clearTimeout.
*/
H.syncTimeout = function (fn, delay, context) {
if (delay) {
Expand All @@ -686,6 +686,20 @@ H.syncTimeout = function (fn, delay, context) {
fn.call(0, context);
};

/**
* Internal clear timeout.
* Function checks if the `id` was not removed (e.g. by `chart.destroy()`).
* For the details see issue #7901.
*
* @function #clearTimeout
* @memberOf Highcharts
* @param {Number} id - id of a timeout.
*/
H.clearTimeout = function (id) {
if (H.defined(id)) {
clearTimeout(id);
}
};

/**
* Utility function to extend an object with the members of another.
Expand Down

0 comments on commit fa4d43e

Please sign in to comment.