Skip to content

Study View: a density drag adds its ranges to the bar charts as custom bins (STS-SC-6) - #449

Merged
alisman merged 4 commits into
masterfrom
studyview-density-bins
Nov 19, 2026
Merged

alisman merged 4 commits into
masterfrom
studyview-density-bins

Conversation

@alisman

@alisman alisman commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Dragging a box on the Mutation Count vs FGA density chart now adds each range's ends to that attribute's bar chart as custom edges, as well as setting the two range filters. The selection then reads as bars of its own, as on the portal (_customBinsFromScatterPlotSelectionSet, STS-SC-6).

  • The rule is densityBinEdges in lib/study-view-density.ts: each range's two ends.
  • The edges are a temporary set, as the portal's _customBinsFromScatterPlotSelectionSet is a set of its own (legacy-spec 30-study-summary.md STS-SC-6, STS-BAR-5):
    • They are kept for the page only, in memory; nothing is written to the reader's Custom Bins.
    • Each drag replaces them.
    • They apply only while the draft still holds that drag's range (withDensityBins, laid over the reader's bins when Explore is asked). Removing the filter, Clear All Filters, or a selection on the bars, which replaces the chart's filter, drops them.
    • So they do not pile up, do not survive a reload, and leave the reader's bins, and with them Log Scale, as they were.

Spec IDs

  • Covered: STS-SC-6 (the bounds become custom edges on the two bar charts).
  • Unchanged: the two range clauses themselves (Mutation Count rounded to whole counts, FGA by the axis span).

Verification

  • Browser, dev server, coadread:
    • A drag over the populated corner sets FGA 0 – 0.38 and Mutation Count 271 – 5,684; 74 patients match.
    • The Mutation Count bars gain (240, 271], (271, 5,684] and >5,684.
    • The FGA bars gain (0.35, 0.38], (0.38, 0.4] and ≤0.
    • Browser storage holds no bins after the drag, and Clear All Filters brings back the default bars (≤20 … >240).
    • No page errors.
    • (A drag over an empty region of the plot gives 0 patients, and the grid then shows its empty state; that was so before this change too.)
  • Unit tests: test/study-view-density-spec.test.ts: a drag's ranges give each attribute its two ends, and on Mutation Count's bars those join the bars' own edges; the edges apply while the draft holds the drag's range, and not once it is removed, cleared or replaced; the reader's bins are not changed. npm test 6,811 pass, 0 fail.
  • Coverage: passes.
  • Planted bugs: 2 in scripts/mutants/study-view/density-bins.ts (guard unit), one of them edges that outlive the filter.

Tracker

Under "Study View → summary charts", this line (docs/PORTAL-PARITY.md:409) is ticked:

