Skip to content

Notebook plots rendered with an inconsistent size when devicePixelRatio > 0 (retina and other high-res monitors) #10825

Closed

Description

@jeffvroom

The IDE will use the browser's devicePixelRatio for rendering Notebook plots to scale up the width/height and dpi (see my comments on this related issue:
#7028).

But, the devicePixelRatio is not updated if the Plots plane is not visible or is zero width. This test here is checking the width and height of the plot's pane in the IDE. If one of them is 0, it won't set the size or the device pixel ratio. But we use the devicePixelRatio here to compute the image size to display when rendering a plot inline in an Rmd chunk. It has nothing to do with the plots pane size... so if the plots pane has never been made visible in this IDE session, the devicePixelRatio remains at the default of 1 and the notebook preview images are not scaled.

To reproduce, start the IDE on a retina display (or other monitor where the browser's window.devicePixelRatio > 1) with a layout where there's no plots pane visible in the initial setup. Render this chunk in an Rmd:

library(ggplot2)
ggplot(mtcars, aes(mpg, wt)) +   geom_point()

You should see it just less than 2" with a 96dpi screen.

Now just run this in the console to bring up the plots pane:

ggplot(mtcars, aes(mpg, wt)) + geom_point()

Now re-run the notebook chunk and see that it's 4X the size (8") (this assumes you are on a mac retina display). It would be 2X but we double-apply the scaling factor in that code linked above.

I think the fix for this particular bug is to always update the device pixel ration in set workbench metrics, even if the graphics device currently is zero width/height.

Activity

  1. mikebessuille commented on Mar 31, 2022

    @mikebessuille
    Contributor

    @timtmok , I think this is at least marginally related to other plot resolution / sizing issues you've been dealing with. If you think it's related and/or can easily fix it, we should try to address in SW.

  2. timtmok commented on Mar 31, 2022

    @timtmok
    Contributor

    I'll see what I can do. It's definitely in a different area of the code if Jeff's suggestion is the solution. There might be something in the GWT side to get the DPI but it appears that Jeff has pointed out that it's available in CPP and should be handled there to render the plot.

  3. mikebessuille commented on Mar 31, 2022

    @mikebessuille
    Contributor

    In that case I'm moving it to next release.

  4. netique commented on Sep 23, 2022

    @netique
    Contributor

    Consider also issue #4521.

  5. ronblum commented on Dec 2, 2022

    @ronblum
    Contributor

    Moving to Cherry Blossom, in order to verify that it's fixed by PR #12324. If it's not, we'll reassign it to the current milestone.

  6. jonvanausdeln commented on Feb 6, 2023

    @jonvanausdeln

    Verified on 2023.03.0-daily+280. The sizes appear to be correct on hi-resolution monitors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions