Repository navigation
Study View: Add chart's X vs Y tab, a density chart for any two numeric attributes (STV-AC-7, STS-SC-1) - #462
Conversation
…ic attributes (STV-AC-7, STS-SC-1) As the portal's: two selects of clinical attributes (survival ones but OS_STATUS left out) and its button for the pair, case by case (xVsYButton): Add Chart, two different attributes, a chart that exists (either way round), two categorical, a numeric with a categorical (the portal's violin table, not drawn here, so refused saying so), and Add density plot. A numeric pair is drawn as its own density chart, "<Y> vs <X>", with Swap Axes, Log Scale where the axis offers it, the download and a drag box, beside the default Mutation Count vs FGA chart. The density card is now a component per pair (DensityCard) with its own request; the survival card asks for survival alone. Verified on coadread: every button state; AGE vs Mutation Count drawn, 532 of 594 samples have both; the default chart and survival unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q3ezTaCo6wHFVsML6Qd4ht
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| const title = densityTitle(nameOf(axes.x.attribute), nameOf(axes.y.attribute)); | ||
| const names = { x: nameOf(axes.x.attribute), y: nameOf(axes.y.attribute) }; | ||
| return ( | ||
| <div className="card xc-card" data-chart={added ? "xvsy" : "mutcount-fga"} data-pair={densityPairKey(pair)}> |
There was a problem hiding this comment.
An added X vs Y card has data-chart="xvsy", and cardOrders (lib/study-view-config.ts CARD_PRIORITY) has no entry for it. Ordered cards get negative order values (i - cards.length), so this card keeps the default order: 0 and goes to the end of the facet grid, after every clinical card. It is not "beside the default chart" as the PR says. The e2e step only counts the cards, so it doesn't catch this. Fix: give the X vs Y cards an order next to [data-chart="mutcount-fga"] (for example, a [data-chart="xvsy"] entry at priority 200).
| <div className="xc-body"> | ||
| {plot && plot.shape === "scatter" && !plot.grid && <p className="note">No data to plot.</p>} | ||
| {plot && plot.shape === "scatter" && plot.grid && | ||
| <Density data={plot} axes={axes} names={names} figure={densityFile} onSelect={(box, span) => addClauses(densitySelection(box, dset, span, pair))} />} |
There was a problem hiding this comment.
Every density card now calls addDensitySelection, which replaces densityBins.current wholesale (use-explore-state.ts:602). With two charts on screen: drag on the default chart, then drag on Age vs Mutation Count. FGA's temporary bar edges from the first drag disappear, but its FGA range filter stays in the draft. The portal keeps scatter-selection bins per attribute (_customBinsFromScatterPlotSelectionSet.set(attr, …)). Fix: merge the new edges by attribute instead of overwriting the whole array.
| const [added, setAdded] = useState<string | null>(null); | ||
| const ax = attrs.find((a) => a.attribute === x) ?? null, ay = attrs.find((a) => a.attribute === y) ?? null; | ||
| // the default chart counts as existing, as on the portal | ||
| const existing = [...xyCharts.map(densityPairKey), densityPairKey(DEFAULT_DENSITY_PAIR)]; |
There was a problem hiding this comment.
The default pair always counts as existing, even when its chart is not drawn. That happens when the reader unchecked the density in the Genomic tab (density=false, so hasScatter is false). Picking FGA + Mutation Count then says "A chart with these attributes already exists", but no such chart is on the page. The pair also can't be added as an X vs Y chart, because shown filters out the default key. Fix: count the default only when chartChecked("genomic|density") is true.
| */ | ||
| function DensityCard({ pair, added, studies, draft, selection, addClauses, nameOf, onRemove }: { pair: DensityPair; added: boolean; studies: string[]; | ||
| draft: Draft; selection: Props["selection"]; addClauses: Props["addClauses"]; nameOf: (a: string) => string; onRemove?: () => void }) { | ||
| const storeKey = added ? DENSITY_KEY + "." + densityPairKey(pair) : DENSITY_KEY; |
There was a problem hiding this comment.
Each added chart's settings are stored under the sorted pair key, but swapped is relative to the pair's x/y order as picked. Example: add Age (x) vs Mutation Count (y), Swap Axes, then Remove chart. Re-adding it as Mutation Count (x) vs Age (y) reads swapped: true from storage, so the chart draws Age along the bottom, the opposite of what was picked. Remove chart also leaves the stored settings behind. Fix: key the storage by the ordered pair, or clear it in onRemovePair.
| export function ExploreCharts({ studies, selection, draft, attrs, endpoints, addClauses, km, density = true, pairs = [], onRemovePair }: Props) { | ||
| const has = (a: string) => attrs.some((x) => x.attribute === a); | ||
| const hasScatter = density && has(MUTATION_COUNT) && has(FGA); | ||
| const nameOf = (a: string) => attrs.find((x) => x.attribute === a)?.displayName || DENSITY_NAMES[a] || a; |
There was a problem hiding this comment.
nameOf now uses the study's displayName before DENSITY_NAMES, so the default chart's title, axis labels and download file names follow each study's metadata. Before, they were always the portal's "Mutation Count vs Fraction Genome Altered". A study whose display name differs (for example "Fraction of genome altered" or a different case) gets a different title and file name than the portal. Fix: use DENSITY_NAMES first for those two attributes.
| setLoading(true); | ||
| const cohort: CohortDef = { ...(studies.length > 1 ? { studies } : {}), all: (draft ? draft.all : []) as CohortDef["all"] }; | ||
| const ac = new AbortController(); | ||
| api.analysis({ study: studies[0], cohorts: { Selected: cohort }, views: [densityView(dset, pair)] }, { signal: ac.signal }) |
There was a problem hiding this comment.
Survival and each density chart now send their own api.analysis request, where the default density used to share one request with survival. With k added pairs, every filter change sends k+2 analysis requests, and each one resolves the same cohort on the server. Each card also sends a throwaway first request with {} settings before its localStorage effect runs, and that request is aborted. Fix: batch the views into one request in ExploreCharts and hand each card its view's result.
| { label: string; adds: boolean; tip?: string } { | ||
| if (!x || !y) return { label: "Add Chart", adds: false }; | ||
| if (x.attribute === y.attribute) return { label: "Please choose two different attributes.", adds: false }; | ||
| if (existing.includes([x.attribute, y.attribute].sort().join("|"))) return { label: "A chart with these attributes already exists", adds: false }; |
There was a problem hiding this comment.
[x.attribute, y.attribute].sort().join("|") re-implements densityPairKey from lib/study-view-density.ts, and the caller in explore-sections.tsx builds existing with densityPairKey. If the key format changes in one place, this check silently stops matching. Fix: use densityPairKey({ x: x.attribute, y: y.attribute }) and update the mutant's find string to match.
|
|
||
| /** | ||
| * One X vs Y density chart (STS-SC-1…6): its own settings (Swap Axes, Log Scale; the default | ||
| * chart's kept under its old key), its own request, its menu, and a drag box that filters on both. |
There was a problem hiding this comment.
This comment describes history ("the default chart's kept under its old key"). ~/projects/CLAUDE.md says: "No "why I changed this" comments in code. Comments describe the current code's intent, not its history". Suggest: "the default chart's under cbiolab.explore.density, an added one's under that plus its pair key".
|
Review verdict: changes requested (head The tab, the button cases, the attribute list and the per-sample pairing are right. A patient attribute against a sample one is plotted per sample with the patient's value spread to each sample, the bins are computed in SQL, and the denominator is samples. The drag's two range clauses select the samples shown in the box. Three things block:
Not blocking (see the inline comments): an added card goes to the end of the grid, which matches the portal's priority 0 for X vs Y charts. The other inline comments are nits: the default pair counts as existing while unchecked, the swapped setting is stored under the sorted key, the default title takes the study's displayName, there is one analysis request per card, CI was still pending at review time. |
…her chart's temporary edges - Remove chart on an added density chart takes its filters on both attributes and their temporary bar edges with it, as the portal's (xyChartRemoval). - A drag on one density chart replaces only its own two attributes' temporary edges; another chart's stay while its filter does, as the portal keeps them per attribute (_customBinsFromScatterPlotSelectionSet; densityBinsAfterDrag, densityBinsWithout). - The X vs Y e2e step drags on the added chart and removes it, checking its filters go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q3ezTaCo6wHFVsML6Qd4ht
# Conflicts: # app/lab/explore-sections.tsx # app/lab/use-explore-state.ts # lib/study-view-add-chart.ts # test/e2e/explore.cjs # test/study-view-add-chart-spec.test.ts
|
Fixed in 76fcd76 (master merged in at 4394754). Each fix has its test written first and a planted bug.
With master merged in (#459, #460): the tab row reads Clinical · Genomic · Gene status · Arm-level CNA · Genetic Ancestry · Methylation · Derived timeline filters · Custom data · X vs Y. |
|
Re-review: pass. 76fcd76 fixes all three blocking findings:
|
Summary
Add chart gains the portal's X vs Y tab (STV-AC-7), and Explore draws a density chart for any two numeric clinical attributes (STS-SC-1), not only Mutation Count against FGA.
The tab: two selects, "Select first clinical attribute" and "Select second clinical attribute". They list every clinical attribute except a survival one other than OS_STATUS, as the portal's (
xVsYAttributes).The button, as the portal's, case by case (
xVsYButton):The violin table (STS-VI) is not drawn here yet, so the numeric + categorical button stays disabled and its tooltip says why. After an add, " vs added." shows, and the selects reset.
The chart: " vs ", drawn beside the default chart, with the default's menu:
xyChartRemoval);densityBinsAfterDrag, as the portal's_customBinsFromScatterPlotSelectionSet).Axis domains follow the existing rules (FGA 0–1, Mutation Count from 0, any other attribute its data's range).
Code: the density card is now a component per pair (
DensityCard), each with its own request and settings. The density functions take the pair (densityAxes,densityView,densitySelection), defaulting to FGA / Mutation Count. The survival card now asks for survival alone.Spec IDs
Verification
Browser, dev server, coadread:
e2e: a new step in
test/e2e/explore.cjson luad. It checks the numeric + categorical and numeric pairs' buttons, the added chart's title, and that the default chart stays; then a drag on the added chart filters on both its attributes, and Remove chart takes the chart and both filters. Run on its own against my dev server: pass.Browser, two density charts (coadread): a drag on the default chart gives Mutation Count its temporary edges (… (240, 271] (271, 6,361] > 6,361); a drag on an added Diagnosis Age × FGA chart then keeps them.
Unit tests:
test/study-view-add-chart-spec.test.ts: the button's seven cases (an existing pair either way round, the violin refusal's reason) and the attribute list.test/study-view-density-spec.test.ts: a pair's axes, swap, Log Scale only where offered, the pair's key either way round, the view's attributes and range; a drag on one chart keeping another's temporary edges; Remove chart's pair, filters and edges.npm test6,903 pass, 0 fail (with master merged in);tsc --noEmitclean.Coverage: passes.
Planted bugs: 5 in
scripts/mutants/study-view/xvsy.ts(guardunit).Not done / follow-ups
Tracker
Under "Study View → filters, actions and tabs", this line (docs/PORTAL-PARITY.md:479):
becomes:
Under "Study View → summary charts", this line (docs/PORTAL-PARITY.md:404):
gains:
Scorecards:
31-study-view-shell.md, row STV-AC-7 (was| STV-AC-7 | ❌ | B | No X vs Y |):| STV-AC-7 | 🟡 | B | The X vs Y tab: two attribute selects (survival but OS_STATUS left out) and the portal's button for each pair (
xVsYButton); two numeric add a density chart; numeric × categorical refused, the violin table not drawn yet |30-study-summary.md, row STS-SC-1 (was| STS-SC-1 | 🟡 | BC | Fixed "Mutation count vs fraction genome altered" card when both attributes exist; no other X vs Y |):| STS-SC-1 | ✅ | BC | The default "Mutation Count vs Fraction Genome Altered" card when both attributes exist (hidden when unchecked in the Genomic tab); any other numeric pair from Add chart › X vs Y, " vs ", one per pair (
DensityCard,densityPairKey) |Preview
/lab?tab=explore&study=coadread_tcga_pan_can_atlas_2018: Add chart → X vs Y → Diagnosis Age and Mutation Count.🤖 Generated with Claude Code
https://claude.ai/code/session_01Q3ezTaCo6wHFVsML6Qd4ht