Skip to content

Commit

Permalink
Merge pull request #501 from GavinHuttley/develop
Browse files Browse the repository at this point in the history
ENH: better support for appended traces to Drawable
  • Loading branch information
GavinHuttley committed Jan 20, 2020
2 parents fee26cd + 881b47b commit b8e69e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/cogent3/draw/drawable.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ def bound_to(self, obj):
def figure(self):
if not self.traces and hasattr(self, "_build_fig"):
self._build_fig()
traces = self.traces
else:
traces = [{}]

traces = self.traces if self.traces else [{}]

xtitle = self.xtitle if not self.xtitle else dict(text=self.xtitle)
ytitle = self.ytitle if not self.ytitle else dict(text=self.ytitle)
self.layout.xaxis.title = xtitle
Expand Down
18 changes: 18 additions & 0 deletions tests/test_draw/test_draw_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ def _check_drawable_styles(self, method, styles, **kwargs):
self._check_drawable_attrs(obj.drawable.figure, style)


class CustomDrawable(BaseDrawablesTests):
"""custom applications of Drawable"""

def test_no_trace(self):
"""should still produce a valid figure"""
d = Drawable()
f = d.figure
self.assertEqual(f.data, [{}])

def test_one_trace(self):
"""should still produce a valid figure"""
d = Drawable()
trace = dict(type="scatter", x=[0, 1], y=[0, 1])
d.add_trace(trace)
f = d.figure
self.assertEqual(f.data, [trace])


class AlignmentDrawablesTests(BaseDrawablesTests):
"""methods on SequenceCollection produce Drawables"""

Expand Down

0 comments on commit b8e69e2

Please sign in to comment.