Skip to content

Commit

Permalink
Add initial implementation of Jupyter Vispy volume exporter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Aug 1, 2024
1 parent 47d1426 commit 981f732
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions glue_plotly/html_exporters/jupyter/vispy_volume3d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from glue.config import viewer_tool
from glue_vispy_viewers.scatter.layer_artist import ScatterLayerArtist

from glue_plotly.common.base_3d import layout_config
from glue_plotly.common.common import data_count, layers_to_export
from glue_plotly.common.scatter3d import traces_for_layer as scatter3d_traces_for_layer
from glue_plotly.common.volume import traces_for_layer as volume_traces_for_layer
from glue_plotly.jupyter_base_export_tool import JupyterBaseExportTool

import plotly.graph_objs as go
from plotly.offline import plot


@viewer_tool
class PlotlyScatter3DStaticExport(JupyterBaseExportTool):
tool_id = 'save:jupyter_plotly3dvolume'

def save_figure(self, filepath):

if not filepath:
return

config = layout_config(self.viewer.state)
layout = go.Layout(**config)
fig = go.Figure(layout=layout)

layers = layers_to_export(self.viewer)
add_data_label = data_count(layers) > 1
bounds = self.viewer._vispy_widget._multivol._data_bounds
count = 5
for layer in layers:
if isinstance(layer, ScatterLayerArtist):
traces = scatter3d_traces_for_layer(self.viewer.state, layer.state,
add_data_label=add_data_label)
else:
traces = volume_traces_for_layer(self.viewer.state, layer.state, bounds,
isosurface_count=count,
add_data_label=add_data_label)

for trace in traces:
fig.add_trace(trace)

plot(fig, filename=filepath, auto_open=False)

0 comments on commit 981f732

Please sign in to comment.