Skip to content

Images through BackgroundColor low-res on high dpi screens #9862

@vin-ni

Description

@vin-ni

Expected Behavior

On high dpi screens, a passed canvas as BackgroundColor scales correctly and is as sharp as the graphs.

Current Behavior

On high dpi screens, a passed canvas as BackgroundColor doesn't scale correctly thus being displayed too largen on devicePixelRatio screens > 1.

Possible Solution

I tried a lot of thing like scaling the transfer canvas with ctx.scale(0.5, 0.5), but nothing seemed to work.
Not passing the pixelDeviceRatio is not an option, as the image gets blurry.

Steps to Reproduce

Bug visible on this codepen: https://codepen.io/Vin-ni/pen/zYdMRqy
And here's also a simple version with just one pattern: https://codepen.io/Vin-ni/pen/LYjXqyP

Look especially at line 11, where the pixel device ratio is set to the drawing canvas. When set to 1 programatically, the pattern has the same scale on every device, but logically gets more blurry the higher the dpr.

Context

The preparePattern code seems a bit complicated, but what it is doing is placing an image at the correct position of the donut part, by creating and offsetting a pattern, so the full image is just embracing the visible part of the donut. That code works well, but the scaling of the backgroundColor is not translated to the dpi.

I tried to turn off the "responsive: true" in the options, and this actually fixed the issue, if I hardcode the canvas html element to be too large and scale it down with css, but this messes up the hover states unfortunately. So not really an option. I believe there must be an issue with the resize function, that doesn't translate the hdpi screen scaling to the passed canvas.

Simple Examples:
Screendeviceratio = 1
Screenshot 2021-11-16 at 11 40 04

Screendeviceratio = 2
Screenshot 2021-11-16 at 11 40 20

Complex Examples:
Screendeviceratio = 1
Screenshot 2021-11-16 at 02 02 58

Screendeviceratio = 2
Screenshot 2021-11-16 at 02 03 39

Screendeviceratio = 3 + not multiplying by sdr factor => works but blurry
IMG_0158

Environment

The bug happens with the latest version on any browser desktop and mobile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions