Skip to content

Commit

Permalink
Prevent resizing of CircularAnnulusROI below inner_radius
Browse files Browse the repository at this point in the history
  • Loading branch information
dhomeier committed Aug 12, 2023
1 parent 0be614f commit 0ae033c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
3 changes: 2 additions & 1 deletion glue_jupyter/bqplot/common/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ def update_selection(self, *args):
if self._roi is None:
inner_r = outer_r * 0.5 # Hardcoded for now, user can edit later.
else:
inner_r = self._roi.inner_radius
# Resizing only changes outer r, avoid having inner_r >= outer_r afterwards.
inner_r = min(self._roi.inner_radius, outer_r * 0.999999)

roi = CircularAnnulusROI(xc=xc, yc=yc, inner_radius=inner_r, outer_radius=outer_r)

Expand Down
2 changes: 1 addition & 1 deletion glue_jupyter/bqplot/image/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BqplotImageView(BqplotBaseView):
_options_cls = ImageViewerStateWidget

tools = ['bqplot:home', 'bqplot:panzoom', 'bqplot:rectangle', 'bqplot:circle', 'bqplot:polygon',
'bqplot:ellipse', 'bqplot:truecircle']
'bqplot:ellipse', 'bqplot:truecircle', 'bqplot:circannulus']

def __init__(self, session):

Expand Down
29 changes: 28 additions & 1 deletion glue_jupyter/bqplot/tests/test_bqplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from numpy.testing import assert_allclose
from nbconvert.preprocessors import ExecutePreprocessor
from glue.core import Data
from glue.core.roi import EllipticalROI
from glue.core.roi import CircularAnnulusROI, EllipticalROI
from ..common.tools import TrueCircularROI

DATA = os.path.join(os.path.dirname(__file__), 'data')
Expand Down Expand Up @@ -305,6 +305,33 @@ def test_imshow_elliptical_brush(app, data_image):
assert_allclose(roi.yc, 276.75)


def test_imshow_circular_annulus_brush(app, data_image):

v = app.imshow(data=data_image)
v.state.aspect = 'auto'

tool = v.toolbar.tools['bqplot:circannulus']
tool.activate()
tool.interact.brushing = True
tool.interact.selected = [(1.5, 3.5), (300.5, 550)]
tool.interact.brushing = False

roi = data_image.subsets[0].subset_state.roi
assert isinstance(roi, CircularAnnulusROI)
assert_allclose(roi.xc, 151.00)
assert_allclose(roi.yc, 276.75)
assert_allclose(roi.outer_radius, 211.375)
assert_allclose(roi.inner_radius, 105.6875)

tool.interact.brushing = True
tool.interact.selected = [(150.0, 275.0), (150.0, 325.0)]
tool.interact.brushing = False
assert_allclose(roi.xc, 151.00)
# assert_allclose(roi.yc, 326.75) # trying to use `move`, but this is not how it works...
assert_allclose(roi.outer_radius, 211.375)
assert_allclose(roi.inner_radius, 105.6875)


def test_imshow_equal_aspect(app, data_image):
data = Data(array=np.random.random((100, 5)))
app.data_collection.append(data)
Expand Down

0 comments on commit 0ae033c

Please sign in to comment.