Skip to content

Commit 5121e51

Browse files
fix: Allow PyVista HTML jupyter backend (#119)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent f12e515 commit 5121e51

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

doc/changelog.d/119.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fix: Allow PyVista HTML jupyter backend

src/ansys/tools/visualization_interface/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
TESTING_MODE: bool = os.environ.get("PYANSYS_VISUALIZER_TESTMODE", "false").lower() == "true"
3434
"""Whether the library is being built or not, used to avoid showing plots while testing."""
3535

36+
USE_HTML_BACKEND: bool = os.environ.get("PYANSYS_VISUALIZER_HTML_BACKEND", "false").lower() == "true"
37+
"""Whether the library is being built or not, used to avoid showing plots while testing."""
38+
39+
3640
from ansys.tools.visualization_interface.plotter import Plotter # noqa: F401, E402
3741
from ansys.tools.visualization_interface.types.edge_plot import EdgePlot # noqa: F401, E402
3842
from ansys.tools.visualization_interface.types.mesh_object_plot import ( # noqa: F401, E402

src/ansys/tools/visualization_interface/backends/pyvista/pyvista_interface.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def plot_iter(
289289
def show(
290290
self,
291291
show_plane: bool = False,
292-
jupyter_backend: Optional[str] = None,
292+
jupyter_backend: Optional[str] = "trame", # Use the PyVista default backend
293293
**kwargs: Optional[Dict],
294294
) -> None:
295295
"""Show the rendered scene on the screen.
@@ -298,6 +298,8 @@ def show(
298298
----------
299299
show_plane : bool, default: True
300300
Whether to show the XY plane.
301+
jupyter_backend : str, default: None
302+
PyVista Jupyter backend.
301303
**kwargs : dict, default: None
302304
Plotting keyword arguments. For allowable keyword arguments, see the
303305
:meth:`Plotter.show <pyvista.Plotter.show>` method.
@@ -320,13 +322,17 @@ def show(
320322
plane = pv.Plane(i_size=sfac * 1.3, j_size=sfac * 1.3)
321323
self.scene.add_mesh(plane, color="white", show_edges=True, opacity=0.1)
322324

325+
# Override Jupyter backend if building docs
326+
if viz_interface.USE_HTML_BACKEND:
327+
jupyter_backend = "html"
328+
323329
# Enabling anti-aliasing by default on scene
324330
self.scene.enable_anti_aliasing("ssaa")
325331

326332
# If screenshot is requested, set off_screen to True for the plotter
327333
if kwargs.get("screenshot") is not None:
328334
self.scene.off_screen = True
329-
self.scene.show(**kwargs)
335+
self.scene.show(jupyter_backend=jupyter_backend, **kwargs)
330336

331337
def set_add_mesh_defaults(self, plotting_options: Optional[Dict]) -> None:
332338
"""Set the default values for the plotting options.

0 commit comments

Comments
 (0)