Skip to content

feat(plot): addjgd graphics device integration#1706

Open
grantmcdermott wants to merge 2 commits into
REditorSupport:masterfrom
grantmcdermott:jgd
Open

feat(plot): addjgd graphics device integration#1706
grantmcdermott wants to merge 2 commits into
REditorSupport:masterfrom
grantmcdermott:jgd

Conversation

@grantmcdermott
Copy link
Copy Markdown

Closes #1679

Embeds the jgd VS Code extension code directly into vscode-R. Users only need the jgd R package installed on their system---and there's a graceful fallback otherwise---with no separate extension required.

Details

Adds a new r.plot.backend enum setting (auto | standard | httpgd | jgd). Default is auto, which tries the best available backend at runtime:

  1. If r.plot.useHttpgd is true → httpgd (ensures backwards compatability)
  2. Otherwise R-side hooks try jgd (if installed) → httpgd (if installed) → standard

This means users who install.packages("jgd") get interactive plots with zero configuration. (Note: I didn't want to presume that the jgd R package becomes a hard dependency, but am happy to adjust if others feel differently.)

Whenjgd is active:

  • Extension starts a Unix socket / named pipe server on activation
  • JGD_SOCKET and SESS_PLOT_BACKEND env vars are passed to R terminals
  • R's sess::register_hooks() sets jgd::jgd() as the default device
  • Plots stream as JSONL frames over the socket and render via Canvas2D in a dedicated webview panel
  • Plot history, navigation (prev/next/first/last), delete, resize, and PNG/SVG export all work

New files ported from the (currently standalone) jgd VSC extension:

  • src/plotViewer/jgdPlotHistory.ts — multi-session plot history with eviction and resize-after-delete protection
  • src/plotViewer/jgdSocketServer.ts — socket server managing concurrent R sessions and JSONL routing
  • src/plotViewer/jgdViewer.tsJgdManager + JgdViewer (Canvas2D webview with font metrics pipeline)

JGD-specific settings: r.plot.jgd.historyLimit, r.plot.jgd.exportWidth, r.plot.jgd.exportHeight, r.plot.jgd.exportDpi.

R-side changes: sess::connect() and sess::register_hooks() gain a use_jgd parameter. The hook priority is jgd > httpgd > standard, gated on package availability and JGD_SOCKET being set.

Backward compatibility: r.plot.useHttpgd is deprecated but still respected. When r.plot.backend is auto (default) and r.plot.useHttpgd is true, httpgd is forced. Existing Docker images and devcontainer configs will continue to work without changes.

Screenshots

Screenshot 2026-05-11 at 6 37 04 PM Screenshot 2026-05-11 at 6 37 39 PM

grantmcdermott and others added 2 commits May 11, 2026 17:22
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>
@randy3k
Copy link
Copy Markdown
Member

randy3k commented May 12, 2026

I haven't had a chance to use jgd, will let @renkun-ken review it. Anyway, great work!

@benz0li
Copy link
Copy Markdown
Contributor

benz0li commented May 12, 2026

Adds a new r.plot.backend enum setting (auto | standard | httpgd | jgd). Default is auto, which tries the best available backend at runtime:

👍

  1. If r.plot.useHttpgd is true → httpgd (ensures backwards compatability)
  2. Otherwise R-side hooks try jgd (if installed) → httpgd (if installed) → standard

The r.plot.backend enum setting (alone) is sufficient.
👉 I simply set "r.plot.backend": "httpgd" if I want to continue using httpgd.

IMHO the handling of setting r.plot.useHttpgd can be removed.

@benz0li
Copy link
Copy Markdown
Contributor

benz0li commented May 12, 2026

No handling = no tinkering (touching, deleting, etc.) of setting "r.plot.useHttpgd: true" in ~/.local/share/code-server/User/settings.json

If r.plot.useHttpgd is true → httpgd (ensures backwards compatability)

This actually breaks forward compatibility.


What I intend to do: My default ~/.local/share/code-server/User/settings.json for the R extension will be

{
  "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:

  • Newer versions of the R extension will interpret r.plot.backend (only) and use jgd (if installed).
    • If jgd is not installed: Fallback to httpgd (if installed); otherwise fallback to standard.
  • Older versions (≤ 2.8.8) of the R extension will interpret "r.plot.useHttpgd": true (only) and use httpgd.

@benz0li
Copy link
Copy Markdown
Contributor

benz0li commented May 12, 2026

@grantmcdermott I am just realising that my detailed comments at #1679 have caused more confusion than clarity.

Sorry about that.

Copy link
Copy Markdown
Contributor

@eitsupi eitsupi left a comment

Choose a reason for hiding this comment

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

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.

@grantmcdermott
Copy link
Copy Markdown
Author

grantmcdermott commented May 12, 2026

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:

  • RE: removing the r.plot.useHttpgd setting. I think we should follow the follow the mode (exemplified by data.table, etc. ) of soft deprecating functions for at least one release cycle, before fully removing them. Also, I think that this solution is more elegant i.t.o. of fallback than switching straight (only) to the auto enum setting. Remember: we're active and up to date users of vscode-R. I think most normies would be caught out if their settings suddenly stopped working altogether.
  • RE: auto default. I personally think jgd makes the most sense as the lighter (and now native) alternative, but will defer to the maintainers.
  • Similarly, yes, jgd is definitely a lighter dep than svglite (incl. no recursive sysdeps), but I'm not sure if they're a like-for-like swap in this context.

@benz0li
Copy link
Copy Markdown
Contributor

benz0li commented May 12, 2026

I think most normies would be caught out if their settings suddenly stopped working altogether.

If it is implemented as @eitsupi suggests, IMHO everything will continue to work as usual.

@eitsupi
Copy link
Copy Markdown
Contributor

eitsupi commented May 12, 2026

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.

@renkun-ken
Copy link
Copy Markdown
Member

Looks user-created R session does not respect r.plot.backend setting as is not reflected in the attach script.

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.

jgd as an alternative graphics device

5 participants