Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@sfc-gh-nbellante
Copy link
Contributor

@sfc-gh-nbellante sfc-gh-nbellante commented Jul 31, 2025

Describe your changes

The issue occurs because the color scale in the Vega-Lite specification lacks an explicit domain parameter. When we generate a color scale with multiple colors for multiple y columns, it should include domain: ['c_one', 'b_two', 'a_three'] to ensure the colors are mapped in the user-specified order rather than alphabetically.

GitHub Issue Link (if applicable)

Fixes #12071

Testing Plan

Added e2e tests with snaps


Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@snyk-io
Copy link
Contributor

snyk-io bot commented Jul 31, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@github-actions
Copy link
Contributor

github-actions bot commented Jul 31, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-12092/streamlit-1.47.1-py3-none-any.whl
🕹️ Preview app pr-12092.streamlit.app (☁️ Deploy here if not accessible)

@sfc-gh-nbellante sfc-gh-nbellante added change:bugfix PR contains bug fix implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR labels Jul 31, 2025
@sfc-gh-nbellante sfc-gh-nbellante changed the title fixing the bug [fix] Assign st.line_chart colors by assigned order, not alphabetically Jul 31, 2025
@sfc-gh-nbellante sfc-gh-nbellante marked this pull request as ready for review July 31, 2025 22:09
@lukasmasuch lukasmasuch requested a review from Copilot July 31, 2025 22:18
Copy link
Contributor

Copilot AI left a 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 bug where st.line_chart colors were assigned alphabetically rather than in the order specified by the user. The fix ensures that when multiple y-columns are provided with custom colors, the color mapping respects the user-specified column order.

Key changes:

  • Added explicit domain parameter to Vega-Lite color scale specification
  • Added e2e test to verify column order preservation with colors

Reviewed Changes

Copilot reviewed 3 out of 9 changed files in this pull request and generated no comments.

File Description
lib/streamlit/elements/lib/built_in_chart_utils.py Added domain parameter to color scale to preserve user-specified column order
e2e_playwright/st_line_chart.py Added test case with non-alphabetical column names and explicit colors
e2e_playwright/st_line_chart_test.py Added e2e test to verify column order is preserved when using y and color parameters
Comments suppressed due to low confidence (1)

e2e_playwright/st_line_chart_test.py:132

  • The hover action appears to be intended to trigger a tooltip for verification, but the test doesn't actually verify the tooltip content or check that the column order is correct. Consider adding assertions to verify the tooltip shows the expected column names in the correct order, or remove the hover if it's not needed for the snapshot test.
    chart_canvas.hover(position={"x": 50, "y": 100}, force=True)

Copy link
Collaborator

@lukasmasuch lukasmasuch Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something seems wrong with these snapshots :( They got cut off on the top ... not sure what happened here. But its consistent across the browsers, so might be related to how vega lite is processing the domain value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's a good point, I didn't notice that. I wonder what's going on there. I'll debug.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to try swapping the order of the tests as the issue seen in the snapshot does not repro locally in that test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that fixed it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it's probably the header bar overlaying the chart

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense

Copy link
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@sfc-gh-nbellante sfc-gh-nbellante enabled auto-merge (squash) July 31, 2025 23:16
@sfc-gh-nbellante sfc-gh-nbellante merged commit 29887e4 into develop Jul 31, 2025
37 checks passed
@sfc-gh-nbellante sfc-gh-nbellante deleted the nico/bugfix-12071 branch July 31, 2025 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

st.line_chart uses columns in wrong order

3 participants