diff --git a/glue_jupyter/bqplot/common/tools.py b/glue_jupyter/bqplot/common/tools.py index 6b20eb0c..97ad97e3 100644 --- a/glue_jupyter/bqplot/common/tools.py +++ b/glue_jupyter/bqplot/common/tools.py @@ -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) diff --git a/glue_jupyter/bqplot/image/viewer.py b/glue_jupyter/bqplot/image/viewer.py index 4b79a7ef..07d13551 100644 --- a/glue_jupyter/bqplot/image/viewer.py +++ b/glue_jupyter/bqplot/image/viewer.py @@ -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): diff --git a/glue_jupyter/bqplot/tests/test_bqplot.py b/glue_jupyter/bqplot/tests/test_bqplot.py index 008e6438..d3ffff67 100644 --- a/glue_jupyter/bqplot/tests/test_bqplot.py +++ b/glue_jupyter/bqplot/tests/test_bqplot.py @@ -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') @@ -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)