Skip to content

Commit 9f2f92f

Browse files
Merge pull request #2 from StructuralPython/features/affordances
Features/affordances
2 parents e64f98b + 6608b55 commit 9f2f92f

File tree

1 file changed

+53
-42
lines changed

1 file changed

+53
-42
lines changed

src/pynite_plotly/rendering.py

Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,12 @@ class Renderer:
1414

1515
scalar = None
1616

17-
def __init__(self, model):
18-
self.model = model
19-
20-
# Default settings for rendering
21-
self._annotation_size = 5
22-
self._deformed_shape = False
23-
self._deformed_scale = 30
24-
self._render_nodes = True
25-
self._render_loads = True
26-
self._color_map = None
27-
self._combo_name = "Combo 1"
28-
self._case = None
29-
self._labels = True
30-
self._scalar_bar = False
31-
self._scalar_bar_text_size = 24
32-
self.theme = "default"
33-
self.colors = dict(
17+
def __init__(
18+
self,
19+
model,
20+
combo_name: str,
21+
annotation_size: int = 5,
22+
colors: dict = dict(
3423
annotation_text="black",
3524
annotation_point="grey",
3625
point_label_text="green",
@@ -42,22 +31,46 @@ def __init__(self, model):
4231
dist_load="green",
4332
moment_load="green",
4433
area_load="green",
45-
)
46-
self.line_widths = dict(
34+
),
35+
deformed_scale: float = 30.0,
36+
deformed_shape: bool = False,
37+
labels: bool = True,
38+
line_widths = dict(
4739
member=4,
4840
loads=2,
4941
deformed_member=2,
5042
spring=3
51-
)
43+
),
44+
title: str = "Pynite - Simple Finite Element Analysis for Python",
45+
window_height: int = 800,
46+
window_width: int = 800,
47+
):
48+
self.model = model
5249

50+
# Default settings for rendering
51+
self._annotation_size = annotation_size
52+
self._deformed_shape = deformed_shape
53+
self._deformed_scale = deformed_scale
54+
self._render_nodes = True
55+
self._render_loads = True
56+
self._color_map = None
57+
self._combo_name = combo_name
58+
self._case = None
59+
self._labels = labels
60+
self._scalar_bar = False
61+
self._scalar_bar_text_size = 24
62+
self.theme = "default"
63+
self.colors = colors
64+
self.line_widths = line_widths
5365
self._title = "Pynite - Simple Finite Element Analysis for Python"
54-
66+
self._window_width = window_width
67+
self._window_height = window_height
5568
self.plotter = None
5669

5770

5871
self._layout = default_layout(self._title)
59-
self.window_width = 800
60-
self.window_height = 800
72+
self._layout.width = window_width
73+
self._layout.height = window_height
6174

6275
# self.plotter.set_background('white') # Setting background color
6376
# # self.plotter.add_logo_widget('./Resources/Full Logo No Buffer - Transparent.png')
@@ -72,6 +85,7 @@ def __init__(self, model):
7285
# Initialize spring labels
7386
self._spring_label_points = []
7487
self._spring_labels = []
88+
self._annotations = []
7589

7690
## Get Figure Size
7791

@@ -207,7 +221,6 @@ def render_model(self, reset_camera=True):
207221
self.update(reset_camera)
208222

209223
# Render the model (code execution will pause here until the user closes the window)
210-
self.plotter.show()
211224
return self.plotter
212225

213226
def screenshot(
@@ -271,8 +284,7 @@ def update(self, reset_camera=True):
271284
# Clear out the old plot (if any)
272285
self.plotter = go.Figure()
273286

274-
layout = default_layout(self._title)
275-
self._layout = layout
287+
layout = self._layout
276288

277289
## Set the layout
278290
self.plotter.layout = self._layout
@@ -1671,6 +1683,8 @@ def add_point_labels(
16711683
point_size: int = 5,
16721684
shape: str = None,
16731685
render_points_as_spheres=False,
1686+
x_shift=0,
1687+
y_shift=0
16741688
):
16751689
assert len(points) == len(labels)
16761690
# if show_points or render_points_as_spheres or shape:
@@ -1685,17 +1699,14 @@ def add_point_labels(
16851699
label = labels[idx]
16861700
x, y, z = point
16871701
text_label = f"{start_bold_tag}{label}{end_bold_tag}"
1688-
# annotations.append(
1689-
# dict(
1690-
# x=x,
1691-
# y=y,
1692-
# z=z,
1693-
# text=text_label,
1694-
# font=dict(
1695-
# color=self.colors['point_label_text']
1696-
# ),
1697-
# )
1698-
# )
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=}")
16991710
annotations.append(
17001711
dict(
17011712
x=x,
@@ -1704,15 +1715,15 @@ def add_point_labels(
17041715
text=text_label,
17051716
showarrow=False,
17061717
font=dict(
1707-
color=self.colors['point_label_text'],
1718+
color=text_color,
17081719
size=16
17091720
),
1710-
yshift=5,
1711-
xshift=5
1721+
yshift=y_shift,
1722+
xshift=x_shift,
17121723
)
17131724
)
1714-
1715-
self.plotter.update_layout(scene=dict(annotations=annotations))
1725+
self._annotations += annotations
1726+
self.plotter.update_layout(scene=dict(annotations=self._annotations))
17161727
# TODO: Show points
17171728

17181729

0 commit comments

Comments
 (0)