Size plots appropriately in R notebooks and Quarto inline output#12539
Size plots appropriately in R notebooks and Quarto inline output#12539
Conversation
|
E2E Tests 🚀 |
nstrayer
left a comment
There was a problem hiding this comment.
This is a huge QOL improvement! Thank you!
Just a couple code questions but nothing blocking at all!
| * Returns dimensions used by the kernel to size outputs (e.g. plot | ||
| * rendering). Uses the same formula as QuartoOutputViewZone._getWidth(). | ||
| */ | ||
| private _getEditorLayoutMetadata(): Record<string, unknown> | undefined { |
There was a problem hiding this comment.
Is this a general Record<string, unknown> type so that it catches problems when future metadata is added? In which case I wonder if using satisfies Record<string, unknown> on the return would help while letting you keep nice return types for using the method?
There was a problem hiding this comment.
A good point. After reviewing this I think the best change is to use a type for this layout metadata and then spread it right before we send it to the kernel! That's done here: fee654a
| }; | ||
| } | ||
|
|
||
| // Fall back to Positron notebook instances. |
There was a problem hiding this comment.
I wonder if we should build this into the notebook editor interface to help get rid of some of these implementation details.
There was a problem hiding this comment.
Yeah, it does feel weird to reach into the editor's DOM for these values. I've moved this to the editor itself: efe746e
This change adds metadata to execution requests so that it is possible for kernels to size plots to fit the viewport/DPI.
For Quarto, we add cell options (such as
fig-widthandfig-height) to the execution metadata; for both Quarto inline outputs and Jupyter editors, we add the width of the output field and the device pixel ratio to the execution request.In notebooks, this means that your plots render crisply on Retina displays and are sized appropriately to your viewport:
In Quarto inline outputs, this means that figure width/height are respected, too, so you get a preview with the correct aspect ratio:
Requires posit-dev/ark#1119
Requires posit-dev/qa-example-content#116
Related to quarto-dev/quarto#938
Addresses #8104
Addresses #12150
Release Notes
New Features
fig-widthandfig-heightoptions (Quarto Inline Output: Respect figure options for plots #12150)Bug Fixes
QA Notes
This PR doesn't attempt to size Python plots, though it takes the first step towards doing so by adding the right metadata. I added a hidden magic you can use to see what is being sent to Python:
The Ark equivalent is
.ps.internal(active_request()).It also doesn't apply to the Plots pane, just notebook-style execution. We'll need to wait for a new Quarto extension to do that (quarto-dev/quarto#938).
Test tags:
@:quarto@positron-notebooks@notebooks