Skip to content

Fix update method with legacy title* properties #1410

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 1 commit into from
Jan 26, 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
14 changes: 13 additions & 1 deletion plotly/basedatatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
24 changes: 24 additions & 0 deletions plotly/tests/test_core/test_graph_objs/test_graph_objs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down