Skip to content

Commit

Permalink
Merge pull request #115 from funkelab/adjustable_point_sizes
Browse files Browse the repository at this point in the history
Make the point size controllable
  • Loading branch information
cmalinmayor authored Dec 9, 2024
2 parents 54fdbe1 + f5b1fc6 commit cadefe9
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/motile_plugin/data_views/views/layers/track_points.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import math
from typing import TYPE_CHECKING

import napari
Expand Down Expand Up @@ -40,12 +41,14 @@ def __init__(
self.tracks_viewer.tracks, self.tracks_viewer.symbolmap
)

self.default_size = 5

super().__init__(
data=points,
name=name,
symbol=symbols,
face_color=colors,
size=5,
size=self.default_size,
properties={
"node_id": self.nodes,
"track_id": track_ids,
Expand Down Expand Up @@ -86,10 +89,21 @@ def click(layer, event):
# listen to updates of the data
self.events.data.connect(self._update_data)

# connect to changing the point size in the UI
self.events.current_size.connect(
lambda: self.set_point_size(size=self.current_size)
)

# listen to updates in the selected data (from the point selection tool)
# to update the nodes in self.tracks_viewer.selected_nodes
self.selected_data.events.items_changed.connect(self._update_selection)

def set_point_size(self, size: int) -> None:
"""Sets a new default point size"""

self.default_size = size
self._refresh()

def _refresh(self):
"""Refresh the data in the points layer"""

Expand All @@ -112,7 +126,7 @@ def _refresh(self):
self.tracks_viewer.colormap.map(track_id) for track_id in track_ids
]
self.properties = {"node_id": self.nodes, "track_id": track_ids}
self.size = 5
self.size = self.default_size
self.border_color = [1, 1, 1, 1]

self.events.data.connect(
Expand Down Expand Up @@ -205,7 +219,7 @@ def update_point_outline(self, visible: list[int] | str) -> None:

# set border color for selected item
self.border_color = [1, 1, 1, 1]
self.size = 5
self.size = self.default_size
for node in self.tracks_viewer.selected_nodes:
index = self.node_index_dict[node]
self.border_color[index] = (
Expand All @@ -214,5 +228,5 @@ def update_point_outline(self, visible: list[int] | str) -> None:
1,
1,
)
self.size[index] = 7
self.size[index] = math.ceil(self.default_size + 0.3 * self.default_size)
self.refresh()

0 comments on commit cadefe9

Please sign in to comment.