Add support for selections on multi-view vega charts#13591
Add support for selections on multi-view vega charts#13591lukasmasuch merged 8 commits intodevelopfrom
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ PR preview is ready!
|
📉 Frontend coverage change detectedThe frontend unit test (vitest) coverage has decreased by 0.0000%
✅ Coverage change is within normal range. |
|
@cursor review |
There was a problem hiding this comment.
Pull request overview
This PR adds support for selections on multi-view (composite) Vega/Altair charts by removing the previous restriction and implementing recursive parameter extraction to find selections at any level of the view hierarchy.
Changes:
- Modified
_extract_selection_parameters()to recursively traverse composite view specs (layer, hconcat, vconcat, concat, facet, repeat) - Removed the
_disallow_multi_view_charts()restriction from the selection activation flow - Added comprehensive documentation about field/encoding requirements for consistent selection output in multi-view charts
- Added extensive unit tests and E2E tests covering various multi-view chart types and selection scenarios
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| lib/streamlit/elements/vega_charts.py | Updated _extract_selection_parameters() to recursively traverse multi-view specs; removed _disallow_multi_view_charts() call; added documentation about fields/encodings in multi-view selections |
| lib/tests/streamlit/elements/vega_charts_test.py | Renamed and updated test for multi-view selections; added comprehensive test classes for Altair and Vega-Lite multi-view selections covering layer, concat, facet, repeat, and nested scenarios |
| e2e_playwright/st_altair_chart_multiview_select.py | New E2E test app with multi-view charts using various selection types |
| e2e_playwright/st_altair_chart_multiview_select_test.py | New E2E tests for multi-view chart selections with different chart types |
SummaryThis PR adds support for selections on multi-view Vega-Lite charts (layer, hconcat, vconcat, concat, facet, and repeat compositions). Previously, selections on multi-view charts were explicitly blocked with a
This closes GitHub issue #8643. Code QualityStrengths:
Issues:
def _extract_selection_parameters(spec: VegaLiteSpec) -> set[str]:
"""Extract the names of all valid selection parameters from the spec.
This function recursively traverses composite view specs (layer, hconcat,
vconcat, concat, facet, repeat) to find all selection parameters, regardless
of where they are defined in the spec hierarchy.
Altair automatically hoists params to the top level, but raw Vega-Lite specs
may have params defined at any level in the view hierarchy.
"""
if not spec:
return set()
param_names: set[str] = set()
# Extract from top-level params
if "params" in spec:
for param in spec["params"]:
# Check if it looks like a valid selection parameter:
# https://vega.github.io/vega-lite/docs/selection.html
if param.get("name") and param.get("select"):
param_names.add(param["name"])
# Recursively check composite view specs (layer, hconcat, vconcat, concat).
# Non-dict entries in the list are silently skipped as they are malformed.
for key in ("layer", "hconcat", "vconcat", "concat"):
if key in spec and isinstance(spec[key], list):
for child_spec in spec[key]:
if isinstance(child_spec, dict):
param_names.update(_extract_selection_parameters(child_spec))
# Check facet/repeat spec (the inner view specification)
if "spec" in spec and isinstance(spec["spec"], dict):
param_names.update(_extract_selection_parameters(spec["spec"]))
return param_namesThe implementation correctly handles edge cases by checking Test CoverageUnit Tests (Excellent): The PR adds two comprehensive test classes:
All tests include:
E2E Tests (Good): New E2E tests cover:
The tests follow best practices:
Minor observation: The E2E tests use fixed pixel coordinates for click positions (e.g., Backwards CompatibilityNo breaking changes. This PR removes a restriction rather than changing existing behavior:
Users who were not using selections on multi-view charts are unaffected. Users who were blocked by the previous limitation can now use this feature. Security & RiskLow risk. The changes are isolated to:
No new attack vectors are introduced. The recursive function has proper termination conditions ( Recommendations
VerdictAPPROVED: This PR is well-implemented with comprehensive test coverage. It enables a highly requested feature (selections on multi-view charts) while maintaining backwards compatibility. The only suggestion is to clean up the dead code ( This is an automated AI review. Please verify the feedback and use your judgment. |
SummaryAdds multi-view selection support by recursively extracting selection params from Vega-Lite specs, plus new Altair/Vega-Lite unit tests and e2e coverage for multi-view selection interactions. Code QualityOverall structure is clear, and the new recursive extraction logic is easy to follow. One robustness gap: Test CoverageGood breadth: unit tests cover layer/hconcat/vconcat/facet/repeat/nested compositions and multi-selection filters, plus raw Vega-Lite nested param cases. The new e2e tests cover layer, hconcat, vconcat, and multi-selection interactions. Consider adding a small “must NOT happen” assertion per e2e scenario (e.g., selection text absent before interaction) to align with e2e best practices ( Backwards CompatibilityChange is additive: previously unsupported multi-view selections are now enabled. No API or behavioral breakages detected for existing single-view charts. Security & RiskNo security concerns spotted. The primary risk is potential e2e flakiness from fixed pixel click/drag coordinates and CSS locators ( Recommendations
VerdictAPPROVED: Solid feature addition with good coverage; only minor robustness and test-style nits. This is an automated AI review using |
Describe your changes
Adds support for adding selections to multi-view vega-charts.
GitHub Issue Link (if applicable)
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.