Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/helpers/helpers.canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,15 @@ export function _isPointInArea(
}

export function clipArea(ctx: CanvasRenderingContext2D, area: TRBL) {
if (!ctx) return;
ctx.save();
ctx.beginPath();
ctx.rect(area.left, area.top, area.right - area.left, area.bottom - area.top);
ctx.clip();
}

export function unclipArea(ctx: CanvasRenderingContext2D) {
if (!ctx) return;
ctx.restore();
}

Expand Down
10 changes: 10 additions & 0 deletions src/helpers/helpers.dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ export function getRelativePosition(
}

const {canvas, currentDevicePixelRatio} = chart;
// Guard against null canvas to prevent ownerDocument crash
if (!canvas) {
return {x: 0, y: 0};
}

const style = getComputedStyle(canvas);
const borderBox = style.boxSizing === 'border-box';
const paddings = getPositionedStyle(style, 'padding');
Expand Down Expand Up @@ -166,6 +171,11 @@ export function getMaximumSize(
bbHeight?: number,
aspectRatio?: number
): { width: number; height: number } {
// Guard against null canvas to prevent ownerDocument crash
if (!canvas) {
return {width: 0, height: 0};
}

const style = getComputedStyle(canvas);
const margins = getPositionedStyle(style, 'margin');
const maxWidth = parseMaxStyle(style.maxWidth, canvas, 'clientWidth') || INFINITY;
Expand Down