Skip to content

Commit 6608b55

Browse files
committed
fix: add nodes and node labels
1 parent cb15a19 commit 6608b55

File tree

1 file changed

+24
-31
lines changed

1 file changed

+24
-31
lines changed

src/pynite_plotly/rendering.py

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def __init__(
4242
spring=3
4343
),
4444
title: str = "Pynite - Simple Finite Element Analysis for Python",
45-
height: int = 800,
46-
width: int = 800,
45+
window_height: int = 800,
46+
window_width: int = 800,
4747
):
4848
self.model = model
4949

@@ -61,21 +61,16 @@ def __init__(
6161
self._scalar_bar_text_size = 24
6262
self.theme = "default"
6363
self.colors = colors
64-
self.line_widths = dict(
65-
member=4,
66-
loads=2,
67-
deformed_member=2,
68-
spring=3
69-
)
70-
64+
self.line_widths = line_widths
7165
self._title = "Pynite - Simple Finite Element Analysis for Python"
72-
66+
self._window_width = window_width
67+
self._window_height = window_height
7368
self.plotter = None
7469

7570

7671
self._layout = default_layout(self._title)
77-
self.window_width = width
78-
self.window_height = height
72+
self._layout.width = window_width
73+
self._layout.height = window_height
7974

8075
# self.plotter.set_background('white') # Setting background color
8176
# # self.plotter.add_logo_widget('./Resources/Full Logo No Buffer - Transparent.png')
@@ -90,6 +85,7 @@ def __init__(
9085
# Initialize spring labels
9186
self._spring_label_points = []
9287
self._spring_labels = []
88+
self._annotations = []
9389

9490
## Get Figure Size
9591

@@ -225,7 +221,6 @@ def render_model(self, reset_camera=True):
225221
self.update(reset_camera)
226222

227223
# Render the model (code execution will pause here until the user closes the window)
228-
self.plotter.show()
229224
return self.plotter
230225

231226
def screenshot(
@@ -289,8 +284,7 @@ def update(self, reset_camera=True):
289284
# Clear out the old plot (if any)
290285
self.plotter = go.Figure()
291286

292-
layout = default_layout(self._title)
293-
self._layout = layout
287+
layout = self._layout
294288

295289
## Set the layout
296290
self.plotter.layout = self._layout
@@ -1689,6 +1683,8 @@ def add_point_labels(
16891683
point_size: int = 5,
16901684
shape: str = None,
16911685
render_points_as_spheres=False,
1686+
x_shift=0,
1687+
y_shift=0
16921688
):
16931689
assert len(points) == len(labels)
16941690
# if show_points or render_points_as_spheres or shape:
@@ -1703,17 +1699,14 @@ def add_point_labels(
17031699
label = labels[idx]
17041700
x, y, z = point
17051701
text_label = f"{start_bold_tag}{label}{end_bold_tag}"
1706-
# annotations.append(
1707-
# dict(
1708-
# x=x,
1709-
# y=y,
1710-
# z=z,
1711-
# text=text_label,
1712-
# font=dict(
1713-
# color=self.colors['point_label_text']
1714-
# ),
1715-
# )
1716-
# )
1702+
if render_points_as_spheres:
1703+
...
1704+
self.plotter.add_trace(
1705+
go.Scatter3d(
1706+
x=[x], y=[y], z=[z], marker=dict(color=point_color, size=self.annotation_size/30)
1707+
)
1708+
)
1709+
# print(f"Annotation: {text_label=} | {point=}")
17171710
annotations.append(
17181711
dict(
17191712
x=x,
@@ -1722,15 +1715,15 @@ def add_point_labels(
17221715
text=text_label,
17231716
showarrow=False,
17241717
font=dict(
1725-
color=self.colors['point_label_text'],
1718+
color=text_color,
17261719
size=16
17271720
),
1728-
yshift=5,
1729-
xshift=5
1721+
yshift=y_shift,
1722+
xshift=x_shift,
17301723
)
17311724
)
1732-
1733-
self.plotter.update_layout(scene=dict(annotations=annotations))
1725+
self._annotations += annotations
1726+
self.plotter.update_layout(scene=dict(annotations=self._annotations))
17341727
# TODO: Show points
17351728

17361729

0 commit comments

Comments
 (0)