Skip to content

Commit 26059f2

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 1d25d7f commit 26059f2

File tree

4 files changed

+84
-15
lines changed

4 files changed

+84
-15
lines changed

examples/01-basic-plotly-examples/plain-usage.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
123
from ansys.tools.visualization_interface.backends.plotly.plotly_interface import PlotlyBackend
224
from ansys.tools.visualization_interface.types import MeshObjectPlot
325
from ansys.tools.visualization_interface import Plotter

src/ansys/tools/visualization_interface/backends/plotly/plotly_interface.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
1+
# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
123
"""Plotly backend interface for visualization."""
2-
from ansys.tools.visualization_interface.backends._base import BaseBackend
3-
from ansys.tools.visualization_interface.types.mesh_object_plot import MeshObjectPlot
24+
from typing import Any, Union
25+
426
import plotly.graph_objects as go
527
from pyvista import PolyData
6-
from typing import Union, Iterable, Any
28+
29+
from ansys.tools.visualization_interface.backends._base import BaseBackend
30+
from ansys.tools.visualization_interface.types.mesh_object_plot import MeshObjectPlot
731

832

933
class PlotlyBackend(BaseBackend):
@@ -16,14 +40,14 @@ def _pv_to_mesh3d(self, pv_mesh: PolyData) -> go.Mesh3d:
1640
"""Convert a PyVista PolyData mesh to Plotly Mesh3d format."""
1741
points = pv_mesh.points
1842
x, y, z = points[:, 0], points[:, 1], points[:, 2]
19-
43+
2044
# Convert mesh to triangular mesh if needed, since Plotly only supports triangular faces
2145
triangulated_mesh = pv_mesh.triangulate()
22-
46+
2347
# Extract triangular faces
2448
faces = triangulated_mesh.faces.reshape((-1, 4)) # Now we know all faces are triangular (3 vertices + count)
2549
i, j, k = faces[:, 1], faces[:, 2], faces[:, 3]
26-
50+
2751
return go.Mesh3d(x=x, y=y, z=z, i=i, j=j, k=k)
2852
@property
2953
def layout(self) -> Any:
@@ -39,8 +63,8 @@ def plot_iter(self, plotting_list):
3963
"""Plot multiple objects using Plotly."""
4064
for item in plotting_list:
4165
self.plot(item)
42-
43-
66+
67+
4468
def plot(self, plottable_object: Union[PolyData, MeshObjectPlot, go.Mesh3d], **plotting_options):
4569
"""Plot a single object using Plotly."""
4670
if isinstance(plottable_object, PolyData):
@@ -58,19 +82,19 @@ def plot(self, plottable_object: Union[PolyData, MeshObjectPlot, go.Mesh3d], **p
5882
except Exception:
5983
raise TypeError("Unsupported plottable_object type for PlotlyInterface.")
6084

61-
def show(self,
85+
def show(self,
6286
plottable_object=None,
6387
screenshot: str = None,
6488
name_filter=None,
6589
**kwargs):
6690
"""Render the Plotly scene."""
6791
if plottable_object is not None:
6892
self.plot(plottable_object)
69-
93+
7094
# Only show in browser if no screenshot is being taken
7195
if not screenshot:
7296
self._fig.show(**kwargs)
73-
97+
7498
if screenshot:
7599
screenshot_str = str(screenshot)
76100
if screenshot_str.endswith('.html'):

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
# SOFTWARE.
2222
"""Conftest file for unit tests."""
2323
import os
24+
from pathlib import Path
2425

25-
import pytest
2626
from PIL import Image, ImageChops
27-
from pathlib import Path
27+
import pytest
2828

2929
os.environ.setdefault("PYANSYS_VISUALIZER_TESTMODE", "true")
3030

tests/test_plotly_backend.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
1+
# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
from plotly.graph_objects import Mesh3d, Scatter3d
24+
import pyvista as pv
25+
126
from ansys.tools.visualization_interface import Plotter
227
from ansys.tools.visualization_interface.backends.plotly.plotly_interface import PlotlyBackend
3-
import pyvista as pv
4-
from plotly.graph_objects import Mesh3d, Scatter3d
528
from ansys.tools.visualization_interface.types import MeshObjectPlot
629

730

0 commit comments

Comments
 (0)