From 87dba20f6190c7c4e65dd76d1930a23bc9d9bbf5 Mon Sep 17 00:00:00 2001 From: Jon Rimmer Date: Wed, 13 Feb 2019 23:19:38 +0000 Subject: [PATCH] Review fixes --- samples/legend/callbacks.html | 61 ++++++++++++++++------------------- src/plugins/plugin.legend.js | 20 ++++++------ 2 files changed, 36 insertions(+), 45 deletions(-) diff --git a/samples/legend/callbacks.html b/samples/legend/callbacks.html index 06313626e06..aa71857489e 100644 --- a/samples/legend/callbacks.html +++ b/samples/legend/callbacks.html @@ -1,6 +1,5 @@ - Legend Callbacks @@ -40,6 +39,15 @@ diff --git a/src/plugins/plugin.legend.js b/src/plugins/plugin.legend.js index 5e634b96812..ac8f21b72c0 100644 --- a/src/plugins/plugin.legend.js +++ b/src/plugins/plugin.legend.js @@ -466,20 +466,17 @@ var Legend = Element.extend({ }, /** - * Gets the legend item, if any, at a given x,y position. * @private - * @param {number} x - The x coordinate to check - * @param {number} y - The y coordindate to check - * @return {?Object} - The legend item found */ - getLegendItemAt: function(x, y) { + _getLegendItemAt: function(x, y) { var me = this; + var i, hitBox, lh; if (x >= me.left && x <= me.right && y >= me.top && y <= me.bottom) { // See if we are touching one of the dataset boxes - var lh = me.legendHitBoxes; - for (var i = 0; i < lh.length; ++i) { - var hitBox = lh[i]; + lh = me.legendHitBoxes; + for (i = 0; i < lh.length; ++i) { + hitBox = lh[i]; if (x >= hitBox.left && x <= hitBox.left + hitBox.width && y >= hitBox.top && y <= hitBox.top + hitBox.height) { // Touching an element @@ -500,6 +497,7 @@ var Legend = Element.extend({ var me = this; var opts = me.options; var type = e.type === 'mouseup' ? 'click' : e.type; + var hoveredItem; if (type === 'mousemove') { if (!opts.onHover && !opts.onLeave) { @@ -509,12 +507,12 @@ var Legend = Element.extend({ if (!opts.onClick) { return; } - } else { - return; + } else { + return; } // Chart event already has relative position in it - var hoveredItem = me.getLegendItemAt(e.x, e.y); + hoveredItem = me._getLegendItemAt(e.x, e.y); if (type === 'click') { if (hoveredItem && opts.onClick) {