From 4543ebe118ca64a0f4a704a5848abe5905883723 Mon Sep 17 00:00:00 2001 From: wbrgss Date: Tue, 30 Apr 2019 19:01:09 -0400 Subject: [PATCH 1/3] Accept `var(--*)` as valid colors --- _plotly_utils/basevalidators.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/_plotly_utils/basevalidators.py b/_plotly_utils/basevalidators.py index c1f0d193341..5c5e1a5df64 100644 --- a/_plotly_utils/basevalidators.py +++ b/_plotly_utils/basevalidators.py @@ -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", @@ -1232,6 +1233,11 @@ def perform_validate_coerce(v, allow_number=None): elif v_normalized in ColorValidator.named_colors: # Valid named color (e.g. 'coral') 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 else: # Not a valid color return None From fdeff74691e599c4ae937039bb5eb6d41566ee35 Mon Sep 17 00:00:00 2001 From: wbrgss Date: Tue, 30 Apr 2019 19:02:49 -0400 Subject: [PATCH 2/3] Add var(--*) values to color validator acceptance tests --- _plotly_utils/tests/validators/test_color_validator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_plotly_utils/tests/validators/test_color_validator.py b/_plotly_utils/tests/validators/test_color_validator.py index 0ffb31a2f14..480bd0ef625 100644 --- a/_plotly_utils/tests/validators/test_color_validator.py +++ b/_plotly_utils/tests/validators/test_color_validator.py @@ -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 @@ -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 From ff0c44e2b2721d6b124a7f5e17d5a18fe20ed2ef Mon Sep 17 00:00:00 2001 From: wbrgss Date: Tue, 30 Apr 2019 19:07:35 -0400 Subject: [PATCH 3/3] More sensible order Group regex match condition with similar conditions --- _plotly_utils/basevalidators.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/_plotly_utils/basevalidators.py b/_plotly_utils/basevalidators.py index 5c5e1a5df64..2e69546e546 100644 --- a/_plotly_utils/basevalidators.py +++ b/_plotly_utils/basevalidators.py @@ -1230,14 +1230,14 @@ 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 v_normalized in ColorValidator.named_colors: - # Valid named color (e.g. 'coral') - 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 else: # Not a valid color return None