Skip to content

Commit

Permalink
Fix _isPointInArea helper when no area is provided (#9489)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Jul 28, 2021
1 parent c0d8dd9 commit 1c837a9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
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

0 comments on commit 1c837a9

Please sign in to comment.