From 300f194dae9b0434e1f4cd4ff9b57668b6b61361 Mon Sep 17 00:00:00 2001 From: Duy Nguyen Date: Fri, 13 Sep 2024 16:49:28 -0400 Subject: [PATCH] Allow plugin to follow viewer coords thru panning --- .../plugins/virtual_observatory/vo_plugin.py | 20 ++++++++++++++++++- .../plugins/virtual_observatory/vo_plugin.vue | 15 +++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.py b/jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.py index 2b85e8653a..2f88d06b7b 100644 --- a/jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.py +++ b/jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.py @@ -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) @@ -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 diff --git a/jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.vue b/jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.vue index a1a81af2db..3fb456a493 100644 --- a/jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.vue +++ b/jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.vue @@ -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." /> + + + + -
+
-
+