From f4a6e4db873d1254f116b71dc80d80eef9819d77 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Sat, 26 Jan 2019 08:17:28 -0500 Subject: [PATCH] Fix update method with legacy title* properties --- plotly/basedatatypes.py | 14 ++++++++++- .../test_graph_objs/test_graph_objs.py | 24 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/plotly/basedatatypes.py b/plotly/basedatatypes.py index a0c3f057d61..2b9e91881d4 100644 --- a/plotly/basedatatypes.py +++ b/plotly/basedatatypes.py @@ -2619,7 +2619,19 @@ def _get_prop_validator(self, prop): ------- BaseValidator """ - return self._validators[prop] + + # Handle remapping + # ---------------- + if prop in self._mapped_properties: + prop_path = self._mapped_properties[prop] + plotly_obj = self[prop_path[:-1]] + prop = prop_path[-1] + else: + plotly_obj = self + + # Return validator + # ---------------- + return plotly_obj._validators[prop] @property def parent(self): diff --git a/plotly/tests/test_core/test_graph_objs/test_graph_objs.py b/plotly/tests/test_core/test_graph_objs/test_graph_objs.py index 49fcd347607..529cc3781c8 100644 --- a/plotly/tests/test_core/test_graph_objs/test_graph_objs.py +++ b/plotly/tests/test_core/test_graph_objs/test_graph_objs.py @@ -59,6 +59,14 @@ def test_title_as_string_layout(self): self.assertEqual(obj.to_plotly_json(), {'title': {'text': 'A title 2'}}) + # Update titlefont + obj.update(titlefont={'size': 23}) + self.assertEqual(obj.title.font.size, 23) + self.assertEqual(obj.to_plotly_json(), + {'title': + {'text': 'A title 2', + 'font': {'size': 23}}}) + # Pie obj = go.Pie() obj.title = 'A title' @@ -67,6 +75,22 @@ def test_title_as_string_layout(self): {'title': {'text': 'A title'}, 'type': 'pie'}) + # And update + obj.update(title='A title 2') + self.assertEqual(obj.title.text, 'A title 2') + self.assertEqual(obj.to_plotly_json(), + {'type': 'pie', + 'title': {'text': 'A title 2'}}) + + # Update titlefont + obj.update(titlefont={'size': 23}) + self.assertEqual(obj.title.font.size, 23) + self.assertEqual(obj.to_plotly_json(), + {'type': 'pie', + 'title': + {'text': 'A title 2', + 'font': {'size': 23}}}) + def test_legacy_title_props_remapped(self): # plain Layout