Skip to content

Commit ae03e4e

Browse files
committed
[FIX] zoom: scorecard chart rendering with zoom
The scorecards were blurry when zooming a sheet. We were not scaling their canvas properly according to the zoom level. Task: 6072348
1 parent 83c8c46 commit ae03e4e

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

packages/o-spreadsheet-engine/src/helpers/figures/charts/scorecard_chart.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,17 +310,18 @@ type Canvas2DContext = CanvasRenderingContext2D | OffscreenCanvasRenderingContex
310310

311311
export function drawScoreChart(
312312
structure: ScorecardChartConfig,
313-
canvas: HTMLCanvasElement | OffscreenCanvas
313+
canvas: HTMLCanvasElement | OffscreenCanvas,
314+
zoom: number = 1
314315
) {
315316
const ctx = canvas.getContext("2d") as Canvas2DContext;
316317
if (!ctx) {
317318
throw new Error("Unable to retrieve 2D context from canvas");
318319
}
319320
const dpr = typeof globalThis.devicePixelRatio === "number" ? globalThis.devicePixelRatio : 1;
320321

321-
canvas.width = dpr * structure.canvas.width;
322-
canvas.height = dpr * structure.canvas.height;
323-
ctx.scale(dpr, dpr);
322+
canvas.width = dpr * structure.canvas.width * zoom;
323+
canvas.height = dpr * structure.canvas.height * zoom;
324+
ctx.scale(dpr * zoom, dpr * zoom);
324325
const availableWidth = structure.canvas.width - CHART_PADDING;
325326

326327
ctx.fillStyle = structure.canvas.backgroundColor;

src/components/figures/chart/scorecard/chart_scorecard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ export class ScorecardChart extends Component<Props, SpreadsheetChildEnv> {
4343
getZoomedRect(1 / zoom, canvas.getBoundingClientRect()),
4444
this.runtime
4545
);
46-
drawScoreChart(config, canvas);
46+
drawScoreChart(config, canvas, zoom);
4747
}
4848
}

0 commit comments

Comments
 (0)