Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the point size controllable #115

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading