Skip to content

Commit

Permalink
generalize clone viewer logic to work for multliple viewer types
Browse files Browse the repository at this point in the history
and to also adopt layer plot options
  • Loading branch information
kecnry committed Mar 27, 2024
1 parent 112ce73 commit 97e6f20
Showing 1 changed file with 15 additions and 36 deletions.
51 changes: 15 additions & 36 deletions lcviz/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,34 @@ def _get_clone_viewer_reference(self):
return name

def clone_viewer(self):
name = self._get_clone_viewer_reference()
name = self.jdaviz_helper._get_clone_viewer_reference(self.reference)

self.jdaviz_app._on_new_viewer(NewViewerMessage(self.__class__,
data=None,
sender=self.jdaviz_app),
vid=name, name=name)

this_viewer_item = self.jdaviz_app._get_viewer_item(self.reference)
this_state = self.state.as_dict()
for data in self.jdaviz_app.data_collection:
data_id = self.jdaviz_app._data_id_from_label(data.label)
visible = this_viewer_item['selected_data_items'].get(data_id, 'hidden')
self.jdaviz_app.set_data_visibility(name, data.label, visible == 'visible')
for data_id, visible in this_viewer_item['selected_data_items'].items():
data_label = data_label = self.jdaviz_app._get_data_item_by_id(data_id)['name']
self.jdaviz_app.set_data_visibility(name, data_label, visible == 'visible')
# TODO: don't revert color when adding same data to a new viewer
# (same happens when creating a phase-viewer from ephemeris plugin)

new_viewer = self.jdaviz_helper.viewers[name]._obj
for k, v in this_state.items():
new_viewer = self.jdaviz_app.get_viewer(name)
if hasattr(self, 'ephemeris_component'):
new_viewer._ephemeris_component = self._ephemeris_component
for k, v in self.state.as_dict().items():
if k in ('layers',):
continue
setattr(new_viewer.state, k, v)

for this_layer_state, new_layer_state in zip(self.state.layers, new_viewer.state.layers):
for k, v in this_layer_state.as_dict().items():
if k in ('layer',):
continue
setattr(new_layer_state, k, v)

return new_viewer.user_api


Expand Down Expand Up @@ -253,33 +259,6 @@ def apply_roi(self, roi, use_current=False):

super().apply_roi(roi, use_current=use_current)

def clone_viewer(self):
name = self.jdaviz_helper._get_clone_viewer_reference(self.reference)

self.jdaviz_app._on_new_viewer(NewViewerMessage(self.__class__,
data=None,
sender=self.jdaviz_app),
vid=name, name=name)

this_viewer_item = self.jdaviz_app._get_viewer_item(self.reference)
this_state = self.state.as_dict()
for data in self.jdaviz_app.data_collection:
data_id = self.jdaviz_app._data_id_from_label(data.label)
visible = this_viewer_item['selected_data_items'].get(data_id, 'hidden')
self.jdaviz_app.set_data_visibility(name, data.label, visible == 'visible')
# TODO: don't revert color when adding same data to a new viewer
# (same happens when creating a phase-viewer from ephemeris plugin)

new_viewer = self.jdaviz_app.get_viewer(name)
if hasattr(self, 'ephemeris_component'):
new_viewer._ephemeris_component = self._ephemeris_component
for k, v in this_state.items():
if k in ('layers',):
continue
setattr(new_viewer.state, k, v)

return new_viewer.user_api


@viewer_registry("lcviz-phase-viewer", label="flux-vs-phase")
class PhaseScatterView(TimeScatterView):
Expand Down Expand Up @@ -337,7 +316,7 @@ def __init__(self, *args, **kwargs):
# Hide axes by default
self.state.show_axes = False

# TODO: refactor upstream so lcviz can inherit cubeviewer methods/setup without
# TODO: refactor upstream so lcviz can inherit cubeviewer methods/setup without
# jdaviz-specific logic:
# * _default_spectrum_viewer_reference_name
# * _default_flux_viewer_reference_name
Expand Down

0 comments on commit 97e6f20

Please sign in to comment.