From 244c8ac7e7cf18e4ced169d2e18e7eb56954d936 Mon Sep 17 00:00:00 2001 From: Ricardo Costa Date: Sat, 27 May 2017 18:51:25 +0100 Subject: [PATCH 1/2] Fix onHover event not being triggered The core controller was looking at the wrong object (options.hover) to find the function to be called on hover. The function is provided on the top level options object (options.onHover). Fixes #4296 --- src/core/core.controller.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 71eb3bb628c..b1f046f416f 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -797,6 +797,7 @@ module.exports = function(Chart) { var me = this; var options = me.options || {}; var hoverOptions = options.hover; + var hoverCallback = options.onHover || options.hover.onHover; var changed = false; me.lastActive = me.lastActive || []; @@ -809,9 +810,9 @@ module.exports = function(Chart) { } // On Hover hook - if (hoverOptions.onHover) { + if (hoverCallback) { // Need to call with native event here to not break backwards compatibility - hoverOptions.onHover.call(me, e.native, me.active); + hoverCallback.call(me, e.native, me.active); } if (e.type === 'mouseup' || e.type === 'click') { From 3551afed97ead2d1b22af3f76073cda23c1e11bf Mon Sep 17 00:00:00 2001 From: Ricardo Costa Date: Sun, 28 May 2017 21:50:28 +0100 Subject: [PATCH 2/2] Use helper function to invoke callback By using the helper function, there's no need to verify if the callback is defined, as the helper already does that. --- src/core/core.controller.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/core/core.controller.js b/src/core/core.controller.js index b1f046f416f..f8c471f3d28 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -797,7 +797,6 @@ module.exports = function(Chart) { var me = this; var options = me.options || {}; var hoverOptions = options.hover; - var hoverCallback = options.onHover || options.hover.onHover; var changed = false; me.lastActive = me.lastActive || []; @@ -809,11 +808,9 @@ module.exports = function(Chart) { me.active = me.getElementsAtEventForMode(e, hoverOptions.mode, hoverOptions); } - // On Hover hook - if (hoverCallback) { - // Need to call with native event here to not break backwards compatibility - hoverCallback.call(me, e.native, me.active); - } + // Invoke onHover hook + // Need to call with native event here to not break backwards compatibility + helpers.callback(options.onHover || options.hover.onHover, [e.native, me.active], me); if (e.type === 'mouseup' || e.type === 'click') { if (options.onClick) {