Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix interaction on partially visible bar #9446

Merged
merged 1 commit into from Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/core.interaction.js
Expand Up @@ -166,7 +166,7 @@ function getNearestItems(chart, position, axis, intersect, useFinalPosition) {
}

const center = element.getCenterPoint(useFinalPosition);
if (!_isPointInArea(center, chart.chartArea, chart._minPadding)) {
if (!_isPointInArea(center, chart.chartArea, chart._minPadding) && !element.inRange(position.x, position.y, useFinalPosition)) {
return;
}
const distance = distanceMetric(position, center);
Expand Down
42 changes: 42 additions & 0 deletions test/fixtures/core.interaction/nearest-partial-bar.js
@@ -0,0 +1,42 @@
module.exports = {
config: {
type: 'bar',
data: {
labels: ['a', 'b', 'c'],
datasets: [
{
data: [220, 250, 225],
},
],
},
options: {
events: ['click'],
interaction: {
mode: 'nearest'
},
plugins: {
tooltip: true,
legend: false
},
scales: {
y: {
beginAtZero: false
}
}
}
},
options: {
spriteText: true,
canvas: {
width: 256,
height: 256
},
async run(chart) {
const point = {
x: chart.chartArea.left + chart.chartArea.width / 2,
y: chart.chartArea.top + chart.chartArea.height / 2,
};
await jasmine.triggerMouseEvent(chart, 'click', point);
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions test/fixtures/core.interaction/nearest-point-behind-scale.js
@@ -0,0 +1,45 @@
module.exports = {
config: {
type: 'scatter',
data: {
datasets: [{
data: [{x: 1, y: 1}, {x: 48, y: 1}]
}]
},
options: {
events: ['click'],
interaction: {
mode: 'nearest',
intersect: false
},
plugins: {
tooltip: true,
legend: false
},
scales: {
x: {
min: 5,
max: 50
},
y: {
min: 0,
max: 2
}
},
layout: {
padding: 50
}
}
},
options: {
spriteText: true,
canvas: {
width: 256,
height: 256
},
async run(chart) {
const point = chart.getDatasetMeta(0).data[0];
await jasmine.triggerMouseEvent(chart, 'click', {y: point.y, x: chart.chartArea.left});
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions test/specs/core.interaction.tests.js
@@ -1,7 +1,6 @@
// Tests of the interaction handlers in Core.Interaction

// Test the rectangle element
describe('Core.Interaction', function() {
describe('auto', jasmine.fixture.specs('core.interaction'));

describe('point mode', function() {
beforeEach(function() {
this.chart = window.acquireChart({
Expand Down