Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
cf98f93
Study View: the portal's grid, with its own library (react-grid-layou…
alisman Nov 20, 2026
23c74b3
Study View cards: one title treatment, one line, and only the portal'…
alisman Nov 20, 2026
fffab2d
Study View KM plot: the curve alone, fitting its card
alisman Nov 20, 2026
57527ac
Study View pies as the portal draws them: the full square, counts on …
alisman Nov 20, 2026
2bbf875
Study View cards: search in the footer, titles centred, title and con…
alisman Nov 23, 2026
3055d25
Study View: the chart grid left-aligned
alisman Nov 23, 2026
1d25f78
Study View: no bar per row in the lists; a card's header buttons on h…
alisman Nov 23, 2026
6527dfe
Study View: each chart fills its card's height
alisman Nov 23, 2026
9d92682
Study View: the density scatter's ticks condensed
alisman Nov 23, 2026
d91dedb
Study View: tables striped, a shaded header, the scroll box ruled
alisman Nov 23, 2026
ed75ca6
Study View: the shading on the card's title bar, not the table's header
alisman Nov 23, 2026
3fcaf4f
Study View: the chart grid on a white panel
alisman Nov 23, 2026
5b55870
Study View: the whole page white behind the chart grid
alisman Nov 23, 2026
c3bfa43
Study View: the page's own background back; card headers white
alisman Nov 24, 2026
ea46e8e
Study View: 7 px around the cards
alisman Nov 24, 2026
c708c15
Study View: the grid flush with both sides of the page
alisman Nov 24, 2026
5204bb6
Study View: the e2e drivers check waits on the gene table's data-drivers
alisman Nov 24, 2026
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
155 changes: 85 additions & 70 deletions app/globals.css

Large diffs are not rendered by default.

