Skip to content

Commit

Permalink
temporarily "clean" incompatible marks
Browse files Browse the repository at this point in the history
by removing any unicode characters and restoring after export
  • Loading branch information
kecnry committed Apr 23, 2024
1 parent 479d17f commit efd9240
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ Bug Fixes
Cubeviz
^^^^^^^

- Re-enable support for exporting spectrum-viewer. [#2825]

Imviz
^^^^^

Expand Down
22 changes: 22 additions & 0 deletions jdaviz/configs/default/plugins/export/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from glue_jupyter.bqplot.image import BqplotImageView

from jdaviz.core.custom_traitlets import FloatHandleEmpty, IntHandleEmpty
from jdaviz.core.marks import ShadowMixin
from jdaviz.core.registries import tray_registry
from jdaviz.core.template_mixin import (PluginTemplateMixin, SelectPluginComponent,
ViewerSelectMixin, DatasetMultiSelectMixin,
Expand Down Expand Up @@ -330,11 +331,32 @@ def export(self, filename=None, show_dialog=None, overwrite=False,
raise FileExistsError(f"{filename} exists but overwrite=False")
return

# temporarily "clean" incompatible marks of unicode characters, etc
restores = []
for mark in viewer.figure.marks:
restore = {}
if len(getattr(mark, 'text', [])):
if not isinstance(mark, ShadowMixin):

Check warning on line 339 in jdaviz/configs/default/plugins/export/export.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/default/plugins/export/export.py#L339

Added line #L339 was not covered by tests
# if it is shadowing another mark, that will automatically get updated
# when the other mark is restored, but we'll still ensure that the mark
# is clean of unicode before exporting.
restore['text'] = [t for t in mark.text]
mark.text = [t.strip() for t in mark.text]

Check warning on line 344 in jdaviz/configs/default/plugins/export/export.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/default/plugins/export/export.py#L343-L344

Added lines #L343 - L344 were not covered by tests
if len(getattr(mark, 'labels', [])):
restore['labels'] = mark.labels[:]
mark.labels = [lbl.strip() for lbl in mark.labels]

Check warning on line 347 in jdaviz/configs/default/plugins/export/export.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/default/plugins/export/export.py#L346-L347

Added lines #L346 - L347 were not covered by tests
restores.append(restore)

if filetype == "mp4":
self.save_movie(viewer, filename, filetype)
else:
self.save_figure(viewer, filename, filetype, show_dialog=show_dialog)

# restore marks to their original state
for restore, mark in zip(restores, viewer.figure.marks):
for k, v in restore.items():
setattr(mark, k, v)

Check warning on line 358 in jdaviz/configs/default/plugins/export/export.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/default/plugins/export/export.py#L356-L358

Added lines #L356 - L358 were not covered by tests

elif len(self.plugin_plot.selected):
plot = self.plugin_plot.selected_obj._obj
filetype = self.plugin_plot_format.selected
Expand Down

0 comments on commit efd9240

Please sign in to comment.