Skip to content

Commit 3edb2e6

Browse files
hyanwongbenjeffery
authored andcommitted
Make max_time work with mutations over roots
1 parent 44a23e2 commit 3edb2e6

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

python/tests/test_drawing.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,20 +1869,31 @@ def test_min_ts_time(self):
18691869
assert svg2 == svg3
18701870

18711871
def test_numeric_max_time_with_mutations_over_roots(self):
1872-
t = self.get_mutations_over_roots_tree()
1873-
max_time_value = 10.0 # Use a numeric max_time value
1872+
max_time_value = 0.1 # Use a numeric max_time value
1873+
params = {"y_ticks": [1.23], "y_axis": True}
1874+
test_draw = {
1875+
"svg_nomin": {},
1876+
"svg_min": {"max_time": max_time_value},
1877+
"svg_log_min": {"max_time": max_time_value, "time_scale": "log_time"},
1878+
}
18741879

1875-
with pytest.warns(
1876-
UserWarning, match="Mutations .* are above nodes which are not present"
1877-
):
1878-
svg = t.draw_svg(max_time=max_time_value)
1879-
self.verify_basic_svg(svg)
1880+
t = self.get_mutations_over_roots_tree()
1881+
assert t.tree_sequence.max_time > max_time_value
18801882

1881-
with pytest.warns(
1882-
UserWarning, match="Mutations .* are above nodes which are not present"
1883-
):
1884-
svg_log = t.draw_svg(max_time=max_time_value, time_scale="log_time")
1885-
self.verify_basic_svg(svg_log)
1883+
for name, extra in test_draw.items():
1884+
with pytest.warns(
1885+
UserWarning, match="Mutations .* are above nodes which are not present"
1886+
):
1887+
svg = t.draw_svg(**{**params, **extra})
1888+
assert svg.count('class="tick"') == 1
1889+
m = re.search(r'<g class="tick" transform="translate\((.*?)\)">', svg)
1890+
assert m is not None
1891+
translate_coords = [float(x) for x in m.group(1).split()]
1892+
if name == "svg_nomin":
1893+
# single tick within the plot region
1894+
assert translate_coords[1] > 0
1895+
else:
1896+
assert translate_coords[1] < 0
18861897

18871898
#
18881899
# TODO: update the tests below here to check the new SVG based interface.

python/tskit/drawing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2004,7 +2004,7 @@ def assign_y_coordinates(
20042004
max_mut_height = np.nanmax(np.append(mut_time, 0))
20052005
max_time = max(max_node_height, max_mut_height) # Reuse variable
20062006
else:
2007-
max_node_height = max(self.node_height.values())
2007+
max_node_height = max_time
20082008
if min_time == "tree":
20092009
min_time = min(self.node_height.values())
20102010
# don't need to check mutation times, as they must be above a node

0 commit comments

Comments
 (0)