From: Evert Timberg Date: Sat, 5 Dec 2015 01:01:04 +0000 (-0500) Subject: Highlight correct items when hover mode is set to 'dataset' X-Git-Tag: 2.0.0-beta2~33^2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=refs%2Fpull%2F1741%2Fhead;p=thirdparty%2FChart.js.git Highlight correct items when hover mode is set to 'dataset' --- 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() {