mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Fix _isPointInArea helper when no area is provided (#9489)
This commit is contained in:
parent
c0d8dd9d05
commit
1c837a9c12
@ -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) {
|
||||
|
||||
@ -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};
|
||||
|
||||
2
types/index.esm.d.ts
vendored
2
types/index.esm.d.ts
vendored
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user