fix: draw over bounds

This commit is contained in:
2026-09-12 11:22:27 +02:00
parent 19c3aedf80
commit 0f198692ad
3 changed files with 31 additions and 12 deletions
+8 -8
View File
@@ -33,7 +33,7 @@ export interface LinearGraphProps {
yMin: number;
yMax: number;
yStep?: number;
/** 'log' requires xMin > 0. Ticks are drawn at 1/2/5-per-decade mantissas, with decade (power-of-10) lines highlighted. */
/** 'log' requires xMin > 0. */
xScale?: AxisScale;
/** 'log' requires yMin > 0. */
yScale?: AxisScale;
@@ -150,7 +150,7 @@ export const LinearGraph = forwardRef<LinearGraphHandle, LinearGraphProps>(funct
const topBase = cq.h * 3;
const rightBase = cq.w * 5;
const bottomBase = cq.h * 4;
const leftBase = cq.w * 2;
const leftBase = cq.w * 7;
const xLabelSpace = xLabel ? cq.h * 7 : 0;
const yLabelSpace = yLabel ? Math.min(cq.w * 6, 24) : 0;
@@ -221,7 +221,7 @@ export const LinearGraph = forwardRef<LinearGraphHandle, LinearGraphProps>(funct
ctx.clearRect(0, 0, cssW, cssH);
const plot = {
x: pad.left + cq.w * 2,
x: pad.left,
y: pad.top,
width: Math.max(1, cssW - pad.left - pad.right - cq.w * 2),
height: Math.max(1, cssH - pad.top - pad.bottom),
@@ -271,14 +271,14 @@ export const LinearGraph = forwardRef<LinearGraphHandle, LinearGraphProps>(funct
ctx.fillRect(plot.x, plot.y, plot.width, plot.height);
}
const clipPad = 2;
const borderInset = 1; // Avoid clipping outside graph bounds
ctx.save();
ctx.beginPath();
ctx.rect(
plot.x - clipPad,
plot.y - clipPad,
plot.width + clipPad * 2,
plot.height + clipPad * 2
plot.x + borderInset,
plot.y + borderInset,
plot.width - borderInset * 2,
plot.height - borderInset * 2
);
ctx.clip();