Skip to content

Commit

Permalink
support rectangles and ellipses
Browse files Browse the repository at this point in the history
* and rename radius_factor > scale_factor
  • Loading branch information
kecnry committed Jan 18, 2024
1 parent 94ad1f2 commit b8f06d7
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,7 @@ def __init__(self, *args, **kwargs):
class ApertureSubsetSelect(SubsetSelect):
"""
"""
def __init__(self, plugin, items, selected, radius_factor, multiselect=None,
def __init__(self, plugin, items, selected, scale_factor, multiselect=None,
dataset=None, viewers=None):
"""
Parameters
Expand All @@ -1921,7 +1921,7 @@ def __init__(self, plugin, items, selected, radius_factor, multiselect=None,
the name of the items traitlet defined in ``plugin``
selected : str
the name of the selected traitlet defined in ``plugin``
radius_factor : str
scale_factor : str
the name of the traitlet defining the radius factor for the drawn aperture
multiselect : str
the name of the traitlet defining whether the dropdown should accept multiple selections
Expand All @@ -1942,11 +1942,11 @@ def __init__(self, plugin, items, selected, radius_factor, multiselect=None,
viewers=viewers,
default_text=None)

self.add_traitlets(radius_factor=radius_factor)
self.add_traitlets(scale_factor=scale_factor)

self.add_observe('is_active', self._plugin_active_changed)
self.add_observe(selected, self._update_mark_coords)
self.add_observe(radius_factor, self._update_mark_coords)
self.add_observe(scale_factor, self._update_mark_coords)
# add marks to any new viewers
self.hub.subscribe(self, ViewerAddedMessage, handler=self._update_mark_coords)
# update coordinates when link type or reference data is _mode_changed
Expand Down Expand Up @@ -2001,7 +2001,22 @@ def _get_mark_coords(self, viewer):
roi = subset_dict[0]['subset_state'].roi.copy()
# NOTE: this assumes that we'll apply the same radius factor to all subsets (all will
# be defined at the same slice for cones in cubes)
roi.radius *= self.radius_factor
if hasattr(roi, 'radius'):
roi.radius *= self.scale_factor
elif hasattr(roi, 'radius_x'):
roi.radius_x *= self.scale_factor
roi.radius_y *= self.scale_factor
elif hasattr(roi, 'center'):
center = roi.center()
width_orig = roi.xmax - roi.xmin
height_orig = roi.ymax - roi.ymin
roi.xmin = center[0] - width_orig/2 * self.scale_factor
roi.xmax = center[0] + width_orig/2 * self.scale_factor
roi.ymin = center[1] - height_orig/2 * self.scale_factor
roi.ymax = center[1] + height_orig/2 * self.scale_factor
else:
raise NotImplementedError

Check warning on line 2018 in jdaviz/core/template_mixin.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/core/template_mixin.py#L2018

Added line #L2018 was not covered by tests

x, y = roi.to_polygon()
# concatenate with nan between to avoid line connecting separate subsets
x_coords = np.concatenate((x_coords, np.array([np.nan]), x))
Expand Down Expand Up @@ -2040,14 +2055,14 @@ class ApertureSubsetSelectMixin(VuetifyTemplate, HubListener):
"""
aperture_items = List([]).tag(sync=True)
aperture_selected = Any('').tag(sync=True)
aperture_radius_factor = Float(1).tag(sync=True)
aperture_scale_factor = Float(1).tag(sync=True)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.aperture = ApertureSubsetSelect(self,
'aperture_items',
'aperture_selected',
'aperture_radius_factor',
'aperture_scale_factor',
dataset='dataset' if hasattr(self, 'dataset') else None, # noqa
multiselect='multiselect' if hasattr(self, 'multiselect') else None) # noqa

Expand Down

0 comments on commit b8f06d7

Please # to comment.