Skip to content

Accept CSS color formats supported by plotly.js in the color validator - #5868

Open
ShawnNotFound wants to merge 2 commits into
plotly:mainfrom
ShawnNotFound:fix-css-color-validation
Open

ShawnNotFound wants to merge 2 commits into
plotly:mainfrom
ShawnNotFound:fix-css-color-validation

Conversation

@ShawnNotFound

@ShawnNotFound ShawnNotFound commented Nov 3, 2026 •

Copy link
Copy Markdown

Link to issue

Closes #5867

Description of change

The color validator now accepts the CSS color syntax that plotly.js parses: signed and exponent numbers, angle units other than deg, the none keyword, any color() color space, and transparent. Before, values like lab(50% -40 59.5) or color(srgb 1 0 0) raised a ValueError even though plotly.js renders them.

Demo

import plotly.graph_objects as go

go.Scatter(marker_color="lab(50% -40 59.5)")
# before: ValueError: Invalid value of type 'builtins.str' received for the 'color' property of scatter.marker
# after: accepted

Testing strategy

Added valid and invalid cases to test_color_validator.py. I checked each of them against culori, the parser plotly.js uses, so the validator accepts and rejects the same strings.

Additional information (optional)

The old code removed spaces before matching so the regex didn't have to handle them. The new regex handles whitespace itself, so that step is gone. Strings that don't form a valid color function, like rgb(255, 0) or rgb(1-2 3 4), are still rejected.

Guidelines

Allow signed and exponent numbers, angle units other than deg, the none
keyword, any color() color space and the transparent keyword. These are
all accepted by plotly.js 4 but were rejected by the Python validator.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Color validator rejects CSS color formats that plotly.js accepts

1 participant