From 59fb1696a8d9bad49bc987a77811f8357cac674d Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Fri, 4 Dec 2015 20:01:04 -0500 Subject: [PATCH] Highlight correct items when hover mode is set to 'dataset' --- samples/line.html | 2 +- src/core/core.controller.js | 19 +++++-------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/samples/line.html b/samples/line.html index 0647173b4..00c0f499f 100644 --- a/samples/line.html +++ b/samples/line.html @@ -88,7 +88,7 @@ } }, hover: { - mode: 'label' + mode: 'dataset' }, scales: { xAxes: [{ diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 536f122ad..0edea25c6 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -331,22 +331,13 @@ }, getDatasetAtEvent: function(e) { - var eventPosition = helpers.getRelativePosition(e, this.chart); - var elementsArray = []; + var elementsArray = this.getElementAtEvent(e); - helpers.each(this.data.datasets, function(dataset, datasetIndex) { - if (helpers.isDatasetVisible(dataset)) { - helpers.each(dataset.metaData, function(element, elementIndex) { - if (element.inLabelRange(eventPosition.x, eventPosition.y)) { - helpers.each(dataset.metaData, function(element, index) { - elementsArray.push(element); - }, this); - } - }, this); - } - }, this); + if (elementsArray.length > 0) { + elementsArray = this.data.datasets[elementsArray[0]._datasetIndex].metaData; + } - return elementsArray.length ? elementsArray : []; + return elementsArray; }, generateLegend: function generateLegend() { -- 2.47.2