The solution is to make a larger canvas, say, 800x800 and put it into that 400x400 space.
Here is an example, using that MDN code, with a 400x400 canvas (red) next to a 800x800 canvas (blue). CSS is forcing them both to appear the same 400x400 size. The blue one should look sharper on most devices.
Note how the 800x800 canvas needs to be scaled double with ctx2.scale(2,2) so that it appears correct.
https://codepen.io/simonsarris/pen/eYexbOb
Pixel ratio is variable (window.devicePixelRatio), so this canvas pixel density is something you'll want to programmatically set for each user.
https://github.com/leeoniya/uPlot/blob/190134aa844cfa2a0c052...
everything stays crisp even as you browser-zoom. e.g. https://leeoniya.github.io/uPlot/demos/area-fill.html
Not everyone's canvas is filling the window.
https://codepen.io/SeanMcBeth/pen/QWOoLNX
Throw a check in there to make sure the native dimensions actually did change so you don't needlessly redraw. Debounce it with setTimeout if you're super worried about people waggling their windows around or whatever.
Or does anyone here happen to know a way ?
I'm glad to have solved your mystery!
It still helps when you do your canvas at 2x rather than just at 1x. But if you're looking for best-fidelity rather than better-fidelity, duly noted.
It turns out it was very obviously exactly what you described. You basically have to double the resolution to get it to look decent on retina and 4k screens. Once I found this out I was over the moon!
(On a related note, colouring looks way off on the HTML5 target compared to native ones, and I spent an embarassing number of hours manually brute-forcing a shader to make everything look similar.
Oh, and sound sucks in the browser.
Oh, and Safari sucks. Seriously, it just sucks. The amount of hacks I put in place to workaround its egregious limitations, particularly regarding canvas operations is insane.)
Whenever I'm trying to draw curved lines, I always have issues with how they look, they seem to look low quality/pixelated.
Like here: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRende...
In the most basic examples they seem to always produce curves like this.
Sorry I don't have more specifics since it's a project I'm not actively working on right now but it was a spine that I never removed.
If the questions is too broad, please let me know!