Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Legend: `[x]` done · `[ ]` open · **Deferred** · **Dropped** · **Superseded*
| [Phase 24](docs/plan/phases/24-section-stack.md) | 3D section stack: registered serial sections in 3D | Done (2026-11-18); one file's z and sections 2026-11-20 |
| [Phase 25](docs/plan/phases/25-imported-segmentations.md) | Segmentations imported onto images (masks, polygons) | Done (2026-11-19) |
| [Phase 26](docs/plan/phases/26-image-channel-conditions.md) | Cell query on image channels: mean and % above per cell | M1 and M2 done (2026-11-19): TIFF and OME-Zarr images |
| [Phase 27](docs/plan/phases/27-screenshot.md) | Screenshot: the spatial view as a high-resolution PNG | Done (2026-11-24) |

**Done** means a phase's tasks shipped. Most phase files also keep a Known
Gaps list whose items stay open; [Open Items](docs/plan/open-items.md)
Expand Down
12 changes: 12 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,18 @@ lets tests replace them.
WebGL context live, and Chromium keeps 16 per page and drops the oldest,
which is the 2D view's. `ReleasingDeck` loses the context and stops
luma.gl's canvas observers once its canvas has left the page.
- Screenshots (`src/features/screenshot/`, plan 27) draw the view again off
screen. App makes one `ScreenshotRunner`; ViewerCore connects its snapshot
to it (the view, the frame, the image channels, a function that builds the
layers with every loaded cell, and the overlay models), and the top bar's
popover starts it. `drawScreenshot` draws the frame in tiles of at most
4,096 px: the image through a `ScreenshotImageComposer`, with its own
`TileCache`s at the level the PNG needs, then the layers through a
`ScreenshotDeckRenderer`, a `ReleasingDeck` of its own whose canvas sits
hidden in the page and is copied out in the same task each tile is drawn,
then the scale bar, legend, axes and selections as one SVG. `pngChunks`
adds the dpi and text chunks. The Deck loses its context as soon as the
screenshot ends.

## Default Colours

Expand Down
564 changes: 564 additions & 0 deletions docs/plan/phases/27-screenshot.md

Large diffs are not rendered by default.

