Skip to content

adjusts html canvas backend size using dpr #147

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

Merged
merged 2 commits into from
May 27, 2020

Conversation

Marius-Mueller
Copy link

Using get_bounding_client_rect to get the html canvas size causes the graph to be incorrectly sized if certain ccs styling is applied to the canvas.
For example, if you use css to scale a chart, get_bounding_client_rect will return the size to which the canvas will be scaled, not the actual size of the canvas. This causes the plot to be drawn with the wrong dimensions if the css scaling isn't set to the precise values which compensate for the dpr, either clipping off the canvas if it is scaled up, or only taking up part of the canvas if it is scaled down.

To address this issue, I use the device pixel ratio to properly adjust the size of the canvas for high DPI screens.

This is essential for resizing graphs without re-rendering them.

@codecov
Copy link

codecov bot commented May 27, 2020

Codecov Report

Merging #147 into master will decrease coverage by 0.05%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #147      +/-   ##
==========================================
- Coverage   67.53%   67.48%   -0.06%     
==========================================
  Files          53       53              
  Lines        5157     5160       +3     
==========================================
- Hits         3483     3482       -1     
- Misses       1674     1678       +4     
Impacted Files Coverage Δ
src/drawing/backend_impl/canvas.rs 0.00% <0.00%> (ø)
src/drawing/backend_impl/svg.rs 75.54% <0.00%> (-0.25%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 42dc17d...384bccc. Read the comment docs.

38 added a commit that referenced this pull request May 27, 2020
@38 38 merged commit 384bccc into plotters-rs:master May 27, 2020
@38
Copy link
Member

38 commented May 27, 2020

Thanks awesome, thanks so much!

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.

2 participants