]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Highlight correct items when hover mode is set to 'dataset' 1741/head
authorEvert Timberg <evert.timberg@gmail.com>
Sat, 5 Dec 2015 01:01:04 +0000 (20:01 -0500)
committerEvert Timberg <evert.timberg@gmail.com>
Sat, 5 Dec 2015 01:01:04 +0000 (20:01 -0500)
samples/line.html
src/core/core.controller.js

index 0647173b440eac559f98c48e7e3998f872e9df3a..00c0f499f00a93f59aa1581064fcda4e70eac677 100644 (file)
@@ -88,7 +88,7 @@
                     }
                 },
                 hover: {
-                    mode: 'label'
+                    mode: 'dataset'
                 },
                 scales: {
                     xAxes: [{
index 536f122ad1c78e6959122a86b2ec03f6e9ee988e..0edea25c640f26bcb69a2002bc8d34f9c3513e98 100644 (file)
                },
 
                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() {