Skip to content

Phase 27: Screenshot, the spatial view as a high-resolution PNG - #425

Merged
prete merged 4 commits into
mainfrom
claude/paper-figure-export-resolution-70299d
Nov 24, 2026
Merged

prete merged 4 commits into
mainfrom
claude/paper-figure-export-resolution-70299d

Conversation

@prete

@prete prete commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Adds a Screenshot button for paper figures: it saves the main 2D view as a PNG at 1×, 2×, 4× or 8× its size on screen, drawn again off screen. The plan is docs/plan/phases/27-screenshot.md; this PR holds the plan and its implementation (tasks A–I).

Problem

The spatial view had no export; the only image the app saved was a plot's Export PNG. A browser screenshot at a higher device pixel ratio falls short:

  • the image gains no detail: the pyramid level is chosen per CSS pixel, so at 4× it is upsampled;
  • a larger window reads a finer level but shrinks points, outlines and text against the figure;
  • the legend is outside the frame;
  • zoomed out, the canvas draws a sample of cells (the render cap: about 250,000 of the Xenium demo's 1.4 million);
  • deck.gl's canvas cannot be read back (toDataURL is blank).

What it does

  • The popover (Screenshot, beside Share): scale (2× to start), a size line with µm per pixel and mm at a dpi, DPI, Scale bar, Legend, Axes and Selections, a background (Canvas, White, Transparent), notes when the screen samples cells or expression, shows transcripts as density squares or is still loading, and Save PNG. Scales over 16,384 px a side or 128 megapixels are disabled. Above 512 MiB of image tiles it asks first.
  • The image at bestLevel(2 ** zoom × N), read through the screenshot's own TileCache per channel with persist: false, so the canvas's tiles and the byte-range cache are left as they were. A failed tile is read again after 1, 2 and 4 s; then the screenshot fails, names the channel and offers Retry.
  • Every loaded cell, from createOverviewLayers without the render cap's sample, in an off-screen Deck at useDevicePixels: N, drawn in tiles of at most 4,096 px. It fails rather than stretch a drawing buffer the GPU shrank, and its WebGL context is lost as soon as it is done.
  • The overlays as one SVG in CSS px, drawn at N×: the scale bar, the legend (bottom left, without hidden classes), the axes, and saved and active selections. Dark boxes on Canvas and Transparent, white ones on White.
  • The file {dataset}-screenshot.png, with pHYs for the dpi and tEXt chunks: Software, Source (the dataset URL without credentials), Description (x and y ranges, µm per pixel, scale, z plane) and Creation Time.
  • One at a time, with progress and Cancel in the popover and the loading list; changing dataset cancels it.

How

  • src/features/screenshot/: screenshotPlan (size, limits, grid, levels, notes), screenshotImage (the image composer), screenshotDeck (the off-screen renderer), screenshotOverlay (the SVG), pngChunks, screenshotRun (one screenshot, tile by tile), screenshotRunner and ScreenshotButton.
  • App owns a ScreenshotRunner and passes it to ViewerCore, which connects a function returning the snapshot of its view. No layers or typed arrays go into React props, and taking a screenshot does not render the live DeckGL again (ViewerCore's test checks it).
  • deck.gl applies layers given before its device is ready in an animation frame, which a hidden page never runs: the PNG had the image and no cells. The renderer now runs that frame itself after onLoad.

Spike (Mac GPU, production build, headless Chromium)

View PNG Time File
Brain, 2× 2,280 × 1,704 0.5 s 5.0 MiB
Brain, 4× 4,560 × 3,408 1.0 s 16.6 MiB
Whole slide, 4×, all cells 4,560 × 3,408 1.6 s 4.5 MiB
  • The whole slide drew all 1,414,155 cells (the screen shows about 250,000); the JS heap grew 12 MiB.
  • Drawing buffers of 4,096, 8,192 and 16,384 px a side were granted; no seam where 4,096 px tiles meet.
  • Not measured: GPU memory, and PNG encoding at 8,192 and 16,384 px.

Where the build differs from the plan

  • A runner object rather than a screenshotRequest prop.
  • A request pool over the screenshot's own caches rather than a TileRequestScheduler.
  • The legend sits bottom left, where the screen puts it, rather than top right.
  • The panel toggles show their labels from 1,180 px (was 1,100 px); Screenshot shows its label from 1,340 px and is an icon below that.
  • The default scale is 2×, or the largest under the limit when 2× is over it.
  • The offline end-to-end test uses a 64² TIFF with one imported outline rather than an AnnData file.

Answered questions

Every loaded cell, not the screen's sample; 2× to start; a tile that cannot be read fails the screenshot with Retry; Copy to the clipboard later.

Checks

  • npx tsc --noEmit -p tsconfig.app.json, ESLint and Prettier on the changed files pass.
  • Vitest: the screenshot, ViewerCore and shell tests pass (280). In the full suite two App tests failed under CPU load, as before; run alone, App.test.tsx and collectionApp.test.tsx pass (127).
  • Playwright: the new @smoke test saves a 2× PNG, checks its size, pHYs and text chunks, that the screenshot's WebGL context is gone with no loss on the page, and that the PNG halved matches the screen (mean difference 0.09 of 255). The axe test opens the popover; the baseline stays empty. The top bar popover test passes.
  • The new @live test, a 4× PNG of the whole Xenium slide, passed in 1.8 minutes, mostly the dataset's load.
  • Docs: docs/ui-reference.md, docs/user-guide.md, docs/architecture.md and PLAN.md.

A Screenshot button beside Share saves the main 2D view at 1x-8x, drawn
again off screen: the image at the pyramid level the larger size needs,
the deck.gl layers at that pixel density, and the scale bar, legend,
axes and selections from their models. Decisions D1-D12, the drawing
steps, tasks A-I with a spike first, risks, and the user's answers to
the four open questions (every loaded cell, 2x to start, a failed tile
fails with Retry, Copy later). PLAN.md gets the phase's row.
The canvas's tile caches already read a failed tile again after 1, 2
and 4 s (TILE_RETRY_DELAYS_MS; the early-timer fix in #426), then keep
the error until the tile is evicted, with no way to forget one tile. So
the screenshot gets its own TileCache and scheduler per channel: a
Retry reads failed tiles again, and a read of hundreds of tiles does not
push the canvas's tiles out of its cache. D4, the drawing steps, task C
and the risks say so; the code map is rechecked at fe50d70.
A Screenshot button beside Share saves the main 2D view as a PNG at 1×,
2×, 4× or 8× its size on screen, drawn again off screen:

- the image at the pyramid level the PNG's pixel size needs, through
  the screenshot's own tile caches (persist: false), retried after 1, 2
  and 4 s, then failing with Retry;
- every loaded cell, not the render cap's sample, from an off-screen
  Deck at useDevicePixels N, in tiles of at most 4,096 px;
- the scale bar, legend, axes and selections as one SVG at N×;
- pHYs for the dpi and tEXt chunks for the software, source, view and
  time.

App owns a ScreenshotRunner, which ViewerCore connects to its view, so
no layers or typed arrays go into props and the live DeckGL does not
render again. Progress and Cancel show in the popover and the loading
list; changing dataset cancels it.

deck.gl applies layers given before its device is ready in an animation
frame, which a hidden page never runs, so the renderer runs one itself.

On the Mac's GPU a 4× PNG of the whole Xenium slide, all 1,414,155
cells, took 1.6 s. The plan records the spike and where the build
differs from it.
@prete prete changed the title Plan Phase 27: Screenshot, the spatial view as a high-resolution PNG Phase 27: Screenshot, the spatial view as a high-resolution PNG Nov 24, 2026
@prete
prete merged commit 73d1ba7 into main Nov 24, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant