[fix] Add selection support for treemap and sunburst in st.plotly_chart#13935
[fix] Add selection support for treemap and sunburst in st.plotly_chart#13935lukasmasuch merged 3 commits intodevelopfrom
st.plotly_chart#13935Conversation
Hierarchical charts (treemap, sunburst) don't emit plotly_selected events but do emit plotly_click events. Add onClick handler that captures these clicks and sends them as selection state for API consistency.
✅ PR preview is ready!
|
✅ 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. |
There was a problem hiding this comment.
Pull request overview
This pull request adds click event selection support for hierarchical Plotly charts (treemap and sunburst) to fix issue #9001. These chart types don't emit plotly_selected events like other charts, but they do emit plotly_click events that can be leveraged to provide the same selection functionality.
Changes:
- Added
handleClickEventfunction to process click events from hierarchical charts and convert them to selection state - Integrated the click handler into the PlotlyChart component with proper activation guards
- Added comprehensive unit tests and E2E tests for both treemap and sunburst chart selection
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
frontend/lib/src/components/elements/PlotlyChart/utils.ts |
Added handleClickEvent function to handle click events from hierarchical charts and emit selection data in a format consistent with other chart types |
frontend/lib/src/components/elements/PlotlyChart/PlotlyChart.tsx |
Integrated the click handler with proper conditional activation based on isSelectionActivated |
frontend/lib/src/components/elements/PlotlyChart/utils.test.ts |
Added comprehensive unit tests covering early returns, treemap/sunburst clicks, undefined pointNumber handling, and deduplication |
e2e_playwright/st_plotly_chart_select.py |
Added test app sections for treemap and sunburst charts with selection enabled |
e2e_playwright/st_plotly_chart_select_test.py |
Added parametrized E2E test verifying click interaction and selection data emission for both chart types |
Consolidated Code ReviewSummaryThis PR adds Key changes:
Code QualityBoth reviewers agree the implementation is clean and follows existing Plotly selection patterns well. The Selection mode gating (reviewers disagreed)gpt-5.3-codex-high flagged that Consolidated assessment: The concern is technically valid -- if a hierarchical chart were configured with only box/lasso modes (no "points"), click-based selections would still fire. However, this is a minor issue in practice because:
Recommendation (non-blocking): Gate the Other code observations (both reviewers agree):
Test CoverageBoth reviewers agree test coverage is strong for the primary scenarios:
Areas for improvement (both reviewers broadly agree):
Backwards CompatibilityBoth reviewers agree: This change is fully backwards compatible.
Security & RiskBoth reviewers agree: Low risk. All changes are frontend-only, processing client-side Plotly click events through the existing widget state mechanism. No new network calls, no new data sources, and no server-side changes. AccessibilityBoth reviewers agree: No accessibility concerns. No new interactive UI elements are introduced; the change leverages existing Plotly chart interaction patterns. RecommendationsOrdered by priority:
VerdictAPPROVED -- A clean, well-structured bugfix that correctly adds selection support for hierarchical Plotly charts. The implementation follows existing patterns, includes good test coverage, and poses minimal regression risk. The E2E locator fragility and selection_mode gating are real but non-blocking issues that can be addressed in this PR or as a follow-up. Both reviewers agree on the overall quality of the implementation. Consolidated review by 📋 Review by `gpt-5.3-codex-high`SummaryThis PR adds Code QualityThe implementation is generally clean and follows existing Plotly selection patterns, but there is one behavioral inconsistency that should be fixed before merge:
Test CoverageCoverage is strong for the primary happy path:
However, an important negative case is missing:
Backwards CompatibilityMost changes are additive and preserve existing behavior for default Security & RiskNo direct security concerns identified. AccessibilityNo accessibility regressions identified in this PR. The change is event wiring in an existing Plotly component and does not introduce new custom interactive DOM controls. Recommendations
VerdictCHANGES REQUESTED: The hierarchical click fix is directionally correct, but selection-mode semantics are currently violated for non-points configurations and should be corrected before merge. This is an automated AI review by 📋 Review by `opus-4.6-thinking`SummaryThis PR adds selection support for hierarchical Plotly chart types (treemap and sunburst) that don't emit native Key changes:
Code QualityThe implementation follows existing patterns well. The Minor observations:
Test CoverageUnit tests (
E2E tests (
Suggestions for improved coverage:
Backwards CompatibilityThis change is fully backwards compatible:
Security & Risk
Accessibility
Recommendations
VerdictAPPROVED: A clean, well-structured bugfix that correctly adds selection support for hierarchical Plotly charts. The implementation follows existing patterns, includes good test coverage, and poses minimal regression risk. The recommendations above are minor improvements that could be addressed in a follow-up. This is an automated AI review by |
st.plotly_chart
Split parameterized treemap/sunburst test into separate functions for clarity. Use isPointsSelectionActivated instead of isSelectionActivated for onClick handler to properly scope click events.
Reword comments to clearly explain why element.id is used instead of element in useCallback dependency arrays: the proto object gets a new reference on each render, but element.id only changes when the element actually changes.
…art` (#13935) ## Describe your changes - Adds `onClick` handler to capture click events from treemap and sunburst charts - Hierarchical charts don't emit `plotly_selected` events, but do emit `plotly_click` events - Selection data sent with consistent format including `id`, `parent`, `label`, `value`, and hierarchy-specific fields ## GitHub Issue Link (if applicable) Closes #9001 ## Testing Plan - [x] Unit Tests (JS) - [x] E2E Tests (treemap and sunburst selection) --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
Describe your changes
onClickhandler to capture click events from treemap and sunburst chartsplotly_selectedevents, but do emitplotly_clickeventsid,parent,label,value, and hierarchy-specific fieldsGitHub Issue Link (if applicable)
Closes #9001
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.