Remember result dimension selections between variables#329
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Results page variable/dimension selector logic so that dimension selections (including “All” and “Sum”) persist when switching between variables that share the same underlying classification (e.g., RTI regions, T2TI technologies), addressing issue #324.
Changes:
- Introduces per-classification caches for selected dimension values and aggregate (“Sum”) flags.
- Initializes dimension selectors from the cached selections when the same classification is encountered again.
- Updates caches when users change dimension selections or aggregation options.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if not hasattr(state, 'dim_selection_cache'): | ||
| state.dim_selection_cache = {} | ||
| if not hasattr(state, 'dim_aggregate_cache'): | ||
| state.dim_aggregate_cache = {} |
| if dim_name in state.dim_selection_cache: | ||
| dim_select.value = [ | ||
| value for value in state.dim_selection_cache[dim_name] | ||
| if value in dim_values | ||
| ] | ||
| elif dim_values: | ||
| dim_select.value = [dim_values[0]] |
| def handler(e): | ||
| state.dim_selections[idx][f'dim{idx}_values'] = e.sender.value | ||
| selected_values = list(e.sender.value or []) | ||
| state.dim_selections[idx][f'dim{idx}_values'] = selected_values | ||
| state.dim_selection_cache[dim_key] = selected_values | ||
| update_plot() |
| selected_values = list(vals) if e.value else [] | ||
| if e.value: | ||
| selector.value = vals | ||
| selector.value = selected_values | ||
| else: | ||
| selector.value = [] | ||
| selector.value = selected_values |
|
@copilot: question only, do not make code changes. When I go to settings and come back to the graph, the line disappears. I only have to reselect one dimension for it to reappear, but what can I do to make that more sticky? @Sanatparida01: I've tested it, and it's a great improvement. This is going to save users a lot of headaches. Thanks so much! Of the copilot suggestions, the first, third and last seem valid. Could you implement those (or ask copilot to implement if you're able to click on those too). |
This behavior is currently due to the Results view being reconstructed when you return from Settings, while the chart redraw only happens after a selector change event. For now, the practical workaround is exactly what you found: toggle/reselect one dimension to trigger a redraw. To make it sticky long-term, the fix is to persist the active dimension selections in page state and trigger a plot refresh when the Results page is shown (not only on selector-change handlers). |
|
@Femkemilene Thanks for the review. I’ve implemented the first, third, and last Copilot suggestions: |
Fixes #324.
This PR updates the Results page so that dimension selections are remembered by classification when switching between variables. For example, if two variables both use Region or the same FTT:P technology classification, the selected values are kept instead of resetting to the first available option.
I tested this locally with FTT-P results. Switching between MEWG and MEWS preserved the selected regions and FTT:P technologies. I also tested the All/Sum options for matching classifications, and these were preserved when switching between variables with the same dimension setup.
I additionally checked a variable with a different dimension setup, PRSCX. In that case, the selected regions were preserved, but the FTT:P technology selector was not shown, which is expected because PRSCX does not use that technology dimension.
I also tried a few other variable switches to check that selections are only carried over when the underlying classifications match.