-
Notifications
You must be signed in to change notification settings - Fork 4k
Add support for setting metric delta colors from color palette #13153
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!
|
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 adds support for setting delta colors from the color palette in st.metric, expanding the delta_color parameter beyond the existing "normal", "inverse", and "off" modes to include eight additional named colors: "red", "orange", "yellow", "green", "blue", "violet", "gray"/"grey", and "primary".
Key Changes
- Extended the
delta_colorparameter to accept named color values from the basic color palette - Maintains backward compatibility with existing "normal", "inverse", and "off" modes
- Added comprehensive unit tests and visual E2E tests for the new color options
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| proto/streamlit/proto/Metric.proto | Added 5 new enum values (ORANGE, YELLOW, BLUE, VIOLET, PRIMARY) to MetricColor enum for protobuf communication |
| lib/streamlit/elements/metric.py | Extended DeltaColor TypeAlias, added color-to-proto mapping dict, updated validation logic and parameter documentation |
| lib/tests/streamlit/elements/metric_test.py | Added parameterized tests for all 9 named colors, updated invalid color test to use partial string matching |
| frontend/lib/src/theme/getColors.ts | Extended getMetricColor, getMetricBackgroundColor, and getMetricTextColor functions to handle new color values |
| frontend/lib/src/theme/getColors.test.ts | Refactored tests to use it.each parameterization, added coverage for all new color values including special handling for PRIMARY |
| e2e_playwright/st_metric.py | Added two metrics with custom delta colors (yellow and primary) for visual testing |
| e2e_playwright/st_metric_test.py | Added snapshot test for custom delta color rendering in both light and dark themes |
| delta: Delta, | ||
| ) -> MetricColorAndDirection: | ||
| if delta_color not in {"normal", "inverse", "off"}: | ||
| if delta_color not in _VALID_DELTA_COLORS: |
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.
[nit] Maybe use:
if delta_color not in _DELTA_COLOR_TO_PROTO and delta_color not in ["normal", "inverse", "off"]:
...
or similar just to avoid having two lists of valid color names that should be in sync.
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.
Good point, updated the set above to use the keys from _DELTA_COLOR_TO_PROTO
|
LGTM, just one suggestion. |
Describe your changes
Adds support for setting
delta_colorofst.metricto any of the colors from our configurable color palette.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.