Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Selector fixes #304

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

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions fastplotlib/graphics/selectors/_base_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def __init__(
# otherwise annoying and requires too much accuracy to move just an edge
self._edge_hovered: bool = False

self._pygfx_event = None

def get_selected_index(self):
"""Not implemented for this selector"""
raise NotImplementedError
Expand Down
11 changes: 5 additions & 6 deletions fastplotlib/graphics/selectors/_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def __init__(

line_data = np.column_stack([xs, ys, zs])
elif axis == "y":
xs = np.zeros(end_points)
ys = np.array(2)
xs = np.array(end_points)
ys = np.zeros(2)
zs = np.zeros(2)

line_data = np.column_stack([xs, ys, zs])
Expand Down Expand Up @@ -150,7 +150,6 @@ def __init__(
self._setup_ipywidget_slider(ipywidget_slider)

self._move_info: dict = None
self._pygfx_event = None

self.parent = parent

Expand Down Expand Up @@ -278,17 +277,17 @@ def _get_selected_index(self, graphic):
or math.fabs(find_value - geo_positions[idx - 1])
< math.fabs(find_value - geo_positions[idx])
):
return int(idx - 1)
return round(idx - 1)
else:
return int(idx)
return round(idx)

if (
"Heatmap" in graphic.__class__.__name__
or "Image" in graphic.__class__.__name__
):
# indices map directly to grid geometry for image data buffer
index = self.selection() - offset
return int(index)
return round(index)

def _move_graphic(self, delta: np.ndarray):
"""
Expand Down
3 changes: 2 additions & 1 deletion fastplotlib/graphics/selectors/_sync.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from . import LinearSelector
from typing import *


class Synchronizer:
def __init__(self, *selectors: LinearSelector, key_bind: str = "Shift"):
def __init__(self, *selectors: LinearSelector, key_bind: Union[str, None] = "Shift"):
"""
Synchronize the movement of `Selectors`. Selectors will move in sync only when the selected `"key_bind"` is
used during the mouse movement event. Valid key binds are: ``"Control"``, ``"Shift"`` and ``"Alt"``.
Expand Down