Skip to content

Commit e6fb51d

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. closes #8502 Task: 6072348 X-original-commit: ff534e9 Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
1 parent e12baf0 commit e6fb51d

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

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
}

src/helpers/figures/charts/scorecard_chart.ts

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

384384
export function drawScoreChart(
385385
structure: ScorecardChartConfig,
386-
canvas: HTMLCanvasElement | OffscreenCanvas
386+
canvas: HTMLCanvasElement | OffscreenCanvas,
387+
zoom: number = 1
387388
) {
388389
const ctx = canvas.getContext("2d") as Canvas2DContext;
389390
if (!ctx) {
390391
throw new Error("Unable to retrieve 2D context from canvas");
391392
}
392393
const dpr = typeof globalThis.devicePixelRatio === "number" ? globalThis.devicePixelRatio : 1;
393394

394-
canvas.width = dpr * structure.canvas.width;
395-
canvas.height = dpr * structure.canvas.height;
396-
ctx.scale(dpr, dpr);
395+
canvas.width = dpr * structure.canvas.width * zoom;
396+
canvas.height = dpr * structure.canvas.height * zoom;
397+
ctx.scale(dpr * zoom, dpr * zoom);
397398
const availableWidth = structure.canvas.width - CHART_PADDING;
398399

399400
ctx.fillStyle = structure.canvas.backgroundColor;

0 commit comments

Comments
 (0)