Skip to content

Commit da2cfc2

Browse files
hyanwongmergify-bot
authored andcommitted
Address review comments
1 parent df4a627 commit da2cfc2

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

python/tests/test_drawing.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,12 +1493,13 @@ def test_nonimplemented_base_class(self):
14931493
with pytest.raises(NotImplementedError):
14941494
plot.draw_y_axis(tick_positions=[0])
14951495

1496-
def test_nonimplemented_tick_spacing(self):
1496+
def test_bad_tick_spacing(self):
1497+
# Integer y_ticks to give auto-generated tick locs is not currently implemented
14971498
t = self.get_binary_tree()
1498-
with pytest.raises(NotImplementedError):
1499+
with pytest.raises(TypeError):
14991500
t.draw_svg(y_axis=True, y_ticks=6)
15001501
ts = self.get_simple_ts()
1501-
with pytest.raises(NotImplementedError):
1502+
with pytest.raises(TypeError):
15021503
ts.draw_svg(y_axis=True, y_ticks=6)
15031504

15041505
def test_no_mixed_yscales(self):
@@ -1513,12 +1514,26 @@ def test_draw_defaults(self):
15131514
svg = t.draw_svg()
15141515
self.verify_basic_svg(svg)
15151516

1516-
def test_draw_nonbinary(self):
1517-
t = self.get_nonbinary_tree()
1518-
svg = t.draw()
1519-
self.verify_basic_svg(svg)
1517+
@pytest.mark.parametrize("y_axis", (True, False))
1518+
@pytest.mark.parametrize("y_label", (True, False))
1519+
@pytest.mark.parametrize(
1520+
"tree_height_scale",
1521+
(
1522+
"rank",
1523+
"time",
1524+
),
1525+
)
1526+
@pytest.mark.parametrize("y_ticks", ([], [0, 1], None))
1527+
@pytest.mark.parametrize("y_gridlines", (True, False))
1528+
def test_draw_svg_y_axis_parameter_combos(
1529+
self, y_axis, y_label, tree_height_scale, y_ticks, y_gridlines
1530+
):
1531+
t = self.get_binary_tree()
15201532
svg = t.draw_svg()
15211533
self.verify_basic_svg(svg)
1534+
ts = self.get_simple_ts()
1535+
svg = ts.draw_svg()
1536+
self.verify_basic_svg(svg, width=200 * ts.num_trees)
15221537

15231538
def test_draw_multiroot(self):
15241539
t = self.get_multiroot_tree()

python/tskit/drawing.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,13 @@ def check_x_scale(x_scale):
124124

125125
def check_ticks(ticks, default_iterable):
126126
"""
127-
If y_ticks is iterable, it is a list of tick positions. Otherwise return a default
128-
or None if falsey
127+
This is trivial, but implemented as a function so that later we can implement a tick
128+
locator function, such that e.g. ticks=5 selects ~5 nicely spaced tick locations
129+
(ideally with sensible behaviour for log scales)
129130
"""
130131
if ticks is None:
131132
return default_iterable
132-
try:
133-
iter(ticks)
134-
return ticks
135-
except TypeError:
136-
raise NotImplementedError("Autocalculated tick mark locations not implemented.")
133+
return ticks
137134

138135

139136
def rnd(x):
@@ -341,9 +338,7 @@ class SvgPlot:
341338
# TODO: we may want to make some of the constants below into parameters
342339
text_height = 14 # May want to calculate this based on a font size
343340
line_height = text_height * 1.2 # allowing padding above and below a line
344-
root_branch_fraction = (
345-
1 / 8
346-
) # Rel. root branch len (unless it has a timed mutation)
341+
root_branch_fraction = 1 / 8 # Rel root branch len, unless it has a timed mutation
347342
default_tick_length = 5
348343
default_tick_length_site = 10
349344
# Placement of the axes lines within the padding - not used unless axis is plotted

python/tskit/trees.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,8 +1631,7 @@ def draw_svg(
16311631
gives no tickmarks). If ``None``, plot one tickmark for each unique
16321632
node value.
16331633
:param bool y_gridlines: Whether to plot horizontal lines behind the tree
1634-
at each y tickmark. If ``None`` (default), only plot gridlines if a list
1635-
of ``y_ticks`` has also been given.
1634+
at each y tickmark.
16361635
16371636
:return: An SVG representation of a tree.
16381637
:rtype: str
@@ -5395,8 +5394,7 @@ def draw_svg(
53955394
gives no tickmarks). If ``None``, plot one tickmark for each unique
53965395
node value.
53975396
:param bool y_gridlines: Whether to plot horizontal lines behind the tree
5398-
at each y tickmark. If ``None`` (default), only plot gridlines if a list
5399-
of ``y_ticks`` has also been given.
5397+
at each y tickmark.
54005398
54015399
:return: An SVG representation of a tree sequence.
54025400
:rtype: str

0 commit comments

Comments
 (0)