Skip to content

Commit

Permalink
Merge pull request #1 from kecnry/export-plugin-plot-render-offscreen
Browse files Browse the repository at this point in the history
render selected plot for export offscreen
  • Loading branch information
cshanahan1 authored Apr 3, 2024
2 parents daf585b + b68f18e commit 134dfe7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions jdaviz/configs/default/plugins/export/export.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import time
from pathlib import Path
from traitlets import Bool, List, Unicode, observe
from glue_jupyter.bqplot.image import BqplotImageView
Expand All @@ -23,7 +24,6 @@
HAS_OPENCV = False
else:
import threading
import time
HAS_OPENCV = True

__all__ = ['Export']
Expand Down Expand Up @@ -300,7 +300,12 @@ def export(self, filename=None, show_dialog=None):
filename = Path(filename).expanduser()
else:
filename = None
self.save_figure(plot, filename, filetype, show_dialog=show_dialog)

with plot._plugin.as_active():
# NOTE: could still take some time for the plot itself to update,
# for now we'll hardcode a short amount of time for the plot to render any updates
time.sleep(0.2)
self.save_figure(plot, filename, filetype, show_dialog=show_dialog)

elif len(self.table.selected):
filetype = self.table_format.selected
Expand Down
4 changes: 4 additions & 0 deletions jdaviz/configs/default/plugins/export/export.vue
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@
:single_select_allow_blank="false"
>
</plugin-inline-select>
<jupyter-widget
v-if='plot_selected_widget.length > 0'
style="position: absolute; left: -100%"
:widget="plot_selected_widget"/>
<v-row v-if="plot_selected.length > 0" class="row-min-bottom-padding">
<v-select
:menu-props="{ left: true }"
Expand Down
10 changes: 10 additions & 0 deletions jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2589,6 +2589,7 @@ def not_empty_plot(plot):
class PluginPlotSelectMixin(VuetifyTemplate, HubListener):
plot_items = List().tag(sync=True)
plot_selected = Any().tag(sync=True)
plot_selected_widget = Any().tag(sync=True)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -2597,6 +2598,15 @@ def __init__(self, *args, **kwargs):
'plot_selected',
multiselect='multiselect' if hasattr(self, 'multiselect') else None) # noqa

@observe('plot_selected')
def _plot_selected_changed(self, *args):
if not hasattr(self, 'plot'):
return
if self.plot_selected == '':
self.plot_selected_widget = ''
else:
self.plot_selected_widget = f'IPY_MODEL_{self.plot.selected_obj._obj.model_id}'


class DatasetSpectralSubsetValidMixin(VuetifyTemplate, HubListener):
"""
Expand Down

0 comments on commit 134dfe7

Please sign in to comment.