Skip to content
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: Chart shrinking uncontrollably on browser zoom (#11089) #11132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gbaron
Copy link
Contributor

@gbaron gbaron commented Feb 11, 2023

My comment on the original issue contains the full analysis (scenario, root cause, how to reproduce):
#11089 (comment)

The functions retinaScale and getMaximumSize are full of minor details and multiple flows.
Hence, this area in the code is quite sensitive IMHO.
I'm making an attempt to fix the issue with minimum side effects.

Fixes #11089.

@@ -200,7 +200,7 @@ export function getMaximumSize(
const maintainHeight = bbWidth !== undefined || bbHeight !== undefined;

if (maintainHeight && aspectRatio && containerSize.height && height > containerSize.height) {
height = containerSize.height;
height = Math.round(containerSize.height);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if round1 would be enough to fix the issue..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or if removing the width rounding too would sctually fix it :)

@lincolnthree
Copy link

Really need this fix!

@Kebechet
Copy link

Kebechet commented Jul 20, 2023

This fix is really needed ! My chart on Android browser shrinks all the time.

EDIT:
I have tested this fix on Android, iOS and Windows and it works correctly.
I have Chart.js built with this fix here

Kebechet added a commit to Kebechet/Chart.js that referenced this pull request Jul 20, 2023
@garybutton
Copy link

Bumping this one, also really in need of the fix! 🙏

@mudassirzr
Copy link

mudassirzr commented Sep 19, 2023

Badly waiting for this fix, can we get this one merged and released soon please?

@fly74
Copy link

fly74 commented Sep 19, 2023

What is blocking the thing since February?

@etimberg
Copy link
Member

@fly74 this hasn't been merged because this is very risky code to touch and this is an issue that the bulk of our users are not experiencing. While this fix solves this specific issue, there are no guarantees that it doesn't break other user's charts or introduces the same problem in other ways. @kurkle already commented that round1 instead of round should likely be used here since it will round to a single decimal place and I think that change would align better with what we've done elsewhere.

@fly74
Copy link

fly74 commented Sep 20, 2023

@etimberg I know that the use of HiDPI Monitors is not common for everybody but 4k with a scale is the future. This is resulting that the browser is choosing a zoom value which is sometimes like 116% or other what is resulting is this rounding issue. Why is it dangerous to round?

@etimberg
Copy link
Member

@fly74 the risk is that we run into a scenario like this hence why we're reluctant to make a ton of changes to this code

  1. Round the width
  2. Height changes slightly
  3. Scrollbar removed from container
  4. Width increases so height is increased
  5. Scrollbar comes back
  6. Infinite loop

If we merge this, we're rounding the height. From what I recall when we last ran into this, rounding to the nearest integer was much more likely to cause the scrollbar problem hence rounding to a single decimal place where our testing showed that it was less likely to occur.

@lincolnthree
Copy link

@fly74 the risk is that we run into a scenario like this hence why we're reluctant to make a ton of changes to this code

A thought. Are you open to adding a configuration parameter or allowing a custom/passthrough rounding function to modify this behavior?

That way individual users could extend the behavior to meet their specific requirements? As it stands right now, we're in this situation you described with the existing functionality. It's just the chart that's freaking out, not the scrollbars (we have them disabled via CSS.)

@fly74
Copy link

fly74 commented Sep 23, 2023

@lincolnthree that would really a perfect solution for everybody who are waiting to get it work. Let's try it with a config parameter. Great idea 👌!

@etimberg
Copy link
Member

@lincolnthree I would be open to having a config option for this + something in the docs discussing this problem and potential solutions.

@LeeLenaleee @kurkle opinions?

@gbaron
Copy link
Contributor Author

gbaron commented Jan 13, 2024

@etimberg with regards to config option, what did you have in mind?

@etimberg
Copy link
Member

@gbaron could be something like roundContainerHeightDuringResize which defaults to false. I'd probably put that under the layout options https://www.chartjs.org/docs/latest/configuration/layout.html

paulovieira added a commit to paulovieira/Chart.js that referenced this pull request Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chart shrinking uncontrollably on browser zoom
8 participants