Scorecard 30-study-summary.md, row STS-SC-6 (was | STS-SC-6 | 🟡 | C | Drag a box → two range clauses (MC rounded to whole counts, FGA by span) (\explore-charts.tsx:89-92`); no custom bins added to the bar charts |`):

| STS-SC-6 | ✅ | C | Drag a box → two range clauses (MC rounded to whole counts, FGA by span), and their ends added to the two bar charts as a temporary set of edges while the filters hold (withDensityBins) |

Preview

/lab?tab=explore&study=coadread_tcga_pan_can_atlas_2018: drag a box on the density chart's lower-left corner, then look at the Mutation Count and FGA bars.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q3ezTaCo6wHFVsML6Qd4ht

alisman and others added 2 commits November 19, 2026 11:48
…m bins (STS-SC-6)

As the portal's _customBinsFromScatterPlotSelectionSet: dragging a box on
the Mutation Count vs FGA density sets the two range filters and adds
each range's ends to that attribute's bar chart as custom edges, so the
selection is drawn as bars of its own. Shares the pill edit's rule
(addBinEdges, binsAfterEdit).

Verified on coadread: a drag over the populated corner, FGA [0, 0.38],
Mutation Count [271, 5684], 74 patients; the bars gain (240, 271],
(271, 5,684], >5,684 and (0.35, 0.38], (0.38, 0.4].

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q3ezTaCo6wHFVsML6Qd4ht
@vercel

vercel Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cbiolab-genie Ready Ready Preview Nov 19, 2026 12:49pm UTC
cbiolab-new Ready Ready Preview Nov 19, 2026 12:49pm UTC
cohort-lab Ready Ready Preview Nov 19, 2026 12:49pm UTC

Request Review

@alisman

alisman commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Review verdict: changes requested

The wiring is right: a drag adds each range's two ends to the Mutation Count and FGA bars, both edits accumulate correctly through binStore, and the filter clauses are unchanged. The problem is where the edges are stored.

Blocking

  • The density edges become the reader's permanent custom bins, which legacy does not do. addDensitySelection → addBinEdges → setChartBins writes {method: "custom"} into the localStorage bin store. On the portal, _customBinsFromScatterPlotSelectionSet is a separate set, separate from the reader's Custom Bins. Each drag replaces it, Reset ↶ clears it, and a selection on the MC/FGA bars clears it too (docs/legacy-spec/30-study-summary.md:284, :517-518). In this PR:
    • the edges survive Reset and reloads;
    • every new drag adds two more edges, so they pile up;
    • selecting on the bars leaves them in place.
  • Regression with Study View bars: the portal's tooltip, 10ⁿ log ticks, Log Scale clears the filter (STS-BAR-3, -4, -7) #439 (Log Scale). Once the bins are custom, lib/data-binner.ts:206 takes the custom branch ahead of the log branch at :217. The merged edges (for example 271) also stop passing looksLogarithmic, so logScaleOffered is false. Result: after one density drag, the Mutation Count chart's Log Scale item disappears and stays gone, even after Reset. The only way back is to clear Custom Bins by hand.
  • Fix without the user: keep the scatter edges in their own non-persisted state for each attribute. Replace them on each drag, drop them when the density filter is removed or a bar selection is made on that chart, and merge them into the bin request only while they are set. Add a test for the clear and replace behaviour.

Non-blocking (nit)

  • Edge semantics: the clause is gte..lte, which includes both ends, but the bars are (a, b]. A sample whose Mutation Count equals the range's start (common with whole counts) is in the filter but is drawn in the bar below, (240, 271]. So the bar (271, 5,684] can show fewer samples than the filter matches. On the portal the filter is start < x ≤ end and matches the bar exactly. The clause rule predates this PR, so this isn't blocking here.
  • addBinEdges and addDensitySelection were inserted between addClauses and its JSDoc ("Deliberately plainer than addClause…"). That comment now sits on top of addBinEdges.
  • The test checks densityBinEdges plus binsAfterEdit, not the addDensitySelection wiring. That's fine for now, but the fix above should come with a test of the clear/replace rule.

CI: gate-e2e failed on infrastructure, not on this PR's code. The job died in "Install Playwright browsers": apt couldn't reach the Ubuntu mirrors (Could not wait for server fd, then E: Failed to fetch …fonts-ipafont-gothic…, Failed to install browsers, exit code 100). It failed before any test ran. Everything else is green (gate-local, gate-warehouse, coverage, lint, reports); planted-bugs is still pending. A re-run should clear it.

…der's Custom Bins

Review of #449. As the portal's _customBinsFromScatterPlotSelectionSet:
a drag's edges are kept for the page only (a ref), each drag replaces
them, and they apply only while the draft holds that drag's range
(withDensityBins), so removing the filter, Clear All or a selection on
the bars drops them. Nothing is written to the reader's Custom Bins, so
they no longer pile up, survive a reload, or keep Log Scale hidden.

Verified on coadread: a drag adds (240, 271], (271, 5,684] to Mutation
Count; browser storage holds no bins; Clear All restores the default bars.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q3ezTaCo6wHFVsML6Qd4ht
@alisman

alisman commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Fixed in 26998c0.

Blocking

  1. Separate and temporary. The drag's edges are no longer written to the reader's Custom Bins. They live in a page-only ref (densityBins): each drag replaces it, and withDensityBins (lib/study-view-density.ts) lays the edges over the reader's bins when Explore is asked, only while the draft still holds that drag's exact range. Removing the filter, Clear All Filters, or a selection on the MC/FGA bars, which replaces the chart's filter, drops them, as the portal's Reset and bar selection do. Nothing reaches localStorage. Checked on coadread: the edges during the selection, browser storage holds no bins, Clear All restores ≤20 … >240.
  2. Log Scale. Since the reader's settings are never changed, the binner's custom branch only runs while the drag's filter stands. Once it goes, the chart bins as before, and Log Scale is offered again wherever looksLogarithmic holds. While a drag's edges are drawn the bars are custom, as the portal's are during a scatter selection.

Nit

  • Inclusive lower bound vs (a, b] bars: right. The density clause is gte, which predates this PR; the portal's {start, end} is start < x ≤ end. Changing the clause changes cohort counts, so I'd rather do it in its own small PR than fold it in here. I'll put it on my list.

Unit tests cover the set: applied while held; dropped when removed, cleared or replaced; the reader's bins unchanged. A planted bug (edges outliving the filter) is guarded by them.

The generic constraint { bins?: unknown } is a weak type, so the test's
reader bins ({ showNa }) failed tsc on the test file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q3ezTaCo6wHFVsML6Qd4ht
Comment thread lib/study-view-density.ts
* The edges a drag box's ranges add to their attributes' bar charts, as the portal adds them as
* custom bins (STS-SC-6, _customBinsFromScatterPlotSelectionSet): each range's two ends.
*/
export interface DensityBins { attribute: string; range: { gte: number; lte: number }; edges: number[] }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nit: DensityBins and withDensityBins were inserted between densityBinEdges and its JSDoc ("The edges a drag box's ranges add…: each range's two ends"), so that comment now documents the DensityBins interface. Move the comment down to densityBinEdges.

* these clauses only mean what they mean together.
*/
/** a numeric chart's bars, plus these edges as custom bins, so a range filtered on is drawn as its own bars (STV-FB-4, STS-SC-6) */
const addBinEdges = (attribute: string, ends: number[]) => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nit: still open from the last round. addClauses's JSDoc ("Deliberately plainer than addClause…") sits above addBinEdges, with addDensitySelection between them and addClauses itself. Moving addBinEdges/addDensitySelection above that comment, or below addClauses, puts it back on its function.

@alisman

alisman commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Re-review verdict: pass (26998c0, 5539663)

Both earlier blocking findings are fixed.

  • Temporary set, not the reader's Custom Bins. The drag's edges live in a page-only ref (densityBins). Nothing goes to the localStorage bin store or the URL. Each drag reassigns the ref. withDensityBins lays the edges over the reader's bins only while the draft holds that drag's exact {gte, lte} range. Clear All (clearDraft), removing the pill, and a selection on the MC/FGA bars all drop it, since selectBins/toggleBin go through replaceChart and write gt ranges. This matches _customBinsFromScatterPlotSelectionSet (legacy-spec 30-study-summary.md:284, :517).
  • Log Scale. The reader's settings are never changed, so the binner takes the custom branch only while the drag's filter stands. Once the filter is cleared, the default (log) bars come back and logScaleOffered holds again. While the set is active the bars are custom, so Log Scale is hidden unless disableLog is set. That is legacy's rule too (isLogScaleByDataBins on the custom data bins, STS-BAR-7). Toggling Log Scale also clears the chart's filter, and with it the set.
  • Tests. The new unit test pins applied-while-held, dropped when removed, cleared (null) or replaced by a bar selection, and the reader's bins left unchanged. The planted bug density-bins-outlive-filter is guarded by it. The hook wiring itself isn't unit-tested, which is acceptable here.

Non-blocking

  • nit (inline): densityBinEdges' JSDoc now sits on the DensityBins interface, and addClauses' JSDoc still sits on addBinEdges.
  • The inclusive gte lower bound vs (a, b] bars: the author will fix it in a separate PR. Agreed, because changing it changes cohort counts.
  • Not this PR's doing: a second drag appends its clauses with addClauses, as on master, rather than replacing the first drag's filters as the portal does. So while drag 1's filter stands, drag 1's edges carry into drag 2's set through the current bars. That's consistent with what's filtered, but it's worth a follow-up if the drag should replace.

CI: no failures. gate-local, gate-e2e, gate-warehouse and lint were still pending at review time; reports, coverage and Vercel were green.

@alisman
alisman added this pull request to the merge queue Nov 19, 2026
Merged via the queue into master with commit cd30f7b Nov 19, 2026
18 of 20 checks passed
@alisman
alisman deleted the studyview-density-bins branch November 19, 2026 13:33

This branch was successfully deployed

1 active deployment
Preview – cohort-lab — 55396630 Deployed Nov 19, 2026 by vercel[bot]
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.

1 participant