Skip to content

Commit

Permalink
Merge pull request #503 from GavinHuttley/develop
Browse files Browse the repository at this point in the history
ENH: Drawable now honours layout titles
  • Loading branch information
GavinHuttley committed Jan 25, 2020
2 parents ba918d4 + 600402a commit 312fff6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/cogent3/draw/drawable.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,16 @@ def figure(self):

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)
if self.xtitle:
xtitle = self.xtitle
else:
xtitle = self.layout.xaxis.get("title", None)

if self.ytitle:
ytitle = self.ytitle
else:
ytitle = self.layout.yaxis.get("title", None)

self.layout.xaxis.title = xtitle
self.layout.yaxis.title = ytitle
return UnionDict(data=traces, layout=self.layout)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_draw/test_draw_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ def test_one_trace(self):
f = d.figure
self.assertEqual(f.data, [trace])

def test_layout_with_titles(self):
"""if provided layout has axis titles, keep them"""
layout = dict(xaxis=dict(title="X"), yaxis=dict(title="Y"))
d = Drawable(layout=layout)
fig = d.figure
self.assertEqual(fig.layout.xaxis.title, "X")
self.assertEqual(fig.layout.yaxis.title, "Y")
d = Drawable()
fig = d.figure
self.assertEqual(fig.layout.xaxis.title, None)
self.assertEqual(fig.layout.yaxis.title, None)


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

0 comments on commit 312fff6

Please sign in to comment.