1+ import math
2+
13import dash_cytoscape
24import dash
35from dash .dependencies import Input , Output
79try :
810 from Bio import Phylo
911except 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):
121124nodes , edges = generate_elements (tree )
122125elements = nodes + edges
123126
124- layout = {
125- 'name' : 'breadthfirst' ,
126- 'directed' : True
127- }
127+ layout = {'name' : 'preset' }
128128
129129stylesheet = [
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
163164app = dash .Dash (__name__ )
164165
165166app .scripts .config .serve_locally = True
166167app .css .config .serve_locally = True
167168
168-
169169app .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+
183204if __name__ == '__main__' :
184205 app .run_server (debug = True )
0 commit comments