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 c5ddd8c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 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,31 @@ 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 i, mark in enumerate(viewer.figure.marks):
restores.append({})
if len(getattr(mark, 'text', [])):
if not isinstance(mark, ShadowMixin):
# 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.
restores[i]['text'] = [t for t in mark.text]
mark.text = [t.strip() for t in mark.text]
if len(getattr(mark, 'labels', [])):
restores[i]['labels'] = mark.labels[:]
mark.labels = [l.strip() for l in mark.labels]

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)

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 c5ddd8c

Please sign in to comment.