Skip to content

Commit

Permalink
BUG: Prevent some spatial ROI from
Browse files Browse the repository at this point in the history
getting too small
  • Loading branch information
pllim committed Dec 19, 2023
1 parent b515772 commit 19e419a
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions glue_jupyter/bqplot/common/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,21 @@ def update_selection(self, *args):
x = self.interact.selected_x
y = self.interact.selected_y
theta = None if self._roi is None else self._roi.theta
roi = RectangularROI(xmin=min(x), xmax=max(x), ymin=min(y), ymax=max(y), theta=theta) # noqa: E501
x_min = min(x)
x_max = max(x)
y_min = min(y)
y_max = max(y)
# Avoid drawing invisible shape.
if isinstance(self._roi, RectangularROI):
dx = abs(x_max - x_min)
dy = abs(y_max - y_min)
if dx < 1:
x_min = self._roi.xmin
x_max = self._roi.xmax
if dy < 1:
y_min = self._roi.ymin
y_max = self._roi.ymax

Check warning on line 169 in glue_jupyter/bqplot/common/tools.py

View check run for this annotation

Codecov / codecov/patch

glue_jupyter/bqplot/common/tools.py#L162-L169

Added lines #L162 - L169 were not covered by tests
roi = RectangularROI(xmin=x_min, xmax=x_max, ymin=y_min, ymax=y_max, theta=theta)
self._roi = roi
self.viewer.apply_roi(roi)
if self.finalize_callback is not None:
Expand Down Expand Up @@ -398,6 +412,17 @@ def update_selection(self, *args):
yc = y.mean()
rx = abs(x[1] - x[0])/2
ry = abs(y[1] - y[0])/2
# Avoid drawing invisible shape.
if isinstance(self._roi, CircularROI):
if rx < 1:
rx = self._roi.radius
if ry < 1:
ry = self._roi.radius

Check warning on line 420 in glue_jupyter/bqplot/common/tools.py

View check run for this annotation

Codecov / codecov/patch

glue_jupyter/bqplot/common/tools.py#L417-L420

Added lines #L417 - L420 were not covered by tests
elif isinstance(self._roi, EllipticalROI):
if rx < 1:
rx = self._roi.radius_x
if ry < 1:
ry = self._roi.radius_y

Check warning on line 425 in glue_jupyter/bqplot/common/tools.py

View check run for this annotation

Codecov / codecov/patch

glue_jupyter/bqplot/common/tools.py#L422-L425

Added lines #L422 - L425 were not covered by tests
# We use a tolerance of 1e-2 below to match the tolerance set in glue-core
# https://github.com/glue-viz/glue/blob/6b968b352bc5ad68b95ad5e3bb25550782a69ee8/glue/viewers/matplotlib/state.py#L198
if self._strict_circle:
Expand Down Expand Up @@ -519,7 +544,11 @@ def update_selection(self, *args):
rx = abs(x[1] - x[0]) * 0.5
ry = abs(y[1] - y[0]) * 0.5
outer_r = float(rx + ry) * 0.5
if self._roi is None:
# Avoid drawing invisible shape.
if isinstance(self._roi, CircularAnnulusROI) and outer_r < 2:
outer_r = self._roi.outer_radius
inner_r = self._roi.inner_radius

Check warning on line 550 in glue_jupyter/bqplot/common/tools.py

View check run for this annotation

Codecov / codecov/patch

glue_jupyter/bqplot/common/tools.py#L549-L550

Added lines #L549 - L550 were not covered by tests
elif self._roi is None:
inner_r = outer_r * 0.5 # Hardcoded for now, user can edit later.
else:
# Resizing only changes outer r, avoid having inner_r >= outer_r afterwards.
Expand Down

0 comments on commit 19e419a

Please sign in to comment.