Skip to content

Commit

Permalink
Merge pull request #1319 from pllim/click-to-center
Browse files Browse the repository at this point in the history
Imviz click to center in pan/zoom
  • Loading branch information
pllim authored May 17, 2022
2 parents bfa615e + d14f598 commit ac48b5f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Imviz
- New curve of growth plot available in Simple Aperture
Photometry plugin. [#1287]

- Clicking on image in pan/zoom mode now centers the image to location
under cursor. [#1319]

Mosviz
^^^^^^

Expand Down
3 changes: 3 additions & 0 deletions docs/imviz/displayimages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ but you can re-link them via WCS using `~jdaviz.configs.imviz.helper.Imviz.link_

Regular Pan/Zoom is also available and is used in a similar way as other Jdaviz tools.

When in either of these modes, clicking on the image will recenter the image to the
location under cursor.

.. seealso::

:ref:`Pan/Zoom <cubeviz-pan-zoom>`
Expand Down
37 changes: 34 additions & 3 deletions jdaviz/configs/imviz/plugins/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,38 @@ def on_limits_change(self, *args):
viewer.state.y_max = self.viewer.state.y_max


@viewer_tool
class JdavizPanZoomMode(BqplotPanZoomMode):
tool_id = 'jdaviz:panzoom'
tool_tip = 'Interactively pan (click-drag), zoom (scroll), and center (click)'

def activate(self):
super().activate()
self.viewer.add_event_callback(self.on_click, events=['click'])

def deactivate(self):
self.viewer.remove_event_callback(self.on_click)
super().deactivate()

def on_click(self, data):
# Find visible layers
visible_layers = [layer for layer in self.viewer.state.layers if layer.visible]
if len(visible_layers) == 0:
return

# Same data as mousemove event in Imviz viewer.
# Any other config that wants this functionality has to have the following:
# viewer._get_real_xy()
# viewer.center_on() --> inherited from AstrowidgetsImageViewerMixin
image = visible_layers[0].layer
x = data['domain']['x']
y = data['domain']['y']
if x is None or y is None: # Out of bounds
return
x, y, _ = self.viewer._get_real_xy(image, x, y)
self.viewer.center_on((x, y))


@viewer_tool
class BlinkOnce(CheckableTool):
icon = os.path.join(ICON_DIR, 'blink.svg')
Expand All @@ -68,8 +100,7 @@ class BlinkOnce(CheckableTool):
'or you can also press the "b" key anytime')

def activate(self):
self.viewer.add_event_callback(self.on_click,
events=['click'])
self.viewer.add_event_callback(self.on_click, events=['click'])

def deactivate(self):
self.viewer.remove_event_callback(self.on_click)
Expand All @@ -87,7 +118,7 @@ class MatchBoxZoom(_MatchedZoomMixin, BoxZoom):


@viewer_tool
class MatchPanZoom(_MatchedZoomMixin, BqplotPanZoomMode):
class MatchPanZoom(_MatchedZoomMixin, JdavizPanZoomMode):
icon = os.path.join(ICON_DIR, 'panzoom_match.svg')
tool_id = 'jdaviz:panzoommatch'
action_text = 'Pan, matching between viewers'
Expand Down
4 changes: 2 additions & 2 deletions jdaviz/configs/imviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class ImvizImageView(BqplotImageView, AstrowidgetsImageViewerMixin, JdavizViewer
inherit_tools = False

tools = ['bqplot:home', 'jdaviz:boxzoom', 'jdaviz:boxzoommatch',
'bqplot:panzoom', 'jdaviz:panzoommatch',
'jdaviz:panzoom', 'jdaviz:panzoommatch',
'jdaviz:contrastbias', 'jdaviz:blinkonce',
'bqplot:rectangle', 'bqplot:circle', 'bqplot:ellipse']

# categories: zoom resets, zoom, pan, subset, select tools, shortcuts
tools_nested = [
['bqplot:home'],
['jdaviz:boxzoom', 'jdaviz:boxzoommatch'],
['bqplot:panzoom', 'jdaviz:panzoommatch'],
['jdaviz:panzoom', 'jdaviz:panzoommatch'],
['bqplot:circle', 'bqplot:rectangle', 'bqplot:ellipse'],
['jdaviz:blinkonce', 'jdaviz:contrastbias'],
['jdaviz:sidebar_plot', 'jdaviz:sidebar_export', 'jdaviz:sidebar_compass']
Expand Down

0 comments on commit ac48b5f

Please sign in to comment.