Skip to content

Commit

Permalink
Fix tooltip for 'dataset' mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Jan 21, 2020
1 parent a1c2dd6 commit 6bd697f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
4 changes: 0 additions & 4 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -919,10 +919,6 @@ class Chart {
if (mode === 'dataset') {
meta = this.getDatasetMeta(items[0].datasetIndex);
meta.controller['_' + prefix + 'DatasetHoverStyle']();
for (i = 0, ilen = meta.data.length; i < ilen; ++i) {
meta.controller[prefix + 'HoverStyle'](meta.data[i], items[0].datasetIndex, i);
}
return;
}

for (i = 0, ilen = items.length; i < ilen; ++i) {
Expand Down
7 changes: 6 additions & 1 deletion src/core/core.interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,12 @@ export default {
let items = options.intersect ? getIntersectItems(chart, position, axis) : getNearestItems(chart, position, axis);

if (items.length > 0) {
items = [{datasetIndex: items[0].datasetIndex}]; // when mode: 'dataset' we only need to return datasetIndex
const datasetIndex = items[0].datasetIndex;
const data = chart.getDatasetMeta(datasetIndex).data;
items = [];
for (let i = 0; i < data.length; ++i) {
items.push({element: data[i], datasetIndex, index: i});
}
}

return items;
Expand Down
16 changes: 8 additions & 8 deletions test/specs/core.interaction.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ describe('Core.Interaction', function() {
y: point.y
};

var elements = Chart.Interaction.modes.dataset(chart, evt, {intersect: true});
expect(elements).toEqual([{datasetIndex: 0}]);
var elements = Chart.Interaction.modes.dataset(chart, evt, {intersect: true}).map(item => item.element);
expect(elements).toEqual(meta.data);
});

it ('should return an empty array if nothing found', function() {
Expand Down Expand Up @@ -283,8 +283,8 @@ describe('Core.Interaction', function() {
y: chart.chartArea.top
};

var elements = Chart.Interaction.modes.dataset(chart, evt, {axis: 'x', intersect: false});
expect(elements).toEqual([{datasetIndex: 0}]);
var elements = Chart.Interaction.modes.dataset(chart, evt, {axis: 'x', intersect: false}).map(item => item.element);
expect(elements).toEqual(chart.getDatasetMeta(0).data);
});

it ('axis: y gets correct items', function() {
Expand All @@ -297,8 +297,8 @@ describe('Core.Interaction', function() {
y: chart.chartArea.top
};

var elements = Chart.Interaction.modes.dataset(chart, evt, {axis: 'y', intersect: false});
expect(elements).toEqual([{datasetIndex: 1}]);
var elements = Chart.Interaction.modes.dataset(chart, evt, {axis: 'y', intersect: false}).map(item => item.element);
expect(elements).toEqual(chart.getDatasetMeta(1).data);
});

it ('axis: xy gets correct items', function() {
Expand All @@ -311,8 +311,8 @@ describe('Core.Interaction', function() {
y: chart.chartArea.top
};

var elements = Chart.Interaction.modes.dataset(chart, evt, {intersect: false});
expect(elements).toEqual([{datasetIndex: 1}]);
var elements = Chart.Interaction.modes.dataset(chart, evt, {intersect: false}).map(item => item.element);
expect(elements).toEqual(chart.getDatasetMeta(1).data);
});
});
});
Expand Down

0 comments on commit 6bd697f

Please sign in to comment.