Skip to content

Commit

Permalink
🎨 Improve add_table data transmission without private traitlets
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Apr 23, 2024
1 parent 981833f commit 87611b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
5 changes: 2 additions & 3 deletions js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function render({ model, el }) {
aladin.getOverlayImageLayer().setAlpha(model.get("overlay_survey_opacity"));
});

model.on("msg:custom", (msg) => {
model.on("msg:custom", (msg, buffers) => {
let options = {};
switch (msg["event_name"]) {
case "goto_ra_dec":
Expand Down Expand Up @@ -232,7 +232,7 @@ function render({ model, el }) {
aladin.select();
break;
case "add_table":
let table_bytes = model.get("_table");
let table_bytes = buffers[0].buffer;
let decoder = new TextDecoder("utf-8");
let blob = new Blob([decoder.decode(table_bytes)]);
let url = URL.createObjectURL(blob);
Expand All @@ -259,7 +259,6 @@ function render({ model, el }) {
model.off("change:overlay_survey");
model.off("change:overlay_survey_opacity");
model.off("change:trigger_event");
model.off("change:_table");
model.off("msg:custom");

aladin.off("positionChanged");
Expand Down
11 changes: 4 additions & 7 deletions src/ipyaladin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
List,
Dict,
Any,
Bytes,
default,
Undefined,
)

from .coordinate_parser import parse_coordinate_string
Expand Down Expand Up @@ -87,9 +85,6 @@ class Aladin(anywidget.AnyWidget):
overlay_survey = Unicode("").tag(sync=True, init_option=True)
overlay_survey_opacity = Float(0.0).tag(sync=True, init_option=True)

# tables/catalogs
_table = Bytes(Undefined).tag(sync=True)

init_options = List(trait=Any()).tag(sync=True)

@default("init_options")
Expand Down Expand Up @@ -300,8 +295,10 @@ def add_table(self, table, **table_options):

table_bytes = io.BytesIO()
table.write(table_bytes, format="votable")
self._table = table_bytes.getvalue()
self.send({"event_name": "add_table", "options": table_options})
self.send(
{"event_name": "add_table", "options": table_options},
buffers=[table_bytes.getvalue()],
)

def add_overlay_from_stcs(self, stc_string, **overlay_options):
"""Add an overlay layer defined by a STC-S string.
Expand Down

0 comments on commit 87611b0

Please sign in to comment.