Skip to content

Commit a8b267f

Browse files
committed
[FIX] ChartRuntime: take devicePixelRatio in account to draw
The charts were not redrawn when the devicePixelRatio was altered and the homebrew chart (scorecard) was not scaled, which led to blurry charts on Mac screens for instance. closes #6071 Task: 4661712 Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
1 parent 88d92de commit a8b267f

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/components/figures/chart/chartJs/chartjs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class ChartJsComponent extends Component<Props, SpreadsheetChildEnv> {
3939
});
4040
useEffect(
4141
() => this.updateChartJs(deepCopy(this.chartRuntime)),
42-
() => [this.chartRuntime]
42+
() => [this.chartRuntime, window.devicePixelRatio]
4343
);
4444
}
4545

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class ScorecardChart extends Component<Props, SpreadsheetChildEnv> {
2020
useEffect(this.createChart.bind(this), () => {
2121
const canvas = this.canvas.el as HTMLCanvasElement;
2222
const rect = canvas.getBoundingClientRect();
23-
return [rect.width, rect.height, this.runtime, this.canvas.el];
23+
return [rect.width, rect.height, this.runtime, this.canvas.el, window.devicePixelRatio];
2424
});
2525
}
2626

src/helpers/figures/charts/scorecard_chart.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,10 @@ export class ScorecardChart extends AbstractChart {
187187

188188
export function drawScoreChart(structure: ScorecardChartConfig, canvas: HTMLCanvasElement) {
189189
const ctx = canvas.getContext("2d")!;
190-
canvas.width = structure.canvas.width;
191-
canvas.height = structure.canvas.height;
190+
const dpr = window.devicePixelRatio || 1;
191+
canvas.width = structure.canvas.width * dpr;
192+
canvas.height = structure.canvas.height * dpr;
193+
ctx.scale(dpr, dpr);
192194

193195
ctx.fillStyle = structure.canvas.backgroundColor;
194196
ctx.fillRect(0, 0, structure.canvas.width, structure.canvas.height);

0 commit comments

Comments
 (0)