-
Notifications
You must be signed in to change notification settings - Fork 12k
Attempt fixing charts shrinking on certain zoom values in Chrome #12097
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
Conversation
e40ea53 to
1c42603
Compare
|
Thanks for the fix! @LeeLenaleee any chance you could release a new version with this fix? We have users that are complaining about this and would love to pull this in. |
|
These changes appear to have some unintended side effects; after upgrading from Chart.js 4.5.0 to 4.5.1, we started encountering errors in our code. Within HTMLCanvasElement's In our case, this resulted in extra resize and update events during chart initialization that some custom in-house plugins weren't prepared to handle. This is a potential bug within our custom plugins, so I can address that, but having guaranteed extra resize and update events (because If preserving decimals within the chart's internal width/height is necessary to prevent bugs, then I assume that the fix is to still truncate to int when comparing to the canvas width/height. |
|
Hm.. I'll have to test whether using e.g. Is the only prerequisite for the multiple resize events a fractional display scaling ratio? If not, I would appreciate a minimal reproduction example (: |
|
Thanks, @bojidar-bg. I should have mentioned - we're seeing this with fractional width / height (due to some percentage-based flex layouts). We haven't touched the scaling ratio. See https://codepen.io/joshkel/pen/azdjLGZ. With Chart.js 4.5.0, you should see one I really think you want |
As a result of chartjs#12097, the HTMLCanvasElement's `width` and `height` (which are always integers - see [MDN][1]) may be compared to fractional `deviceWidth` and `deviceHeight`, resulting in extra resize and update events being fired. This PR rounds the dimensions for purposes of comparing to the canvas element's, which should put the behavior closer to Chart.js 4.5.0 and earlier. I've tested this against chartjs#11224 and against my own code (which was generating errors due to an interaction between these extra events and some internal plugins), and it seems to work, but other testing and feedback is welcome. [1]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement#instance_properties
As a result of chartjs#12097, the HTMLCanvasElement's `width` and `height` (which are always integers - see [MDN][1]) may be compared to fractional `deviceWidth` and `deviceHeight`, resulting in extra resize and update events being fired. This PR rounds the dimensions for purposes of comparing to the canvas element's, which should put the behavior closer to Chart.js 4.5.0 and earlier. I've tested this against chartjs#11224, my own code (which was generating errors due to an interaction between these extra events and some internal plugins), and https://codepen.io/joshkel/pen/azdjLGZ, and it seems to work. [1]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement#instance_properties
|
Hi @bojidar-bg My app crashes when the zoom level is different than 100%. Different from @joshkel who uses some custom in-house plugins, we use the official plugin After debugging, I pinpointed the issue to Moreover, the extra render causes also another issue: None of the problems exist if the zoom level is 100% so very likely to be related to this discussion and zoom levels. |
|
@kk-adi Mm... mind opening an issue on https://github.com/chartjs/chartjs-plugin-datalabels itself? I can try to look at it in the coming week, but it'd be nice if this PR's discussion does not become an issue list (: |
|
@bojidar-bg sure, I'll open an issue there. I just wanted to have it also here because it's closely related to the zoom values that were changed in this PR |
This is an attempt at fixing #11224 and possibly #12076.
I managed to reproduce the issue with the steps from #11224 on Chromium 138 on Linux, but it is very sensitive to screen width so I'm not sure if I caught all cases. At any rate, with the submitted fix, I'm no longer able to reproduce the issue myself.
Would appreciate if someone with Chrome on Windows could try reproducing the issue with the steps from #12076 (comment) and this PR.