Skip to content

Commit ffecae9

Browse files
hyanwongmergify[bot]
authored andcommitted
Add textual mouseover descriptions of collapsed nodes
I realised that the numbers can be somewhat cryptic, and it's trivial to add helpful text that appears on mouseover, e.g. "This polytomy has 3 additional branches, leading to a total of 14 descendant samples"
1 parent af21766 commit ffecae9

5 files changed

Lines changed: 71 additions & 26 deletions

File tree

python/tests/data/svg/tree_poly_tracked.svg

Lines changed: 16 additions & 4 deletions
Loading

python/tests/data/svg/tree_poly_tracked_collapse.svg

Lines changed: 20 additions & 5 deletions
Loading

python/tests/data/svg/tree_simple_collapsed.svg

Lines changed: 8 additions & 2 deletions
Loading

python/tests/data/svg/tree_subtrees_with_collapsed.svg

Lines changed: 4 additions & 1 deletion
Loading

python/tskit/drawing.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,15 +1990,20 @@ def draw_tree(self):
19901990
end=(x2, 0),
19911991
)
19921992
)
1993-
poly.add(
1994-
dwg.text(
1995-
f"+{info.num_samples}/{bold_integer(info.num_branches)}",
1996-
font_style="italic",
1997-
x=[rnd(x2)],
1998-
dy=[rnd(-self.text_height / 10)], # make the plus sign line up
1999-
text_anchor="end",
1993+
label = dwg.text(
1994+
f"+{info.num_samples}/{bold_integer(info.num_branches)}",
1995+
font_style="italic",
1996+
x=[rnd(x2)],
1997+
dy=[rnd(-self.text_height / 10)], # make the plus sign line up
1998+
text_anchor="end",
1999+
)
2000+
label.set_desc(
2001+
title=(
2002+
f"This polytomy has {info.num_branches} additional branches, "
2003+
f"leading to a total of {info.num_samples} descendant samples"
20002004
)
20012005
)
2006+
poly.add(label)
20022007
curr_svg_group.add(poly)
20032008

20042009
# Add edge above node first => on layer underneath anything else
@@ -2092,14 +2097,18 @@ def draw_tree(self):
20922097
node_lab_attr["transform"] = self.text_transform("above")
20932098
else:
20942099
if multi_samples is not None:
2095-
curr_svg_group.add(
2096-
dwg.text(
2097-
text=f"+{multi_samples}",
2098-
transform=self.text_transform("below", dy=1),
2099-
font_style="italic",
2100-
class_="lab summary",
2101-
)
2100+
label = dwg.text(
2101+
text=f"+{multi_samples}",
2102+
transform=self.text_transform("below", dy=1),
2103+
font_style="italic",
2104+
class_="lab summary",
2105+
)
2106+
title = (
2107+
f"A collapsed {'sample' if tree.is_sample(u) else 'non-sample'} "
2108+
f"node with {multi_samples} descendant samples in this tree"
21022109
)
2110+
label.set_desc(title=title)
2111+
curr_svg_group.add(label)
21032112
if u == left_child[tree.parent(u)]:
21042113
add_class(node_lab_attr, "lft")
21052114
node_lab_attr["transform"] = self.text_transform("above_left")

0 commit comments

Comments
 (0)