Skip to content

Commit

Permalink
basic implementation of mouseover marker
Browse files Browse the repository at this point in the history
* only used in spectrum profile viewers
* currently ALWAYS on
  • Loading branch information
kecnry committed Dec 29, 2022
1 parent b1f465d commit 682a4be
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
25 changes: 25 additions & 0 deletions jdaviz/configs/imviz/plugins/coords_info/coords_info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from traitlets import Bool, Unicode

from jdaviz.configs.specviz.plugins.viewers import SpecvizProfileView
from jdaviz.core.registries import tool_registry
from jdaviz.core.template_mixin import TemplateMixin
from jdaviz.core.marks import PluginScatter

__all__ = ['CoordsInfo']

Expand All @@ -23,6 +25,29 @@ class CoordsInfo(TemplateMixin):
unreliable_world = Bool(False).tag(sync=True)
unreliable_pixel = Bool(False).tag(sync=True)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._marks = {}
# initialize marks (this plugin doesn't open so won't create marks on open)
self.marks

@property
def marks(self):
"""
Access the marks created by this plugin.
"""
if self._marks:
# TODO: replace with cache property?
return self._marks

# create marks for each of the spectral viewers (will need a listener event to create marks
# for new viewers if dynamic creation of spectral viewers is ever supported)
for id, viewer in self.app._viewer_store.items():
if isinstance(viewer, SpecvizProfileView):
self._marks[id] = PluginScatter(viewer, visible=False)
viewer.figure.marks = viewer.figure.marks + [self._marks[id]]
return self._marks

def reset_coords_display(self):
self.world_label_prefix = '\u00A0'
self.world_label_prefix_2 = '\u00A0'
Expand Down
4 changes: 4 additions & 0 deletions jdaviz/configs/specviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def on_mouse_or_key_event(self, data):
self.label_mouseover.pixel = ""
self.label_mouseover.reset_coords_display()
self.label_mouseover.value = ""
self.label_mouseover.marks[self._reference_id].visible = False
return

fmt = 'x={:0' + str(closest_maxsize) + '.1f}'
Expand All @@ -130,12 +131,15 @@ def on_mouse_or_key_event(self, data):
self.label_mouseover.world_dec_deg = closest_flux.unit.to_string()
self.label_mouseover.icon = closest_label
self.label_mouseover.value = "" # Not used
self.label_mouseover.marks[self._reference_id].update_xy([closest_wave.value], [closest_flux.value])
self.label_mouseover.marks[self._reference_id].visible = True

elif data['event'] == 'mouseleave' or data['event'] == 'mouseenter':
self.label_mouseover.icon = ""
self.label_mouseover.pixel = ""
self.label_mouseover.reset_coords_display()
self.label_mouseover.value = ""
self.label_mouseover.marks[self._reference_id].visible = False

def _expected_subset_layer_default(self, layer_state):
super()._expected_subset_layer_default(layer_state)
Expand Down
24 changes: 18 additions & 6 deletions jdaviz/core/marks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

__all__ = ['OffscreenLinesMarks', 'BaseSpectrumVerticalLine', 'SpectralLine',
'SliceIndicatorMarks', 'ShadowMixin', 'ShadowLine', 'ShadowLabelFixedY',
'PluginLine',
'PluginLine', 'PluginScatter',
'LineAnalysisContinuum', 'LineAnalysisContinuumCenter',
'LineAnalysisContinuumLeft', 'LineAnalysisContinuumRight',
'LineUncertainties', 'ScatterMask', 'SelectedSpaxel']
Expand Down Expand Up @@ -484,19 +484,31 @@ def _on_shadowing_changed(self, change):
self._update_align()


class PluginLine(Lines, HubListener):
def __init__(self, viewer, x=[], y=[], **kwargs):
# color is same blue as import button
super().__init__(x=x, y=y, colors=["#007BA1"], scales=viewer.scales, **kwargs)

class PluginMark():
def update_xy(self, x, y):
self.x = np.asarray(x)
self.y = np.asarray(y)

def append_xy(self, x, y):
self.x = np.append(self.x, x)
self.y = np.append(self.y, y)

def clear(self):
self.update_xy([], [])


class PluginLine(Lines, PluginMark, HubListener):
def __init__(self, viewer, x=[], y=[], **kwargs):
# color is same blue as import button
super().__init__(x=x, y=y, colors=["#007BA1"], scales=viewer.scales, **kwargs)


class PluginScatter(Scatter, PluginMark, HubListener):
def __init__(self, viewer, x=[], y=[], **kwargs):
# color is same blue as import button
super().__init__(x=x, y=y, colors=["#007BA1"], scales=viewer.scales, **kwargs)


class LineAnalysisContinuum(PluginLine):
pass

Expand Down

0 comments on commit 682a4be

Please sign in to comment.