Skip to content

[FIX] ChartRuntime: take devicePixelRatio in account #6072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 7 additions & 0 deletions src/components/figures/chart/chartJs/chartjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ export class ChartJsComponent extends Component<Props, SpreadsheetChildEnv> {
this.currentRuntime = runtime;
}
});
useEffect(
() => {
this.currentRuntime = this.chartRuntime;
this.updateChartJs(deepCopy(this.currentRuntime));
},
() => [window.devicePixelRatio]
);
}

private createChart(chartData: ChartConfiguration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class GaugeChartComponent extends Component<Props, SpreadsheetChildEnv> {
() => {
const canvas = this.canvas.el as HTMLCanvasElement;
const rect = canvas.getBoundingClientRect();
return [rect.width, rect.height, this.runtime, this.canvas.el];
return [rect.width, rect.height, this.runtime, this.canvas.el, window.devicePixelRatio];
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/figures/chart/scorecard/chart_scorecard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ScorecardChart extends Component<Props, SpreadsheetChildEnv> {
useEffect(this.createChart.bind(this), () => {
const canvas = this.canvas.el as HTMLCanvasElement;
const rect = canvas.getBoundingClientRect();
return [rect.width, rect.height, this.runtime, this.canvas.el];
return [rect.width, rect.height, this.runtime, this.canvas.el, window.devicePixelRatio];
});
}

Expand Down
6 changes: 4 additions & 2 deletions src/helpers/figures/charts/gauge_chart_rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ interface Segment {

export function drawGaugeChart(canvas: HTMLCanvasElement, runtime: GaugeChartRuntime) {
const canvasBoundingRect = canvas.getBoundingClientRect();
canvas.width = canvasBoundingRect.width;
canvas.height = canvasBoundingRect.height;
const dpr = window.devicePixelRatio || 1;
canvas.width = dpr * canvasBoundingRect.width;
canvas.height = dpr * canvasBoundingRect.height;
const ctx = canvas.getContext("2d")!;
ctx.scale(dpr, dpr);

const config = getGaugeRenderingConfig(canvasBoundingRect, runtime, ctx);
drawBackground(ctx, config);
Expand Down
9 changes: 6 additions & 3 deletions src/helpers/figures/charts/scorecard_chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,12 @@ export class ScorecardChart extends AbstractChart {

export function drawScoreChart(structure: ScorecardChartConfig, canvas: HTMLCanvasElement) {
const ctx = canvas.getContext("2d")!;
canvas.width = structure.canvas.width;
const availableWidth = canvas.width - DEFAULT_CHART_PADDING;
canvas.height = structure.canvas.height;
const dpr = window.devicePixelRatio || 1;

canvas.width = dpr * structure.canvas.width;
canvas.height = dpr * structure.canvas.height;
ctx.scale(dpr, dpr);
const availableWidth = structure.canvas.width - DEFAULT_CHART_PADDING;

ctx.fillStyle = structure.canvas.backgroundColor;
ctx.fillRect(0, 0, structure.canvas.width, structure.canvas.height);
Expand Down