Skip to content

Commit accc862

Browse files
author
Xing Han Lu
authored
Merge pull request #605 from plotly/update-dash-vtk-explorer
Update dash-vtk-explorer Former-commit-id: 500fd50
2 parents a1755ab + f0905e6 commit accc862

File tree

11 files changed

+81
-6
lines changed

11 files changed

+81
-6
lines changed
Loading

apps/dash-vtk-explorer/demos/pyvista-point-cloud/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
dash-vtk
33
pyvista
44
numpy
5+
vtk

apps/dash-vtk-explorer/demos/pyvista-terrain-following-mesh/app.py

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from dash.dependencies import Input, Output, State
77

88
import random
9+
import json
910
import numpy as np
1011
import pyvista as pv
1112
from pyvista import examples
@@ -44,6 +45,7 @@ def updateWarp(factor=1):
4445

4546
vtk_view = dash_vtk.View(
4647
id="vtk-view",
48+
pickingModes=["hover"],
4749
children=[
4850
dash_vtk.GeometryRepresentation(
4951
id="vtk-representation",
@@ -68,8 +70,19 @@ def updateWarp(factor=1):
6870
],
6971
colorMapPreset="erdc_blue2green_muted",
7072
colorDataRange=color_range,
71-
property={"edgeVisibility": True,},
72-
)
73+
property={"edgeVisibility": True},
74+
showCubeAxes=True,
75+
cubeAxesStyle={"axisLabels": ["", "", "Altitude"]},
76+
),
77+
dash_vtk.GeometryRepresentation(
78+
id="pick-rep",
79+
actor={"visibility": False},
80+
children=[
81+
dash_vtk.Algorithm(
82+
id="pick-sphere", vtkClass="vtkSphereSource", state={"radius": 100},
83+
)
84+
],
85+
),
7386
],
7487
)
7588

@@ -96,31 +109,86 @@ def updateWarp(factor=1):
96109
value="erdc_rainbow_bright",
97110
),
98111
),
112+
dbc.Col(
113+
children=dcc.Checklist(
114+
id="toggle-cube-axes",
115+
options=[{"label": " Show axis grid", "value": "grid"},],
116+
value=[],
117+
labelStyle={"display": "inline-block"},
118+
),
119+
),
99120
],
100121
style={"height": "12%", "align-items": "center"},
101122
),
102123
html.Div(
103124
html.Div(vtk_view, style={"height": "100%", "width": "100%"}),
104125
style={"height": "88%"},
105126
),
127+
html.Pre(
128+
id="tooltip",
129+
style={
130+
"position": "absolute",
131+
"bottom": "25px",
132+
"left": "25px",
133+
"zIndex": 1,
134+
"color": "white",
135+
},
136+
),
106137
],
107138
)
108139

109140

110141
@app.callback(
111142
[
143+
Output("vtk-representation", "showCubeAxes"),
112144
Output("vtk-representation", "colorMapPreset"),
113145
Output("vtk-representation", "colorDataRange"),
114146
Output("vtk-polydata", "points"),
115147
Output("vtk-polydata", "polys"),
116148
Output("vtk-array", "values"),
117149
Output("vtk-view", "triggerResetCamera"),
118150
],
119-
[Input("dropdown-preset", "value"), Input("scale-factor", "value")],
151+
[
152+
Input("dropdown-preset", "value"),
153+
Input("scale-factor", "value"),
154+
Input("toggle-cube-axes", "value"),
155+
],
120156
)
121-
def updatePresetName(name, scale_factor):
157+
def updatePresetName(name, scale_factor, cubeAxes):
122158
points, polys, elevation, color_range = updateWarp(scale_factor)
123-
return [name, color_range, points, polys, elevation, random.random()]
159+
return [
160+
"grid" in cubeAxes,
161+
name,
162+
color_range,
163+
points,
164+
polys,
165+
elevation,
166+
random.random(),
167+
]
168+
169+
170+
@app.callback(
171+
[
172+
Output("tooltip", "children"),
173+
Output("pick-sphere", "state"),
174+
Output("pick-rep", "actor"),
175+
],
176+
[Input("vtk-view", "clickInfo"), Input("vtk-view", "hoverInfo"),],
177+
)
178+
def onInfo(clickData, hoverData):
179+
info = hoverData if hoverData else clickData
180+
if info:
181+
if (
182+
"representationId" in info
183+
and info["representationId"] == "vtk-representation"
184+
):
185+
return (
186+
[json.dumps(info, indent=2)],
187+
{"center": info["worldPosition"]},
188+
{"visibility": True},
189+
)
190+
return dash.no_update, dash.no_update, dash.no_update
191+
return [""], {}, {"visibility": False}
124192

125193

126194
if __name__ == "__main__":
Loading
Loading
Loading
Loading
Loading
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# If you skipped `pip install -e ../../`, the package below will be retrieved from pypi:
22
dash-vtk
3+
dash
34
vtk
45
numpy

0 commit comments

Comments
 (0)