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 _isPointInArea helper when no area is provided #9489

Merged
merged 1 commit into from Jul 28, 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
4 changes: 2 additions & 2 deletions src/helpers/helpers.canvas.js
Expand Up @@ -251,8 +251,8 @@ export function drawPoint(ctx, options, x, y) {
export function _isPointInArea(point, area, margin) {
margin = margin || 0.5; // margin - default is to match rounded decimals

return point && area && point.x > area.left - margin && point.x < area.right + margin &&
point.y > area.top - margin && point.y < area.bottom + margin;
return !area || (point && point.x > area.left - margin && point.x < area.right + margin &&
point.y > area.top - margin && point.y < area.bottom + margin);
}

export function clipArea(ctx, area) {
Expand Down
3 changes: 3 additions & 0 deletions test/specs/helpers.canvas.tests.js
Expand Up @@ -24,6 +24,9 @@ describe('Chart.helpers.canvas', function() {
});

describe('isPointInArea', function() {
it('should return true when no area is provided', function() {
expect(helpers._isPointInArea({x: 1, y: 1})).toBe(true);
});
it('should determine if a point is in the area', function() {
var isPointInArea = helpers._isPointInArea;
var area = {left: 0, top: 0, right: 512, bottom: 256};
Expand Down
2 changes: 1 addition & 1 deletion types/index.esm.d.ts
Expand Up @@ -1629,7 +1629,7 @@ export interface FontSpec {
export type TextAlign = 'left' | 'center' | 'right';

export interface VisualElement {
draw(ctx: CanvasRenderingContext2D): void;
draw(ctx: CanvasRenderingContext2D, area?: ChartArea): void;
inRange(mouseX: number, mouseY: number, useFinalPosition?: boolean): boolean;
inXRange(mouseX: number, useFinalPosition?: boolean): boolean;
inYRange(mouseY: number, useFinalPosition?: boolean): boolean;
Expand Down