Skip to content

Commit ae460fa

Browse files
author
Xing Han Lu
committed
Update styling and callbacks
Add callbacks on hover, update stylesheet to match new algorithm
1 parent 9f93143 commit ae460fa

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

demos/usage-phylogeny.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import math
2+
13
import dash_cytoscape
24
import dash
35
from dash.dependencies import Input, Output
@@ -7,7 +9,8 @@
79
try:
810
from Bio import Phylo
911
except ModuleNotFoundError as e:
10-
print(e, "Please make sure you have biopython installed correctly before running this example.")
12+
print(e,
13+
"Please make sure biopython is installed correctly before running this example.")
1114
exit(1)
1215

1316

@@ -121,10 +124,7 @@ def add_to_elements(clade, clade_id):
121124
nodes, edges = generate_elements(tree)
122125
elements = nodes + edges
123126

124-
layout = {
125-
'name': 'breadthfirst',
126-
'directed': True
127-
}
127+
layout = {'name': 'preset'}
128128

129129
stylesheet = [
130130
{
@@ -136,36 +136,36 @@ def add_to_elements(clade, clade_id):
136136
"text-valign": "top",
137137
}
138138
},
139+
{
140+
'selector': '.support',
141+
'style': {'background-opacity': 0}
142+
},
139143
{
140144
'selector': 'edge',
141145
'style': {
142-
"source-endpoint": "outside-to-node",
146+
"source-endpoint": "inside-to-node",
147+
"target-endpoint": "inside-to-node",
143148
}
144149
},
145150
{
146151
'selector': '.terminal',
147152
'style': {
148153
'label': 'data(name)',
149-
"shape": "roundrectangle",
150-
"width": 115,
151-
"height": 25,
154+
'width': 10,
155+
'height': 10,
152156
"text-valign": "center",
153-
'background-color': 'white',
154-
"border-width": 1.5,
155-
"border-style": "solid",
156-
"border-opacity": 1,
157+
"text-halign": "right",
158+
'background-color': '#222222'
157159
}
158160
}
159161
]
160162

161-
162163
# Start the app
163164
app = dash.Dash(__name__)
164165

165166
app.scripts.config.serve_locally = True
166167
app.css.config.serve_locally = True
167168

168-
169169
app.layout = html.Div([
170170
dash_cytoscape.Cytoscape(
171171
id='cytoscape',
@@ -180,5 +180,26 @@ def add_to_elements(clade, clade_id):
180180
])
181181

182182

183+
@app.callback(Output('cytoscape', 'stylesheet'),
184+
[Input('cytoscape', 'mouseoverEdgeData')])
185+
def color_children(edgeData):
186+
if not edgeData:
187+
return stylesheet
188+
189+
if 's' in edgeData['source']:
190+
val = edgeData['source'].split('s')[0]
191+
else:
192+
val = edgeData['source']
193+
194+
children_style = [{
195+
'selector': f'edge[source *= "{val}"]',
196+
'style': {
197+
'line-color': 'blue'
198+
}
199+
}]
200+
201+
return stylesheet + children_style
202+
203+
183204
if __name__ == '__main__':
184205
app.run_server(debug=True)

0 commit comments

Comments
 (0)