Skip to content

Commit c3a2463

Browse files
erwardenaarclaude
andcommitted
Fix: scatter bubble click now correctly opens model card
- Read scatter selection from session_state before st.plotly_chart (on_select='rerun' triggers an immediate rerun, so post-chart code never runs in the same cycle) - Add selection_source tracking ('scatter' | 'grid' | None) so grid's else-branch no longer clears selected_model when the scatter plot is the selection owner - Guard grid deselect: only clear selected_model when selection_source == 'grid' - Reset selection_source in profile _close() alongside the other session state keys Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 889d697 commit c3a2463

22 files changed

Lines changed: 27 additions & 18 deletions

app/components/grid.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ def render_grid(filtered: list[dict]) -> None:
8181
row_idx = selection.selection.rows[0]
8282
if row_idx < len(display_df):
8383
st.session_state.selected_model = display_df.iloc[row_idx]["name"]
84+
st.session_state.selection_source = "grid"
8485
else:
85-
# Row was deselected — close the profile card.
86-
st.session_state.selected_model = None
86+
# Only close the profile card if the grid was the component that opened
87+
# it. If the source was the scatter plot, leave selected_model alone —
88+
# the grid has no highlighted row in that case, but that is expected.
89+
if st.session_state.get("selection_source") == "grid":
90+
st.session_state.selected_model = None
91+
st.session_state.selection_source = None

app/components/profile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def _close() -> None:
2626
st.session_state.selected_model = None
2727
st.session_state.pop("grid", None)
2828
st.session_state.pop("scatter", None)
29+
st.session_state.pop("selection_source", None)
2930
st.rerun()
3031

3132

app/components/scatter.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,22 +180,24 @@ def render_scatter(filtered: list[dict]) -> None:
180180
selected = st.session_state.get("selected_model")
181181
fig = _build_figure(df, x_axis, y_axis, selected)
182182

183-
event = st.plotly_chart(
184-
fig,
185-
width="stretch",
186-
on_select="rerun",
187-
key="scatter",
188-
)
189-
190-
# Extract the clicked model name from the event.
183+
# Handle click from the PREVIOUS rerun cycle.
184+
# on_select='rerun' triggers a full rerun immediately, so any code after
185+
# st.plotly_chart never executes in the same cycle the click occurred.
186+
# Reading from session_state here (before the chart call) captures the
187+
# selection that was stored during that previous cycle.
191188
# customdata[0] is the first element of the custom_data=["name"] list —
192189
# more reliable than "hovertext", which has changed key names across
193190
# Plotly/Streamlit minor versions.
194-
if event and event.selection and event.selection.points:
195-
point = event.selection.points[0]
191+
prev = st.session_state.get("scatter")
192+
if prev and prev.selection and prev.selection.points:
193+
point = prev.selection.points[0]
196194
name = (point.get("customdata") or [None])[0] or point.get("hovertext")
197-
if name:
195+
if name and name != st.session_state.get("selected_model"):
198196
st.session_state.selected_model = name
197+
st.session_state.selection_source = "scatter"
198+
st.rerun()
199+
200+
st.plotly_chart(fig, width="stretch", on_select="rerun", key="scatter")
199201

200202
note = "Bubble area encodes model size; models over 100 B are capped. Use fullscreen for detail."
201203
if x_axis == "training_tokens_b" or y_axis == "training_tokens_b":

docs/flowchart.png

49 KB
Loading

docs/scenarioafilter1.png

29.4 KB
Loading

docs/scenarioafilter2.png

28.4 KB
Loading

docs/scenarioamodelcard.png

196 KB
Loading

docs/scenarioaresults.png

70.2 KB
Loading

docs/scenariobfilter.png

40 KB
Loading

docs/scenariobresults.png

99.8 KB
Loading

0 commit comments

Comments
 (0)