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

Add other formats for plot save #311

Merged
merged 4 commits into from
Apr 16, 2024
Merged

Add other formats for plot save #311

merged 4 commits into from
Apr 16, 2024

Conversation

timtmok
Copy link
Contributor

@timtmok timtmok commented Apr 12, 2024

Address posit-dev/positron#2657

UI PR: posit-dev/positron#2729

During my testing, I had trouble saving SVG until I installed XQuartz. I'm not sure if R users will find this to be a problem on Mac. It seems that it's not common to use grDevices::svg() to save as SVG.

Support PNG, SVG, PDF, and JPEG
Copy link
Contributor

@DavisVaughan DavisVaughan left a comment

Choose a reason for hiding this comment

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

I'm not really an expert on these but this seems reasonable to me

Comment on lines +36 to +37
/// The requested plot format
pub format: String,
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel somewhat strongly that this should be an enum of the 4 currently valid format types! I think that would make things more type safe and clear (even if we have to convert to string when eventually handing off to R, that's totally fine)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be really nice to add as another task. I'll have to update the comms definition and the Python extension after regenerating. I'll put up another PR for it.

crates/ark/src/modules/positron/graphics.R Outdated Show resolved Hide resolved
),
"svg" = grDevices::svg(
filename = filepath,
width = (width / 72),
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you mind adding a comment above the switch( call about why we do / 72?

height = height,
res = res,
type = type
switch(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the exact same switch( as above?

If so, can you extract the repeated switch( statement out into a helper, like renderPlotWithDevice() or something

crates/ark/src/plots/graphics_device.rs Outdated Show resolved Hide resolved
@timtmok timtmok merged commit 7def77c into main Apr 16, 2024
1 check passed
@timtmok timtmok deleted the save-plot-formats branch April 17, 2024 18:02
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