Skip to content

Commit

Permalink
Allow plugin to follow viewer coords thru panning
Browse files Browse the repository at this point in the history
  • Loading branch information
duytnguyendtn committed Sep 13, 2024
1 parent 03a00e3 commit 300f194
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
20 changes: 19 additions & 1 deletion jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class VoPlugin(PluginTemplateMixin, AddResultsMixin, TableMixin):
resources_loading = Bool(False).tag(sync=True)

source = Unicode("").tag(sync=True)
coord_follow_viewer_pan = Bool(False).tag(sync=True)
coordframes = List([]).tag(sync=True)
coordframe_selected = Unicode("icrs").tag(sync=True)
radius_val = Float(1).tag(sync=True)
Expand Down Expand Up @@ -89,7 +90,24 @@ def __init__(self, *args, **kwargs):
self.hub.subscribe(self, RemoveDataMessage, handler=self.vue_center_on_data)
self.hub.subscribe(self, LinkUpdatedMessage, handler=self.vue_center_on_data)

@observe("viewer_selected", type="change")
@observe("viewer_selected", "coord_follow_viewer_pan", type="change")
def vue_viewer_changed(self, _=None):
if not hasattr(self, "viewer"):
# mixin object not yet initialized
return

# Clear all existing subscriptions
for viewer in self.viewer.viewers:
viewer.state.remove_callback('zoom_center_x', self.vue_center_on_data)
viewer.state.remove_callback('zoom_center_y', self.vue_center_on_data)

# Subscribe to selected viewer
if self.coord_follow_viewer_pan:
self.viewer.selected_obj.state.add_callback('zoom_center_x', self.vue_center_on_data)
self.viewer.selected_obj.state.add_callback('zoom_center_y', self.vue_center_on_data)

self.vue_center_on_data()

def vue_center_on_data(self, _=None):
"""
If data is present in the default viewer, center the plugin's coordinates on
Expand Down
15 changes: 12 additions & 3 deletions jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@
:selected.sync="viewer_selected"
label="Viewer"
:show_if_single_entry="true"
hint="Select a viewer to autofill center coordinates, or Manual for manual coordinate entry."
hint="Select a viewer to retrieve center coordinates, or Manual for manual coordinate entry."
/>

<v-row v-if="viewer_selected !== 'Manual'">
<v-switch
v-model="coord_follow_viewer_pan"
label="Follow Viewer Center"
hint="Automatically adjust coordinates as viewer pans and zooms"
persistent-hint
></v-switch>
</v-row>

<v-row>
<div :style="viewer_selected === 'Manual' ? 'width: 100%' : 'width: calc(100% - 32px)'">
<div :style="!(viewer_selected !== 'Manual' && !coord_follow_viewer_pan) ? 'width: 100%' : 'width: calc(100% - 32px)'">
<v-text-field
v-model="source"
label="Source/Coordinates"
Expand All @@ -26,7 +35,7 @@
persistent-hint>
</v-text-field>
</div>
<div v-if="viewer_selected !== 'Manual'" style="line-height:64px; width:32px">
<div v-if="viewer_selected !== 'Manual' && !coord_follow_viewer_pan" style="line-height:64px; width:32px">
<v-btn
id="autocenterbtn"
@click="center_on_data"
Expand Down

0 comments on commit 300f194

Please sign in to comment.