61 changes: 56 additions & 5 deletions docs/ui-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,18 @@ shown sections first (`setLinked`).
| Measure ▾ | While measuring: `Measure unit` (µm or px, starting at the mouse coordinate unit) and `Clear Measurement` |
| Magic Lens ▾ | `Radius` (10–500 µm, step 10; 80 µm) and `Summarise View`, which scans the whole view into the Magic Lens card |
| Panels | `Embedding`, `Plots` and `Query` open and close the [Embedding](#embedding-panel), [Plots](#plots-panel) and [Cell Query](#cell-query-panel) panels; an open one is pressed. See below |
| `Screenshot` | A camera: saves the spatial view as a PNG at 1×, 2×, 4× or 8× its size; see [Screenshot](#screenshot) |
| `Share` | Copies the link (the address, which holds the view) and says "Link copied" |
| `Help` | `?` opens and closes it. Lists the keyboard shortcuts, from `SHORTCUTS` (`src/features/shell/shortcuts.ts`), the table the key handlers read, and links to the guides on GitHub (`HELP_LINKS`) |
| `Settings` | See [Settings](#settings) |

**Panels** (the `Panels` group, `PanelToggles` in `TopBar.tsx`): the
windows' toggles sit at the right of the bar, above where the windows open.
A dataset shows only the ones it has: none on images, no `Plots` or `Query`
on Visium HD, whose bins are not cells the panels can read. From 1100 px
wide each shows its icon and name; between 860 and 1100 px only the icon,
with the name still read and in the tooltip. Under 860 px they fold into a
on Visium HD, whose bins are not cells the panels can read. From 1180 px
wide each shows its icon and name; between 860 and 1180 px only the icon,
with the name still read and in the tooltip. `Screenshot` shows its name
from 1340 px, and its camera alone below that. Under 860 px they fold into a
menu (see [Narrow Screens](#narrow-screens)). Until 2026-11-19 they were
Cells › Panels › `Show Embedding`, `Show Plots` and `Show Query`, below the
genes and clusters. A window the open dataset lacks closes, so a dataset
Expand Down Expand Up @@ -323,6 +325,55 @@ shown tooltip does only that, and the tool stays.
`Boundary limit` applies on Enter or when the field is left. Escape puts the
limit back, and a field left empty keeps it.

### Screenshot

`Screenshot` (`ScreenshotButton`, `src/features/screenshot/`, plan 27) saves
the main 2D view as a PNG for a figure. It is off until a dataset is open,
and says so when the view has not drawn yet. Its popover:

| Control | Type | Default | Notes |
| ------------ | -------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- |
| `Scale` | Segmented 1× / 2× / 4× / 8× | 2×, or the largest under the limit below it | A scale over 16,384 px on a side or 128 megapixels is off, and its tooltip says which |
| Size line | Text | | "3,000 × 1,800 px · 0.25 µm per pixel · 254 × 152 mm at 300 dpi" |
| `DPI` | Number, 30–2400 | 300 | Written into the PNG; changes only the mm figure, not the pixels |
| `Include` | Checkboxes | `Scale bar`, `Legend`, `Axes` from Settings; `Selections` on | The scale bar bottom right, the legend bottom left, the rulers, and the saved and active selections |
| `Background` | Segmented Canvas / White / Transparent | Canvas | On White the scale bar's and legend's boxes turn white with dark text |
| Read line | Text | | "Reads 480 image tiles (96 MB)": the tiles at the PNG's scale, and their size where the TIFF index says |
| Notes | List | | What the view holds that the PNG shows differently, or still loads; see below |
| `Save PNG` | Button | | Above 512 MiB of tiles it asks first: `Read {size} and save` or `Back` |

While it runs the popover shows its progress with `Cancel`, and so does the
loading list, as `Screenshot`; closing the popover does not stop it. One runs
at a time, and opening another dataset cancels it. A tile that cannot be read
after the canvas's retries (1, 2 and 4 s) fails it with `Retry`, which reads
again with new caches; a figure with a hole in it is worse than none. It ends
with "Saved {file}".

The PNG is the canvas's frame, the part under the layer panel and the cards
included, drawn again off screen rather than copied (the live view is never
resized or read):

- The image at the pyramid level the PNG's pixel size needs: a 4× PNG reads
the level a window four times larger would. Its tiles go through caches of
the screenshot's own, and reads leave the byte-range cache as it is.
- Every loaded cell, not the render cap's sample. The notes say so when the
screen samples ("Draws all 1,414,155 cells in view; the screen shows about
250,000."), when expression is a sample at this zoom, when transcripts are
density squares, and what is still loading. The PNG shows what has loaded;
`All cells` and `Exact` make the view complete.
- Points, outlines and text keep their size against the frame, so the PNG
looks as the screen does, only sharper.
- The marks are drawn from their models at the PNG's scale. The legend leaves
out its controls and the classes hidden on the map. Tooltips, the
crosshair, the readouts, tool hints, a shape or measurement being drawn,
the minimap and the zoom buttons are left out.

The file is `{dataset}-screenshot.png`, named as plot exports are. It records
its dpi (`pHYs`) and, in `tEXt` chunks, `Software` (the app, its release and
commit), `Source` (the dataset address without a presigned URL's
signature), `Description` (the view's x and y ranges, µm per pixel, the
scale and, for a z-stack, the plane) and `Creation Time` (UTC, ISO 8601).

## Layer Panel

The layer panel is an accordion with a section per layer. Each header has a
Expand Down Expand Up @@ -1812,8 +1863,8 @@ stylesheet's narrow rules use too) the shell folds up:
- The tools fold into a menu: its button shows the active tool ("Tools:
Pan"), and it lists each tool with its key and, when off, why. Picking one
closes the menu and returns focus to its button. The brand is
hidden, the summary chip is read out but not shown, and Share shows only its
icon. The Magic Lens options appear only while the lens is on. The dataset
hidden, the summary chip is read out but not shown, and Screenshot and
Share show only their icons. The Magic Lens options appear only while the lens is on. The dataset
name gives way to the buttons, ending in "…".
- The window toggles fold into a `Panels` menu beside Share, listing
`Embedding`, `Plots` and `Query` with the open one pressed. Picking one
Expand Down
22 changes: 22 additions & 0 deletions docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,28 @@ the top bar copies the link to share the same view. Older links with `tab=`
still work. Each dataset you open is a step in the browser's history, so Back
returns to the previous dataset, or to the start screen.

### Making A Figure

`Screenshot` (the camera in the top bar) saves the spatial view as a PNG for
a figure. Frame the view, then pick:

- **Scale**: the PNG is 1, 2, 4 or 8 times the size of the view on screen.
The line under it gives the size in pixels, µm per pixel and the size in
print at the `DPI` you set (300 to start). The image is read at the detail
the larger size needs, and points, outlines and text grow with it, so the
PNG looks like the screen, only sharper.
- **Include**: the scale bar, legend and axes start from Settings; the
selections' outlines start on.
- **Background**: black as on screen, white, or transparent.

The PNG draws every loaded cell, where the screen draws a sample of a large
dataset zoomed out; the popover says so. It also says when expression is a
sample at this zoom or transcripts are density squares: set
`Expression detail` to `All cells`, and the transcripts' `Detail` to `Exact`
(or zoom in), for a complete figure. A screenshot that reads a lot of image
asks first, and you can cancel it from the popover or the loading list. The
file records the dpi, the dataset, the view in µm and when it was made.

## Layers And Genes

The layer panel's Image section controls dataset image opacity, image
Expand Down
79 changes: 79 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
useMemo,
useRef,
useState,
useSyncExternalStore,
type CSSProperties,
} from 'react'
import {
Expand Down Expand Up @@ -60,6 +61,14 @@ import { manifestSegmentationSource } from './datasets/datasetManifest'
import { datasetManifestFor } from './data/datasetFiles'
import { ShellLayout } from './features/shell/ShellLayout'
import { useTopBarModel } from './features/shell/topBarModel'
import {
ScreenshotRunner,
screenshotStageText,
} from './features/screenshot/screenshotRunner'
import {
screenshotFileInfo,
type ScreenshotModel,
} from './features/screenshot/screenshotModel'
import { useToolShortcuts } from './features/shell/useToolShortcuts'
import { useNarrowScreen } from './features/shell/useNarrowScreen'
import { useCardStackModel } from './features/cards/cardModels'
Expand Down Expand Up @@ -520,6 +529,12 @@ export function App({ dependencies }: AppProps = {}) {
} | null>(null)

const datasetUrl = useViewerStore((state) => state.datasetUrl)
// Screenshots of the spatial view (plan 27), one at a time.
const [screenshotRunner] = useState(() => new ScreenshotRunner())
const screenshotState = useSyncExternalStore(
screenshotRunner.subscribe,
screenshotRunner.getState,
)
const setDatasetUrl = useViewerStore((state) => state.setDatasetUrl)
const appState = useAppDomainState({ initialShareableState, performanceBudget })
const {
Expand Down Expand Up @@ -2715,9 +2730,21 @@ export function App({ dependencies }: AppProps = {}) {
detail: `${importedSegmentation.state.shapeCount.toLocaleString()} outlines`,
}
: undefined,
screenshotLoading:
screenshotState.status === 'running'
? {
detail: screenshotStageText(screenshotState.progress),
progress:
screenshotState.progress === null
? undefined
: screenshotState.progress.done /
Math.max(1, screenshotState.progress.total),
}
: undefined,
boundariesAreSegmentation: platformAdapter.kind === 'image',
}),
[
screenshotState,
importedSegmentation.state,
platformAdapter.kind,
analysisEmbeddingState,
Expand Down Expand Up @@ -3975,6 +4002,9 @@ export function App({ dependencies }: AppProps = {}) {
'cell-transcripts': cancelCellDetails,
'roi-cells': handleCancelRoiCells,
'roi-genes': handleCancelRoiGenes,
screenshot: () => {
screenshotRunner.cancel()
},
}

cancelLoadingTaskRef.current = (id) => {
Expand Down Expand Up @@ -4962,6 +4992,53 @@ export function App({ dependencies }: AppProps = {}) {
: loadState.status === 'loading'
? loadState.url
: null
// Changing dataset cancels a screenshot of the last one (27-D12).
useEffect(
() => () => {
screenshotRunner.cancel()
},
[loadedDatasetUrl, screenshotRunner],
)
const screenshotModel = useMemo<ScreenshotModel | null>(
() =>
loadedDatasetUrl === null
? null
: {
runner: screenshotRunner,
available: true,
include: {
scaleBar: showScaleBar,
legend: showLegend,
axes: showAxes,
selections: true,
},
expressionSampled:
geneExpressionState.status === 'ready' &&
(geneExpressionState.mode === 'sampled' ||
geneExpressionState.mode === 'overview-sampled'),
transcriptsAsDensity: transcriptLayerAggregateBins.length > 0,
loadingLabels: loadingTasks
.filter((task) => task.id !== 'screenshot')
.map((task) => task.label),
file: screenshotFileInfo(
loadedDatasetUrl,
morphologyImage?.zStack === undefined
? null
: morphologyImage.zStack.zPlane + 1,
),
},
[
geneExpressionState,
loadedDatasetUrl,
loadingTasks,
morphologyImage,
screenshotRunner,
showAxes,
showLegend,
showScaleBar,
transcriptLayerAggregateBins.length,
],
)
const topBar = useTopBarModel({
activeTool,
appendDebugEvent,
Expand Down Expand Up @@ -4993,6 +5070,7 @@ export function App({ dependencies }: AppProps = {}) {
onReturnToPan: returnToPan,
onRoiModeChange: handleRoiModeChange,
platform: platformAdapter.kind,
screenshot: screenshotModel,
setDebugMode,
})
const [fitRequestKey, setFitRequestKey] = useState(0)
Expand Down Expand Up @@ -5418,6 +5496,7 @@ export function App({ dependencies }: AppProps = {}) {
axes={showAxes}
scaleBar={showScaleBar}
fitRequestKey={fitRequestKey}
screenshot={screenshotRunner}
onImageTileError={handleImageTileError}
onTileCacheEviction={handleTileCacheEviction}
onViewportCellCountChange={setViewportCellCount}
Expand Down
24 changes: 1 addition & 23 deletions src/components/MorphologyCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '../rendering/morphologyCanvas'
import { tileSchedulingForLoader } from '../rendering/morphologyTileScheduling'
import { MorphologyTileStore } from '../rendering/morphologyTileStore'
import { visibleMorphologyChannels } from './morphologyCanvasChannels'
import type { DisplayWindow } from '../codecs/jpeg2000'
import type { CssViewportSize } from '../rendering/morphologyCanvas'
import type { ImagePyramidLoader } from '../data/imagePyramid'
Expand Down Expand Up @@ -407,29 +408,6 @@ function requestedTilesWillRetry(requests: readonly ChannelRequest[]): boolean {
)
}

function visibleMorphologyChannels(
loader: ImagePyramidLoader | null | undefined,
channels: readonly MorphologyCanvasChannel[] | undefined,
): readonly MorphologyCanvasChannel[] {
if (channels !== undefined && channels.length > 0) {
return channels.filter((channel) => channel.enabled)
}

if (loader === null || loader === undefined) {
return []
}

return [
{
id: loader.url,
loader,
enabled: true,
color: [255, 255, 255],
opacity: 1,
},
]
}

interface ChannelRequestPlan {
readonly spec: MorphologyTileChannelSpec
readonly channel: MorphologyCanvasChannel
Expand Down
Loading