Skip to content

Commit

Permalink
Add textual mouseover descriptions of collapsed nodes
Browse files Browse the repository at this point in the history
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"
  • Loading branch information
hyanwong authored and benjeffery committed Jan 8, 2025
1 parent af21766 commit 4a3b35b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 26 deletions.
20 changes: 16 additions & 4 deletions python/tests/data/svg/tree_poly_tracked.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 20 additions & 5 deletions python/tests/data/svg/tree_poly_tracked_collapse.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 8 additions & 2 deletions python/tests/data/svg/tree_simple_collapsed.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion python/tests/data/svg/tree_subtrees_with_collapsed.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 23 additions & 14 deletions python/tskit/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1990,15 +1990,20 @@ def draw_tree(self):
end=(x2, 0),
)
)
poly.add(
dwg.text(
f"+{info.num_samples}/{bold_integer(info.num_branches)}",
font_style="italic",
x=[rnd(x2)],
dy=[rnd(-self.text_height / 10)], # make the plus sign line up
text_anchor="end",
label = dwg.text(
f"+{info.num_samples}/{bold_integer(info.num_branches)}",
font_style="italic",
x=[rnd(x2)],
dy=[rnd(-self.text_height / 10)], # make the plus sign line up
text_anchor="end",
)
label.set_desc(
title=(
f"This polytomy has {info.num_branches} additional branches, "
f"leading to a total of {info.num_samples} descendant samples"
)
)
poly.add(label)
curr_svg_group.add(poly)

# Add edge above node first => on layer underneath anything else
Expand Down Expand Up @@ -2092,14 +2097,18 @@ def draw_tree(self):
node_lab_attr["transform"] = self.text_transform("above")
else:
if multi_samples is not None:
curr_svg_group.add(
dwg.text(
text=f"+{multi_samples}",
transform=self.text_transform("below", dy=1),
font_style="italic",
class_="lab summary",
)
label = dwg.text(
text=f"+{multi_samples}",
transform=self.text_transform("below", dy=1),
font_style="italic",
class_="lab summary",
)
title = (
f"A collapsed {'sample' if tree.is_sample(u) else 'non-sample'} "
f"node with {multi_samples} descendant samples in this tree"
)
label.set_desc(title=title)
curr_svg_group.add(label)
if u == left_child[tree.parent(u)]:
add_class(node_lab_attr, "lft")
node_lab_attr["transform"] = self.text_transform("above_left")
Expand Down

0 comments on commit 4a3b35b

Please sign in to comment.