Skip to content

Commit

Permalink
helper and viewer-level access to data_labels properties
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Dec 18, 2023
1 parent f35136d commit 9056070
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
50 changes: 40 additions & 10 deletions jdaviz/configs/default/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,55 @@ def __init__(self, *args, **kwargs):
@property
def user_api(self):
# default exposed user APIs. Can override this method in any particular viewer.
expose = ['data_labels', 'data_labels_loaded', 'data_labels_visible']
if isinstance(self, BqplotImageView):
if isinstance(self, AstrowidgetsImageViewerMixin):
expose = ['save',
'center_on', 'offset_by', 'zoom_level', 'zoom',
'colormap_options', 'set_colormap',
'stretch_options', 'stretch',
'autocut_options', 'cuts',
'marker', 'add_markers', 'remove_markers', 'reset_markers',
'blink_once', 'reset_limits']
expose += ['save',
'center_on', 'offset_by', 'zoom_level', 'zoom',
'colormap_options', 'set_colormap',
'stretch_options', 'stretch',
'autocut_options', 'cuts',
'marker', 'add_markers', 'remove_markers', 'reset_markers',
'blink_once', 'reset_limits']
else:
# cubeviz image viewers don't inherit from AstrowidgetsImageViewerMixin yet,
# but also shouldn't expose set_limits because of equal aspect ratio concerns
expose = []
expose += []
elif isinstance(self, TableViewer):
expose = []
expose += []
else:
expose = ['set_limits', 'reset_limits']
expose += ['set_limits', 'reset_limits']
return ViewerUserApi(self, expose=expose)

@property
def data_labels_loaded(self):
"""
List of data labels loaded in this viewer.
Returns
-------
data_labels : list
list of strings
"""
viewer_item = self.jdaviz_app._get_viewer_item(self.reference_id)
return [self.jdaviz_app._get_data_item_by_id(data_id)['name']
for data_id in viewer_item.get('selected_data_items', {}).keys()]

@property
def data_labels_visible(self):
"""
List of data labels visible in this viewer.
Returns
-------
data_labels : list
list of strings
"""
viewer_item = self.jdaviz_app._get_viewer_item(self.reference_id)
return [self.jdaviz_app._get_data_item_by_id(data_id)['name']
for data_id, visibility in viewer_item.get('selected_data_items', {}).items()
if visibility != 'hidden']

def reset_limits(self):
"""
Reset viewer axes limits.
Expand Down
12 changes: 12 additions & 0 deletions jdaviz/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ def load_data(self, data, data_label=None, parser_reference=None, **kwargs):
kwargs['data_label'] = data_label
self.app.load_data(data, parser_reference=parser_reference, **kwargs)

@property
def data_labels(self):
"""
List of data labels loaded and available in jdaviz
Returns
-------
data_labels : list
list of strings
"""
return [data.label for data in self.app.data_collection]

@property
def plugins(self):
"""
Expand Down

0 comments on commit 9056070

Please # to comment.