-
Notifications
You must be signed in to change notification settings - Fork 4k
[Fix] Altair charts with vconcat and hconcat #13423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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!
|
SummaryThis PR fixes issue #13410 where Altair charts containing nested Key changes:
Code QualityStrengths
Minor Observations
# Check if vconcat contains nested compositions
if "vconcat" in spec and isinstance(spec["vconcat"], list):
for item in spec["vconcat"]:
# Check if this item is a dict containing any composition operator
if isinstance(item, dict) and any(
k in item for k in ["hconcat", "vconcat", "concat", "layer"]
):
return True
Test CoveragePython Unit Tests ✅The test coverage is comprehensive and follows best practices:
Tests follow the guidelines:
E2E Tests ✅The E2E tests are appropriate and follow best practices:
Minor note: The E2E test imports Backwards CompatibilityLow risk of breaking changes:
Security & RiskNo security concerns identified. Low regression risk:
RecommendationsNo blocking issues found. The following are minor suggestions for future consideration (not required for this PR):
VerdictAPPROVED: This PR provides a well-implemented fix for issue #13410 with comprehensive test coverage, clear documentation of trade-offs, and minimal risk of regressions. The changes follow existing patterns in the codebase and are appropriately scoped. This is an automated AI review. Please verify the feedback and use your judgment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a rendering issue where Altair charts containing both HConcat and VConcat elements don't render (empty element) in Streamlit versions 1.42+. The fix introduces special autosize handling for nested composition charts to prevent "Infinite extent" errors while acknowledging a known limitation where these charts may overflow their container.
Key Changes
- Adds
_has_nested_composition()helper function to detect nested composition operators within vconcat specs - Modifies autosize configuration logic to use "pad" instead of "fit-x" for nested compositions
- Updates default width behavior to treat nested compositions like facet/hconcat charts (defaults to "content" instead of "stretch")
Reviewed changes
Copilot reviewed 4 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
lib/streamlit/elements/vega_charts.py |
Core fix: adds nested composition detection and adjusts autosize/width defaults |
lib/tests/streamlit/elements/vega_charts_test.py |
Comprehensive unit tests for nested compositions and autosize behavior |
e2e_playwright/st_altair_chart.py |
E2E test script with marginal histogram example (nested vconcat+hconcat) |
e2e_playwright/st_altair_chart_test.py |
E2E test assertion for new chart snapshot |
e2e_playwright/__snapshots__/ |
Visual regression test baselines (PNG snapshots) |
| True if the spec contains nested composition operators, False otherwise. | ||
| """ | ||
| # Check if vconcat contains nested compositions | ||
| if "vconcat" in spec and isinstance(spec["vconcat"], list): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Does this support all possible usecases that vconcat could be in? In other words, does this also need to be recursive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This supports all vconcat use cases (hconcat is already handled separately).
I re-confirmed that updating to recursion would not uncover any additional cases not already handled by the existing logic since in valid Vega-Lite specs, composition operators (hconcat, vconcat) are always top-level keys of a view specification. They can't be buried inside encoding, mark, or other nested properties.
|
Just a heads up that there have been flickering issues with these charts in connection with the width sizing options because some options from vega lead to a looping calculation of the width in conjunction with our element sizing. They typically show up when you go into full screen and then return back to the regular view and might not show up in the regression tests since it is hard to capture a flicker consistently. I don't think this will necessarily trigger the flicker, but just recommend manual testing. |
sfc-gh-lwilby
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
📈 Frontend coverage change detectedThe frontend unit test (vitest) coverage has increased by 0.0200%
✅ Coverage change is within normal range. |
Describe your changes
In streamlit versions 1.42 and above, Altair charts that contain both HConcat and Vconcat elements do not render (empty element). This resolves the rendering issue (but not the container width issue more specifically referenced in #9091 - based on upstream vega/vega-lite#5219).
GitHub Issue Link (if applicable)
Closes #13410
Testing Plan