Skip to content

Enable DDK compatibility #1541

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

Merged
merged 3 commits into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions _plotly_utils/basevalidators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,7 @@ class ColorValidator(BaseValidator):
"""
re_hex = re.compile('#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})')
re_rgb_etc = re.compile('(rgb|hsl|hsv)a?\([\d.]+%?(,[\d.]+%?){2,3}\)')
re_ddk = re.compile('var\(\-\-.*\)')

named_colors = [
"aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
Expand Down Expand Up @@ -1229,6 +1230,11 @@ def perform_validate_coerce(v, allow_number=None):
# Valid rgb(a), hsl(a), hsv(a) color
# (e.g. rgba(10, 234, 200, 50%)
return v
elif fullmatch(ColorValidator.re_ddk, v_normalized):
# Valid var(--*) DDK theme variable, inspired by CSS syntax
# (e.g. var(--accent) )
# DDK will crawl & eval var(-- colors for Graph theming
return v
elif v_normalized in ColorValidator.named_colors:
# Valid named color (e.g. 'coral')
return v
Expand Down
4 changes: 2 additions & 2 deletions _plotly_utils/tests/validators/test_color_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def validator_aok_colorscale():
# Array not ok, numbers not ok
# ----------------------------
@pytest.mark.parametrize('val',
['red', 'BLUE', 'rgb(255, 0, 0)', 'hsl(0, 100%, 50%)', 'hsla(0, 100%, 50%, 100%)',
['red', 'BLUE', 'rgb(255, 0, 0)', 'var(--accent)', 'hsl(0, 100%, 50%)', 'hsla(0, 100%, 50%, 100%)',
'hsv(0, 100%, 100%)', 'hsva(0, 100%, 100%, 50%)'])
def test_acceptance(val, validator):
assert validator.validate_coerce(val) == val
Expand Down Expand Up @@ -58,7 +58,7 @@ def test_rejection(val, validator):
# ------------------------
# ### Acceptance ###
@pytest.mark.parametrize('val',
['red', 'BLUE', 23, 15, 'rgb(255, 0, 0)', 'hsl(0, 100%, 50%)', 'hsla(0, 100%, 50%, 100%)',
['red', 'BLUE', 23, 15, 'rgb(255, 0, 0)', 'var(--accent)', 'hsl(0, 100%, 50%)', 'hsla(0, 100%, 50%, 100%)',
'hsv(0, 100%, 100%)', 'hsva(0, 100%, 100%, 50%)'])
def test_acceptance_colorscale(val, validator_colorscale):
assert validator_colorscale.validate_coerce(val) == val
Expand Down