Skip to content

Commit

Permalink
Add histogram pan/zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
gselzer committed Jan 4, 2025
1 parent 721d882 commit 9067b6c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/ndv/views/_pygfx/_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ def __init__(self, *, vertical: bool = False) -> None:
color_mode="vertex",
),
)
# TODO: Refactor method
# self._update_lut_lines()
self._scene.add(self._clim_handles)

self._x = pygfx.Ruler(
Expand All @@ -149,6 +147,16 @@ def __init__(self, *, vertical: bool = False) -> None:
)
self._scene.add(self._x, self._y)

# TODO: Re-implement pan/zoom?
controller = pygfx.PanZoomController(register_events=self._viewport)
controller.add_camera(
self._camera,
include_state={"x", "width"},
)
self._controller = controller
# increase zoom wheel gain
self._controller.controls.update({"wheel": ("zoom_to_point", "push", -0.005)})

self.refresh()

def refresh(self) -> None:
Expand Down Expand Up @@ -399,10 +407,14 @@ def on_mouse_press(self, event: MousePressEvent) -> bool:
pos = event.x, event.y
# check whether the user grabbed a node
self._grabbed = self._find_nearby_node(pos)
if self._grabbed != Grabbable.NONE:
# disconnect pan/zoom events until handle is dropped
self._controller.enabled = False
return False

def on_mouse_release(self, event: MouseReleaseEvent) -> bool:
self._grabbed = Grabbable.NONE
self._controller.enabled = True
return False

def on_mouse_move(self, event: MouseMoveEvent) -> bool:
Expand Down

0 comments on commit 9067b6c

Please sign in to comment.