feat(plot): addjgd graphics device integration#1706
Conversation
Embed the JGD (JSON Graphics Device) VS Code extension directly into vscode-R so users only need the `jgd` R package for interactive, Canvas2D-rendered plots with history, navigation, and PNG/SVG export. Add `r.plot.backend` enum setting (auto/standard/httpgd/jgd) with backward compatibility for existing `r.plot.useHttpgd` configurations. The JGD socket server starts eagerly on activation when the backend is set to "jgd", passing JGD_SOCKET to R terminals via env vars. Closes REditorSupport#1679 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
In auto mode, the JGD socket server starts eagerly and R-side hooks try jgd > httpgd > standard based on package availability. Users who install the jgd R package get interactive plots with zero config. r.plot.useHttpgd: true still forces httpgd for backward compatibility. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
I haven't had a chance to use jgd, will let @renkun-ken review it. Anyway, great work! |
👍
The IMHO the handling of setting |
|
No handling = no tinkering (touching, deleting, etc.) of setting
This actually breaks forward compatibility. What I intend to do: My default {
"r.bracketedPaste": true,
"r.plot.useHttpgd": true,
"r.plot.backend": "auto",
"r.rterm.linux": "/usr/local/bin/radian",
"r.rterm.option": [
"--no-save",
"--no-restore"
],
"r.workspaceViewer.showObjectSize": true,
}This will lead to the following behaviour:
|
|
@grantmcdermott I am just realising that my detailed comments at #1679 have caused more confusion than clarity. Sorry about that. |
eitsupi
left a comment
There was a problem hiding this comment.
I haven't looked at the details, but based on the description, I think it would be better to do it this way.
- Delete old setting
r.plot.useHttpgd - In auto mode, the priority is set to httpgd, then jgd.
This means that in older environments where httpgd is installed, httpgd will continue to be used automatically.
I'm also wondering if we could remove the svglite backend for simplification.
At the very least, I don't think it should be a hard dependency of the sess package.
I believe jgd is lighter than svglite.
|
Thanks for the quick comments. I don't want to respond to everything until @renkun-ken has had a chance to review. But just quickly:
|
If it is implemented as @eitsupi suggests, IMHO everything will continue to work as usual. |
|
My understanding is that only httpgd offers features like thumbnail display for past plots, so it makes sense to prioritize httpgd over jgd in environments where httpgd is installed. Another point that caught my attention is that the tests don't seem to have been ported from the jgd repository. |
|
Looks user-created R session does not respect |
The attach script for user-created R sessions now passes use_httpgd, use_jgd, and JGD_SOCKET to sess::connect(), matching the managed terminal behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The attach script for user-created R sessions now passes use_httpgd, use_jgd, and JGD_SOCKET to sess::connect(), matching the managed terminal behavior. Also fixes terminal test to handle the new SESS_PLOT_BACKEND env var and config default resolution. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Thanks. Should be fixed now.
I think these only touch the Deno server, right? Porting them to VS Code is out-of-scope IMO. |
I meant these files. |
svglite usage is already guarded with requireNamespace() checks, so it doesn't need to be a hard dependency. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
A good catch. I'll port those (second one might be a bit trickier given we changed some things from the original extension, but it should work...) |
Port unit tests from the standalone JGD extension, adapted to the project's mocha/assert test style. Also moves svglite from Imports to Suggests in sess since its usage is already guarded with requireNamespace(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
if From the perspective of current capabilities: httpgd > jgd > svglite > png From the perspective of hard dependencies, footprints, things to be loaded into the user session: png > jgd > svglite > httpgd From a balanced view of both perspectives as well as native extension support, jgd is a good choice I guess? From user-side, if loading a ton of hard dependencies is not a big deal, choosing the currently most capable installed backend might make more sense. From the status quo, I guess a good proportion of existing users use httpgd as a suggested approach to view graphics, with their Considering all these, I think it is fair to make jgd > httpgd as we don't want to introduce a heavier dependency for user workflow by default. The only thing that might be a bit drawback is that do we think jgd has reached a level of stability that could be released/set by default if installed? |
|
In my opinion, if httpgd is removed from CRAN again (which is likely to happen in the not-too-distant future), leaving the |
Closes #1679
Embeds the jgd VS Code extension code directly into
vscode-R. Users only need thejgdR package installed on their system---and there's a graceful fallback otherwise---with no separate extension required.Details
Adds a new
r.plot.backendenum setting (auto|standard|httpgd|jgd). Default isauto, which tries the best available backend at runtime:r.plot.useHttpgdistrue→httpgd(ensures backwards compatability)jgd(if installed) →httpgd(if installed) →standardThis means users who
install.packages("jgd")get interactive plots with zero configuration. (Note: I didn't want to presume that thejgdR package becomes a hard dependency, but am happy to adjust if others feel differently.)When
jgdis active:JGD_SOCKETandSESS_PLOT_BACKENDenv vars are passed to R terminalssess::register_hooks()setsjgd::jgd()as the default deviceMain files
I've added three new files to
src/plotViewer/(ported from from the currently standalonejgdVSC extension):jgdPlotHistory.ts— multi-session plot history with eviction and resize-after-delete protectionjgdSocketServer.ts— socket server managing concurrent R sessions and JSONL routingjgdViewer.ts—JgdManager+JgdViewer(Canvas2D webview with font metrics pipeline)UX
JGD-specific settings:
r.plot.jgd.historyLimitr.plot.jgd.exportWidthr.plot.jgd.exportHeightr.plot.jgd.exportDpi.R-side changes:
sess::connect()andsess::register_hooks()gain ause_jgdparameter. The hook priority isjgd>httpgd>standard, gated on package availability andJGD_SOCKETbeing set.Backward compatibility:
r.plot.useHttpgdis deprecated but still respected. Whenr.plot.backendisauto(default) andr.plot.useHttpgdistrue, httpgd is forced. Existing Docker images and devcontainer configs will continue to work without changes.Screenshots