-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
fix: avoid resize loop when browser zoom is set to 90% #10971
Conversation
…elRatio the assignment would cause the size to reduce by 1px. Since it's called from the ResizeObserver it will be stuck in a loop that constantly reduce the size of the chart and canvas.
Should resolve #10951. |
The other scenario is here: #9015 Would you be able to consider that case here too? I'd think the fix is actually something else. |
I'm a little worried about this even with a test added. Would it be better to consider reverting the PR that broke this in v4? |
Reading #9015:
Based on my experiments, I suspect that the current implementation doesn't always achieve this.
When Zoom is 90%, |
In general, there are a few different ways to fix this issue. The reason I choose this change is that I couldn't think of a reason for the assignment back to Same as above, the current code is effectively setting
I couldn't figure out a reason to do that. Curious if someone can think of one. @etimberg I agree with your concerns. I'll keep digging. |
I think we should skip a step, basically: chart.height = Math.floor(maxSize.height);
chart.width = Math.floor(maxSize.width);
canvas.height = Math.floor(maxSize.height * pixelRatio);
canvas.width = Math.floor(maxSize.width * pixelRatio); But my take on what really happens here is (edited):
One fix could be to apply some rounding to the aspect ratio here (but does not feel correct): Chart.js/src/core/core.controller.js Line 223 in ae264e1
|
…s of pixelRatio the assignment would cause the size to reduce by 1px. Since it's called from the ResizeObserver it will be stuck in a loop that constantly reduce the size of the chart and canvas." This reverts commit ed7a348.
@kurkle, After updating the implementation I noticed a different issue. Chart-Shrinks.movAfter some exploration, I noticed that I noticed Chart.js/src/helpers/helpers.dom.ts Line 191 in ae264e1
Chart.js/src/helpers/helpers.dom.ts Line 193 in ae264e1
The same example after removing Removed-Math-Floor.movI did my best to update the code changes and add a test accordingly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gbaron thank you for the good investigation and spent time!
…e retinaScale function." This reverts commit 23525ab.
@kurkle Nice catch! |
Following up on the discussion in #10951
I opened this PR to demonstrate the issue and hopefully fix it.
The PR includes a new test that reproduces the issue.
The test currently fails with the following error:
@kurkle - is it safe to assume that
helpers.retinaScale
shouldn't change the chart size or did I misunderstand the function purpose?