85 changes: 53 additions & 32 deletions app/lab/explore-charts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
// same ones an analysis would report. A density is a filter: drag a rectangle over it to add both
// axes' ranges to the selection.
import { useEffect, useRef, useState } from "react";
import { RotateCcw } from "lucide-react";
import { cardRank, type GridCard } from "./explore-grid.tsx";
import { chartCells, kmPlotTitle } from "../../lib/study-view-layout.ts";
import { api } from "./api.ts";
import { Choice } from "../_ui/choice.tsx";
import { Button } from "../_ui/button";
import { useWidth } from "./figure.tsx";
import { useSize } from "./figure.tsx";
import { linear, axisLeft, axisBottom, leftAxisWidth, bottomAxisHeight } from "../../lib/svg-kit.ts";
import { fmtInt } from "../../lib/chart/format.ts";
import type { CohortDef } from "../../lib/types.ts";
import { fmtCompactTick, fmtInt } from "../../lib/chart/format.ts";
import type { CohortDef, KmCurve } from "../../lib/types.ts";
import type { PlotCell } from "../../lib/plot.ts";
import { ChartMenu } from "./partitions.tsx";
import { caseFileAction, densityFigureSvg, figureActions, standaloneSvg } from "./chart-files.ts";
import { chartFileName } from "../../lib/study-view-download.ts";
import { survivalSvg } from "../../lib/views/survival/figure.ts";
import { curveSummary, survivalSvg } from "../../lib/views/survival/figure.ts";
import { PORTAL_STUDY_VIEW_KM } from "../../lib/chart/style.ts";
import {
FGA, MUTATION_COUNT, correlationLines, densityAxes, densityPairKey, densityAxisLabel, densityColors, densityGradient, densitySelection, densityTip,
Expand Down Expand Up @@ -55,8 +57,29 @@ interface Props {
type PlotData = { shape: string; n: number; extent?: { x0: number; x1: number; y0: number; y1: number }; grid?: [number, number];
bins?: PlotCell[]; stats?: { pearson: number | null; spearman: number | null }; coverage?: { total: number; nx: number; ny: number } };

export function ExploreCharts({ studies, selection, draft, attrs, endpoints, addClauses, km, density = true, pairs = [], onRemovePair, onClearDensity }: Props) {
/**
* The survival chart and the density charts as grid cards. The survival chart is one card with an
* endpoint picker (kept on purpose, 2026-11-13), drawn at 2 × 2 where the portal draws a 1 × 1 tile
* per endpoint.
*/
export function exploreChartCards(props: Props): GridCard[] {
const { attrs, density = true, pairs = [], onRemovePair, onClearDensity, studies, draft, selection, addClauses } = props;
const nameOf = (a: string) => attrs.find((x) => x.attribute === a)?.displayName || DENSITY_NAMES[a] || a;
// the default Mutation Count vs FGA chart (unless unchecked), then the reader's X vs Y charts (STS-SC-1)
// the same rule the filter bar reads to hide a drag's pills (STV-FB-3b)
const shown = densityChartsShown(attrs.map((a) => a.attribute), density, pairs);
return [
...(props.endpoints && props.endpoints.length ? [{ key: "survival", ...cardRank('[data-chart="survival"]'), ...chartCells("density"), node: <SurvivalCard {...props} /> }] : []),
...shown.map(({ pair, added }): GridCard => ({
key: "density:" + densityPairKey(pair), ...(added ? { name: nameOf(pair.x) + " vs " + nameOf(pair.y) } : cardRank('[data-chart="mutcount-fga"]')),
...chartCells("density"),
node: <DensityCard pair={pair} added={added} studies={studies} draft={draft} selection={selection} addClauses={addClauses}
nameOf={nameOf} onRemove={added && onRemovePair ? () => onRemovePair(pair) : undefined} onClear={onClearDensity ? () => onClearDensity(pair) : undefined} />,
})),
];
}

function SurvivalCard({ studies, selection, draft, endpoints, km, attrs }: Props) {
const [endpoint, setEndpoint] = useState<string>("OS");
const ep = endpoints && endpoints.length ? (endpoints.includes(endpoint) ? endpoint : endpoints[0]) : null;
const [res, setRes] = useState<{ key: string; curves?: unknown[]; error?: string } | null>(null);
Expand Down Expand Up @@ -84,39 +107,33 @@ export function ExploreCharts({ studies, selection, draft, attrs, endpoints, add
return () => ac.abort();
}, [key]); // eslint-disable-line react-hooks/exhaustive-deps

// the default Mutation Count vs FGA chart (unless unchecked), then the reader's X vs Y charts (STS-SC-1)
// the same rule the filter bar reads to hide a drag's pills (STV-FB-3b)
const shown = densityChartsShown(attrs.map((a) => a.attribute), density, pairs);
const stale = loading || !res || res.key !== key;
return <>
{ep && (
<div className="card xc-card" data-chart="survival">
<div className="xc-head">
<span className="xc-title">{ep === "OS" ? "Overall survival" : ep + " survival"} of the selection</span>
<ChartMenu label="the survival chart" actions={[{ label: "Download", title: "save this chart as a file",
<span className="xc-title" data-tip={"the selection's patients, " + ep + "_MONTHS and " + ep + "_STATUS"}>{kmPlotTitle(attrs.find((a) => a.attribute === ep + "_STATUS")?.displayName || ep + " Status")}</span>
<ChartMenu label="the survival chart" actions={[
// the endpoint the curve follows, where the portal draws a chart per endpoint
...(endpoints && endpoints.length > 1 ? [{ label: "Endpoint", title: "the outcome the curve follows",
sub: endpoints.map((x) => ({ label: x, checked: x === ep, title: "follow " + x, onClick: () => setEndpoint(x) })) }] : []),
{ label: "Download", title: "save this chart as a file",
sub: [caseFileAction("Data", { kind: "survival", status: ep + "_STATUS", months: ep + "_MONTHS" }, chartFileName((ep === "OS" ? "Overall" : ep) + " survival", "data"),
selection, (update) => setFileError((cur) => update(cur))),
...figureActions((ep === "OS" ? "Overall" : ep) + " survival", () => {
const curves = res?.curves;
return curves && curves.length ? standaloneSvg(survivalSvg({ kind: "survival", curves } as never, { width: 480, theme: "light" }, PORTAL_STUDY_VIEW_KM)) : null;
}, (message) => setFileError(message))] }]} />
{endpoints && endpoints.length > 1 && (
<Choice className="w-28" title="the outcome the curve follows" value={ep} onChange={setEndpoint}
options={endpoints.map((x) => [x, x] as const)} />
)}
</div>
<div className="xc-body">
{/* the curve's median, patients and events in its tooltip, where the portal's small KM chart keeps its legend (STS-KM-3) */}
<div className="xc-body" data-tip={res?.curves?.length ? (res.curves as KmCurve[]).map((c) => c.cohort + ": " + curveSummary(c)).join("\n") : undefined}>
{res && res.curves && (res.curves.length ? km(res.curves) : <p className="note">no patient in the selection has a {ep} time and status</p>)}
{res && res.error && <p className="note">{res.error}</p>}
{fileError && <p className="note">{fileError}</p>}
{stale && <div className="xc-wait"><span className="spinner" /> {res ? "updating…" : "loading…"}</div>}
</div>
</div>
)}
{shown.map(({ pair, added }) => (
<DensityCard key={densityPairKey(pair)} pair={pair} added={added} studies={studies} draft={draft} selection={selection} addClauses={addClauses}
nameOf={nameOf} onRemove={added && onRemovePair ? () => onRemovePair(pair) : undefined} onClear={onClearDensity ? () => onClearDensity(pair) : undefined} />
))}
</>;
}

Expand Down Expand Up @@ -169,11 +186,10 @@ function DensityCard({ pair, added, studies, draft, selection, addClauses, nameO
return (
<div className="card xc-card" data-chart={added ? "xvsy" : "mutcount-fga"} data-pair={densityPairKey(pair)}>
<div className="xc-head">
<span className="xc-title">{title}</span>
<span className="meta">{plot && plot.coverage && plot.coverage.total > plot.n
? fmtInt(plot.n) + " of " + fmtInt(plot.coverage.total) + " samples have both · " : ""}{held ? "selected: " + heldText : "drag a box to filter"}</span>
{held && onClear && <Button variant="outline" size="xs" data-chart-reset onClick={onClear}
data-tip={"Reset filters: clear this chart's selection (" + heldText + ")"}>Reset</Button>}
<span className="xc-title" data-tip={title + "\n" + (plot && plot.coverage && plot.coverage.total > plot.n
? fmtInt(plot.n) + " of " + fmtInt(plot.coverage.total) + " samples have both · " : "") + (held ? "selected: " + heldText : "drag a box to filter")}>{title}</span>
{held && onClear && <span className="cardctl"><Button variant="ghost" size="icon-xs" className="charticon size-5" data-chart-reset onClick={onClear} aria-label="Reset filters in chart"
data-tip={"Reset filters: clear this chart's selection (" + heldText + ")"}><RotateCcw /></Button></span>}
<ChartMenu label={"the " + title + " chart"} actions={[
{ label: "Swap Axes", title: "put " + names.y + " along the bottom", onClick: () => saveDensity(swapDensity(dset)) },
...(["x", "y"] as const).filter((k) => logOffered(axes[k].attribute)).map((k) => ({
Expand Down Expand Up @@ -207,22 +223,27 @@ function Density({ data, axes, names, figure, held, onSelect }: { data: PlotData
/** set to draw the chart as a file */
figure: React.MutableRefObject<(() => string | null) | null>;
onSelect: (box: { x0: number; x1: number; y0: number; y1: number }, span: { x: number; y: number }) => void }) {
const { ref, width } = useWidth(260);
// the box's size: in a grid card, the room under the title, which the chart fills
const { ref, size } = useSize();
const width = size?.width ?? null;
const LEGEND_W = 92;
const W = Math.max(200, (width ?? 340) - LEGEND_W), H = Math.round(Math.max(200, Math.min(300, W * 0.72)));
const W = Math.max(200, (width ?? 340) - LEGEND_W), H = size && size.height >= 160 ? size.height : Math.round(Math.max(200, Math.min(300, W * 0.72)));
const [gx, gy] = data.grid!;
// the engine's log axis is log2(1 + v); the portal draws ln(1 + v)
const show = (v: number, log: boolean) => log ? lnFromEngine(v) : v;
const e = { x0: show(data.extent!.x0, axes.x.log), x1: show(data.extent!.x1, axes.x.log),
y0: show(data.extent!.y0, axes.y.log), y1: show(data.extent!.y1, axes.y.log) };
const xName = names.x, yName = names.y;
const xTitle = densityAxisLabel(xName, axes.x.log), yTitle = densityAxisLabel(yName, axes.y.log);
const ys0 = linear(e.y0, e.y1, 0, 1, { nice: false, count: 8 });
const L = 6 + leftAxisWidth(ys0, yTitle), R = 8, T = 8, B = bottomAxisHeight(xTitle) + 2, PW = W - L - R, PH = H - T - B;
const ys = linear(e.y0, e.y1, T + PH, T, { nice: false, count: 8 });
const xs = linear(e.x0, e.x1, L, L + PW, { nice: false, count: 8 });
// about five ticks an axis, thousands as "10K": the labels take little of the card from the plot
const TICKS = 5;
const ys0 = linear(e.y0, e.y1, 0, 1, { nice: false, count: TICKS });
const yFmt = (v: number) => fmtCompactTick(v, ys0.fmt);
const L = 6 + leftAxisWidth(ys0, yTitle, yFmt), R = 8, T = 8, B = bottomAxisHeight(xTitle) + 2, PW = W - L - R, PH = H - T - B;
const ys = linear(e.y0, e.y1, T + PH, T, { nice: false, count: TICKS });
const xs = linear(e.x0, e.x1, L, L + PW, { nice: false, count: TICKS });
const pal = { ink: "var(--ink)", muted: "var(--muted)", line: "var(--line)" };
const axesSvg = axisLeft(ys, L, pal, { title: yTitle }) + axisBottom(xs, T + PH, pal, { title: xTitle, minX: 0, maxX: W });
const axesSvg = axisLeft(ys, L, pal, { title: yTitle, fmt: (v) => fmtCompactTick(v, ys.fmt) }) + axisBottom(xs, T + PH, pal, { title: xTitle, minX: 0, maxX: W, fmt: (v) => fmtCompactTick(v, xs.fmt) });
const bins = data.bins || [];
const { color, legend } = densityColors(bins.map((b) => b.n));
const lines = correlationLines({ pearson: data.stats?.pearson ?? null, spearman: data.stats?.spearman ?? null }, bins.reduce((a, b) => a + b.n, 0));
Expand Down
48 changes: 48 additions & 0 deletions app/lab/explore-grid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"use client";
/**
* The Study View's chart grid, laid out as the portal's (STS-LY-1…3) with the portal's own grid
* library, react-grid-layout: cells of about 195 × 170 px 7 px apart, as many columns as fill the
* page's width, flush with both its sides,
* each card a whole number of cells by its kind, placed in priority order into the first free spot.
* Cards keep their places: no drag and no resize (decided against, 2026-11-13).
*/
import { useMemo, type ReactNode } from "react";
import ReactGridLayout, { useContainerWidth } from "react-grid-layout";
import { absoluteStrategy, verticalCompactor } from "react-grid-layout/core";
import "react-grid-layout/css/styles.css";
import { CARD_PRIORITY } from "../../lib/study-view-config.ts";
import { GRID_CELL, findSpotLayout, gridCols, orderCards, type CardSpec } from "../../lib/study-view-layout.ts";

/** a card on the grid: its place in the layout (`lib/study-view-layout.ts`) and what it draws */
export type GridCard = CardSpec & { node: ReactNode };

/** the portal's rank and name for a card that is not a clinical attribute's (STS-LY-8), by its card's selector */
export function cardRank(selector: string): { name: string; priority: number } {
const r = CARD_PRIORITY.find((c) => c.selector === selector);
if (!r) throw new Error("no rank for " + selector);
return { name: r.name, priority: r.priority };
}

const MARGIN: [number, number] = [GRID_CELL.margin, GRID_CELL.margin];
/** no padding at the grid's sides, the gap above and below it */
const PADDING: [number, number] = [0, GRID_CELL.margin];

export function StudyViewGrid({ cards }: { cards: GridCard[] }) {
// the grid fills its box's width; the columns stretch or squeeze a little to fill it
const { width, containerRef, mounted } = useContainerWidth({ measureBeforeMount: true });
const cols = gridCols(width);
const ordered = useMemo(() => orderCards(cards), [cards]);
const layout = useMemo(() => findSpotLayout(ordered, cols), [ordered, cols]);
return (
<div ref={containerRef} className="svgridbox">
{mounted && (
<ReactGridLayout className="svgrid" width={width} layout={layout}
gridConfig={{ cols, rowHeight: GRID_CELL.h, margin: MARGIN, containerPadding: PADDING }}
dragConfig={{ enabled: false }} resizeConfig={{ enabled: false }}
compactor={verticalCompactor} positionStrategy={absoluteStrategy}>
{ordered.map((c) => <div key={c.key} className="svcell" data-cell={c.key}>{c.node}</div>)}
</ReactGridLayout>
)}
</div>
);
}
Loading
Loading