-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
276 lines (249 loc) · 10.7 KB
/
app.py
File metadata and controls
276 lines (249 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#!/usr/bin/env python
"""matdat.py: Plotly based analyse tool for specific material data."""
__author__ = "Christoph Jahnke"
__copyright__ = "Copyright 2020, Universität der Bundeswehr"
__credits__ = ["Christoph Jahnke"]
__license__ = "GPL"
__version__ = "1.0.0"
__maintainer__ = "Christoph Jahnke"
__email__ = "[email protected]"
__status__ = "Testing"
import dash
import dash_html_components as html
import dash_daq as daq
import dash_core_components as dcc
import plotly.express as px
import plotly.graph_objects as go
from dash.dependencies import Input, Output
import pandas as pd
external_stylesheets = ['https://codepen.io/anon/pen/mardKv.css']
#Load the CSV Data
df = pd.read_csv('propertiesmap-v2.csv')
# Initialise the app
app = dash.Dash(__name__)
# Associating server
server = app.server
app.title = 'matdat - UNIBW'
app.config.suppress_callback_exceptions = True
#Compare Options for graphselector
all_options = {
'Tensile : Yield': ['Ductility_Percentage', 'Yield_Mpa'],
'Tensile : UTS': ['Ductility_Percentage', 'UTS_Mpa'],
}
##################################################
# INFO TABLE
##################################################
def update_info_table():
fig = go.Figure(data=[go.Table(
header=dict(values=list(['Author', 'LPBF System', 'Laser Power [W]', 'Scanning Speed [mm/s]', 'Layer Height [μm]']),
line_color='darkslategray',
fill_color='lightskyblue',
font = dict(color = 'darkslategray', size = 14),
align='left'),
cells=dict(values=list(['', '', '', '', '']),
line_color='darkslategray',
fill_color='lightskyblue',
font = dict(color = 'darkslategray', size = 14),
align='left')
)
])
fig.update_layout(
colorway=["#03f2ff", '#FF4F00', '#375CB1', '#FF7400', '#FFF400', '#FF0056'],
template='plotly_dark',
paper_bgcolor='rgba(0, 0, 0, 0)',
plot_bgcolor='rgba(0, 0, 0, 0)',
margin={'b': 15},
autosize=True,)
return fig
##################################################
# Define the app style={'textAlign': 'center', 'color': '#ffbc03'}
app.layout = html.Div(children=[
html.Div(className='div-user-controls', children=[
html.H1('Laser Powder Bed Fusion Material Properties', style={'textAlign': 'center'}),
html.Div(className='four columns', style={'padding-top': '64px'}, children=[
dcc.Dropdown(
id='graphselector',
className='div-for-dropdown',
options=[{'label': k, 'value': k} for k in all_options.keys()],
value='Tensile : Yield',
clearable=False
),
html.Div(className='div-for-dropdown', children=[
html.Span('Error', className='two-columns', style={'float': 'left'}),
daq.BooleanSwitch(
id='error_switch',
on=True,
style={'float': 'right'}
)
])
])
]),
html.Div(className='row', # Define the row element
children=[
# Define the left element
html.Div(className='eight columns div-for-charts ',
children=[
html.H4('Material Properties of L-PBF Ti6V4Al'),
html.H5('Produced via Laser Power bed Fusion'),
dcc.Graph(
id='graph_main',
style={'padding-top': '-30px'},
hoverData={'points': [{'curveNumber': 0, 'pointNumber': 10, 'pointIndex': 10, 'x': 1.9, 'y': 900}]},
config={'displayModeBar': False}
)
]
),
# Define the right element
html.Div(className='four columns div-for-charts',
children=[
html.H4('Termal History in Post-Processing'),
html.H5('Post Termal Processing Type:x'),
dcc.Graph(id='graph_temp', config={'displayModeBar': False})
]),
]),
html.Table(
className='eleven columns div-user-controls',
children=[
dcc.Graph(id='info_table',figure = update_info_table(), config={'displayModeBar': False})
]
)
])
#The Callback
@app.callback(Output('graph_main', 'figure'),
[Input('graphselector', 'value'), Input('error_switch', 'on')])
def update_main_graph(selected_dropdown_value, error_on):
dff = df
# print(errorselect)
figure = go.Figure(
data=go.Scatter(
x=dff[f'{all_options[selected_dropdown_value][0]}'],
y=dff[f'{all_options[selected_dropdown_value][1]}'],
error_y=dict(
type='data', # value of error bar given in data coordinates
array=dff[f'{all_options[selected_dropdown_value][1]}_Error'],
visible=error_on),
error_x=dict(
type='data', # value of error bar given in data coordinates
array=dff[f'{all_options[selected_dropdown_value][0]}_Error'],
visible=error_on),
mode='markers',),
layout=go.Layout(
colorway=["#ffbc03", '#FF4F00', '#375CB1', '#FF7400', '#FFF400', '#FF0056'],
template='plotly_dark',
paper_bgcolor='rgba(0, 0, 0, 0)',
plot_bgcolor='rgba(0, 0, 0, 0)',
margin={'b': 15},
# hovermode='x',
autosize=True,
))
figure.update_xaxes(title=f'{all_options[selected_dropdown_value][0]}')
figure.update_yaxes(title=f'{all_options[selected_dropdown_value][1]}')
return figure
##############################################
#FUNCTION THAT HANDLE HOVER DATA TO TEMP GRAPH
##############################################
@app.callback(
dash.dependencies.Output('graph_temp', 'figure'),
[dash.dependencies.Input('graph_main', 'hoverData'),
])
def update_y_timeseries(hoverData):
dff=df
# print(hoverData)
work = hoverData['points'][0]['pointIndex']
back = dff.iloc[work:(work+1), 1:5]
temp1 = back.iloc[0,0]
temp2 = back.iloc[0,2]
time1 = back.iloc[0,1]
time2 = back.iloc[0,3]
post_processing = (dff.iloc[work:(work+1),25:26]).iloc[0,0]
back_new = pd.DataFrame({'temp': [temp1, temp1, temp2],
'time': [0, time1, time2]},
index=['1', '2', '3'])
return create_time_series(back_new, post_processing)
##############################################
##################################
# FUNCTION FOR PLOTTING TEMP GRAPH
##################################
def create_time_series(back_new, post_processing):
#print(post_processing)
# set up plotly figure
figure = go.Figure()
# add line / trace 1 to figure
figure.add_trace(go.Scatter(
x=back_new['time'],
y=back_new['temp'],
mode='lines+markers',
connectgaps=True,
hovertemplate =
'<br><b>Time</b>: %{x} h<br>'+
'<br><b>Temp</b>: %{y} °C<br>',
showlegend=False,
))
figure.update_xaxes(title='Time[h]')
figure.update_yaxes(title='Temperature[°C]')
#text = ('Thermal history in Post-Processing <br> Post Processing type : ' + post_processing)
# print(text)
figure.update_layout(
#title=text,
colorway=["#03f2ff", '#FF4F00', '#375CB1', '#FF7400', '#FFF400', '#FF0056'],
template='plotly_dark',
paper_bgcolor='rgba(0, 0, 0, 0)',
plot_bgcolor='rgba(0, 0, 0, 0)',
margin={'b': 15},
hovermode='x',
autosize=True,)
return figure
###################################
#############
# HOVER TABLE
#############
#@app.callback(
# dash.dependencies.Output('hover_table', 'figure'),
# [dash.dependencies.Input('graph_main', 'hoverData'),
# Input('graphselector', 'value')
# ])
#def update_hovertable(hoverData, value):
# dff=df
# #print(all_options[value][0])
# work = hoverData['points'][0]['pointIndex']
# #print(dff.at[work,f'{all_options[value][0]}'])
# back = []
# val1 = dff.at[work,f'{all_options[value][0]}']
# back.append(val1)
# val2 = dff.at[work,f'{all_options[value][1]}']
# back.append(val2)
# val3 = dff.at[work,'post_processing']
# back.append(val3)
# #print(back)
#
# return create_hover_table(back, value)
#
#def create_hover_table(back, value):
# dff=df
# fig = go.Figure(data=[go.Table(
# header=dict(values=list([f'{all_options[value][0]}', f'{all_options[value][1]}', 'Post Processing']),
# line_color='darkslategray',
# fill_color='lightskyblue',
# font = dict(color = 'darkslategray', size = 14),
# align='left'),
# cells=dict(values=list([f'{(back[0])}', f'{(back[1])}', f'{(back[2])}']),
# line_color='darkslategray',
# fill_color='lightskyblue',
# font = dict(color = 'darkslategray', size = 14),
# align='left')
# )
# ])
# fig.update_layout(
# title='Information about the Datapoint:',
# colorway=["#03f2ff", '#FF4F00', '#375CB1', '#FF7400', '#FFF400', '#FF0056'],
# template='plotly_dark',
# paper_bgcolor='rgba(0, 0, 0, 0)',
# # plot_bgcolor='rgba(0, 0, 0, 0)',
# margin={'b': 15},
# height=200,
# autosize=True,)
# return fig
#############
# Run the app
if __name__ == '__main__':
app.run_server(debug=True)