Skip to content

Fix EquilibriumPlot crash on empty/sparse data - #218

Draft
meganrm wants to merge 1 commit into
mainfrom
fix/equilibrium-plot-empty-data-crash
Draft

Fix EquilibriumPlot crash on empty/sparse data#218
meganrm wants to merge 1 commit into
mainfrom
fix/equilibrium-plot-empty-data-crash

Conversation

@meganrm

@meganrm meganrm commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Problem

Estimated review size: small

EquilibriumPlot crashed / produced NaN garbage when fewer than 3 equilibrium points had been recorded. Math.max(...x) and the bestFit regression (regression.logarithmic/regression.exponential) ran unconditionally, before the component's own bestFitVisible = x.length >= 3 guard — which only gated display, not the computation itself.

Fixes #225

Solution

Guarded the bestFit useMemo and the standalone Math.max(...x) with the same x.length >= 3 threshold already used elsewhere in the component, short-circuiting to a safe default ({ x: [], y: [], value: NaN }) when there isn't enough data. No behavior change for 3+ points — the plot already correctly hid the best-fit line/indicator below 3 points, this just stops the underlying computation from crashing on the way there.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Change summary:

  • Guard bestFit regression against empty/too-few data points
  • Guard standalone Math.max(...x) the same way
  • Guard tickvals so it doesn't push NaN when the best-fit line isn't visible

Steps to Verify:

  1. Start a High Affinity, Low Affinity, or Competitive Binding experiment
  2. Before recording any equilibrium points, confirm the plot renders without error
  3. Record 1-2 points — confirm no crash, no best-fit line (unchanged from prior behavior)
  4. Record 3+ points — confirm the best-fit line / Kd or Ki indicator still renders correctly, unchanged from before

Screenshots (optional):

Keyfiles (delete if not relevant):

  1. src/components/plots/EquilibriumPlot.tsx

Thanks for contributing!

…a points (B3, B8)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@meganrm
meganrm requested a review from a team as a code owner August 11, 2026 23:54
@meganrm
meganrm requested review from frasercl and toloudis and removed request for a team August 11, 2026 23:54
@meganrm
meganrm marked this pull request as draft August 12, 2026 17:45
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.

EquilibriumPlot crashes on empty/sparse data (Math.max(...[]), unguarded regression)

1 participant