Skip to content

Commit

Permalink
Clarify fit, use reference_data [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
pllim committed Jul 23, 2021
1 parent 8f44f3e commit ced8ee0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions jdaviz/configs/imviz/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,13 @@ def zoom_level(self):
* 1 means real-pixel-size.
* 2 means zoomed in by a factor of 2.
* 0.5 means zoomed out by a factor of 2.
* 'fit' resets the zoom.
* 'fit' means zoomed to fit the whole image width into display.
"""
viewer = self.app.get_viewer("viewer-1")
i_top = get_top_layer_index(viewer)
image = viewer.layers[i_top].layer
image = viewer.state.reference_data

# TODO: Need to fix formula to use "real pixel size"
nx = image.shape[viewer.state.x_att.axis]
ny = image.shape[viewer.state.y_att.axis]
zoom_x = nx / (viewer.state.x_max - viewer.state.x_min)
Expand All @@ -237,21 +238,19 @@ def zoom_level(self, val):
raise ValueError(f'Unsupported zoom level: {val}')

viewer = self.app.get_viewer("viewer-1")
if (viewer.state.reference_data is None or viewer.state.x_att is None
or viewer.state.y_att is None):
image = viewer.state.reference_data
if image is None or viewer.state.x_att is None or viewer.state.y_att is None:
return

# Want to zoom what is actually visible.
# Zoom on X and Y will auto-adjust.
i_top = get_top_layer_index(viewer)
image = viewer.layers[i_top].layer
nx = image.shape[viewer.state.x_att.axis]

if val == 'fit':
# Similar to ImageViewerState.reset_limits() in Glue.
new_x_min = 0
new_x_max = nx
else:
# TODO: Need to fix formula to use "real pixel size"
cur_xcen = (viewer.state.x_min + viewer.state.x_max) * 0.5
new_dx = nx * 0.5 / val
new_x_min = cur_xcen - new_dx
Expand Down
2 changes: 1 addition & 1 deletion notebooks/ImvizExample.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@
"* 1 means real-pixel-size.\n",
"* 2 means zoomed in by a factor of 2.\n",
"* 0.5 means zoomed out by a factor of 2.\n",
"* 'fit' resets the zoom."
"* 'fit' means zoomed to fit the whole image width into display."
]
},
{
Expand Down

0 comments on commit ced8ee0

Please sign in to comment.