Fix _isPointInArea helper when no area is provided (#9489)

This commit is contained in:
Jukka Kurkela 2021-07-28 14:57:35 +03:00 committed by GitHub
parent c0d8dd9d05
commit 1c837a9c12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 3 deletions

View File

@ -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) {

View File

@ -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};

View File

@ -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;