Skip to content

Commit

Permalink
Merge pull request #77 from lowe-lab-ucl/fix-text-pos
Browse files Browse the repository at this point in the history
Update annotation positioning and mouse events
  • Loading branch information
paddyroddy authored Jun 29, 2022
2 parents bb23b25 + 5619d68 commit 8bc5ed6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion napari_arboretum/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def append_mouse_callback(self, track_layer: Tracks) -> None:
when the layer is clicked.
"""

@track_layer.mouse_drag_callbacks.append
@track_layer.mouse_double_click_callbacks.append
def show_tree(tracks: Tracks, event: Event) -> None:
self.tracks = tracks

Expand Down
12 changes: 9 additions & 3 deletions napari_arboretum/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ def layout_tree(nodes: List[TreeNode]) -> Tuple[List[Edge], List[Annotation]]:
# draw the root of the tree
edges.append(Edge(y=(y, y), x=(node.t[0], node.t[-1]), id=node.ID))

if node.is_root:
annotations.append(Annotation(y=y, x=node.t[0], label=str(node.ID)))

# mark if this is an apoptotic tree
if node.is_leaf:
annotations.append(Annotation(y=y, x=node.t[-1], label=str(node.ID)))

if node.is_root:
annotations.append(Annotation(y=y, x=node.t[0], label=str(node.ID)))
continue

children = [t for t in nodes if t.ID in node.children]

Expand All @@ -94,6 +95,11 @@ def layout_tree(nodes: List[TreeNode]) -> Tuple[List[Edge], List[Annotation]]:

# plot a linking line to the children
edges.append(Edge(y=(y, y_pos[-1]), x=(node.t[-1], child.t[0])))

# if it's a leaf don't plot the annotation
if child.is_leaf:
continue

annotations.append(
Annotation(
y=y_pos[-1],
Expand Down
3 changes: 2 additions & 1 deletion napari_arboretum/visualisation/vispy_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ def add_annotation(self, x: float, y: float, label: str, color):
pos=[y, x, 0],
anchor_x="left",
anchor_y="top",
font_size=10,
font_size=6,
rotation=90,
)
self.add_subvisual(visual)
self.subvisuals.append(visual)
Expand Down

0 comments on commit 8bc5ed6

Please sign in to comment.