diff --git a/_plotly_utils/basevalidators.py b/_plotly_utils/basevalidators.py index d094e27aae..81c413b4c4 100644 --- a/_plotly_utils/basevalidators.py +++ b/_plotly_utils/basevalidators.py @@ -1211,7 +1211,7 @@ class ColorscaleValidator(BaseValidator): named_colorscales = [ 'Greys', 'YlGnBu', 'Greens', 'YlOrRd', 'Bluered', 'RdBu', 'Reds', 'Blues', 'Picnic', 'Rainbow', 'Portland', 'Jet', 'Hot', 'Blackbody', - 'Earth', 'Electric', 'Viridis' + 'Earth', 'Electric', 'Viridis', 'Cividis' ] def __init__(self, plotly_name, parent_name, **kwargs): @@ -1229,7 +1229,7 @@ def description(self): - One of the following named colorscales: ['Greys', 'YlGnBu', 'Greens', 'YlOrRd', 'Bluered', 'RdBu', 'Reds', 'Blues', 'Picnic', 'Rainbow', 'Portland', 'Jet', - 'Hot', 'Blackbody', 'Earth', 'Electric', 'Viridis'] + 'Hot', 'Blackbody', 'Earth', 'Electric', 'Viridis', 'Cividis] """.format(plotly_name=self.plotly_name) return desc @@ -1274,9 +1274,11 @@ def validate_coerce(self, v): return v def present(self, v): - # Return tuple of tuples so that colorscale is immutable + # Return-type must be immutable if v is None: return None + elif isinstance(v, string_types): + return v else: return tuple([tuple(e) for e in v]) diff --git a/_plotly_utils/tests/validators/test_colorscale_validator.py b/_plotly_utils/tests/validators/test_colorscale_validator.py index 74ffb41877..fa2dda20e4 100644 --- a/_plotly_utils/tests/validators/test_colorscale_validator.py +++ b/_plotly_utils/tests/validators/test_colorscale_validator.py @@ -11,7 +11,8 @@ def validator(): @pytest.fixture(params=['Greys', 'YlGnBu', 'Greens', 'YlOrRd', 'Bluered', 'RdBu', 'Reds', 'Blues', - 'Picnic', 'Rainbow', 'Portland', 'Jet', 'Hot', 'Blackbody', 'Earth', 'Electric', 'Viridis']) + 'Picnic', 'Rainbow', 'Portland', 'Jet', 'Hot', 'Blackbody', 'Earth', 'Electric', + 'Viridis', 'Cividis']) def named_colorscale(request): return request.param @@ -26,6 +27,8 @@ def test_acceptance_named(named_colorscale, validator: ColorscaleValidator): # Uppercase assert (validator.validate_coerce(named_colorscale.upper()) == named_colorscale.upper()) + + assert validator.present(named_colorscale) == named_colorscale # ### Acceptance as array ### @pytest.mark.parametrize('val', [ diff --git a/plotly/tests/test_core/test_graph_objs/test_properties_validated.py b/plotly/tests/test_core/test_graph_objs/test_properties_validated.py index a7e25c9902..897b2104c7 100644 --- a/plotly/tests/test_core/test_graph_objs/test_properties_validated.py +++ b/plotly/tests/test_core/test_graph_objs/test_properties_validated.py @@ -102,6 +102,16 @@ def test_present_colorscale(self): # Presented as tuple of tuples self.assertEqual(self.scatter.marker.colorscale, ((0, 'red'), (1, 'green'))) + + def test_present_colorscale_str(self): + self.assertIsNone(self.scatter.marker.colorscale) + + # Assign string + self.scatter.marker.colorscale = "Viridis" + + # Presented as a string + self.assertEqual(self.scatter.marker.colorscale, + "Viridis") class TestPropertyIterContains(TestCase):