Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Lines for table layers #96

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add line functionality for table layer.
Carifio24 committed Mar 3, 2023
commit 20132fc84d867ddfc4efe4dbb38f4ab33ff1cba5
26 changes: 26 additions & 0 deletions glue_wwt/viewer/table_layer.py
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@
from astropy.coordinates import SkyCoord
from astropy.table import Table

from matplotlib.colors import to_rgb

import pywwt
from pywwt.layers import TableLayer
from distutils.version import LooseVersion
@@ -71,6 +73,8 @@ class WWTTableLayerState(LayerState):

img_data_att = SelectionCallbackProperty(default_index=0)

line_visible = CallbackProperty(False)

def __init__(self, layer=None, **kwargs):

self._sync_markersize = None
@@ -165,6 +169,8 @@ def __init__(self, viewer_state, wwt_client=None, layer_state=None, layer=None):
self.wwt_layer = None
self._coords = [], []

self.line = None

self.layer_id = "{0:08x}".format(random.getrandbits(32))
self.wwt_client = wwt_client

@@ -181,6 +187,9 @@ def clear(self):
self.wwt_layer.remove()
self.wwt_layer = None
self._coords = [], []
if self.line is not None:
self.line.remove()
self.line = None

def remove(self):
self._removed = True
@@ -359,6 +368,8 @@ def _update_presentation(self, force=False, **kwargs):

if force or 'color' in changed:
self.wwt_layer.color = self.state.color
if self.line is not None:
self.line.color = self._annotation_color

if force or 'alpha' in changed:
self.wwt_layer.opacity = self.state.alpha
@@ -380,6 +391,17 @@ def _update_presentation(self, force=False, **kwargs):

self.enable()

if 'line_visible' in changed:
if self.state.line_visible:
lon, lat = self._coords
points = SkyCoord(lon, lat, unit=u.deg)
self.line = self.wwt_client.add_line(points, color=self._annotation_color)
else:
self.wwt_client.clear_annotations()
if self.line is not None:
self.line.remove()
self.line = None

# TODO: deal with visible, zorder, frame

def center(self, *args):
@@ -401,3 +423,7 @@ def redraw(self):

def update(self):
self._update_presentation(force=True)

@property
def _annotation_color(self):
return (*to_rgb(self.state.color), self.state.alpha)