@@ -267,7 +267,9 @@ def _import_visual_modules(self):
267
267
268
268
from dash import html
269
269
270
- return cyto , JupyterDash , html
270
+ from dash .dependencies import Input , Output
271
+
272
+ return cyto , JupyterDash , html , Input , Output
271
273
272
274
def _get_verts (self ):
273
275
"""Convert vertices to tuple format for visualizer."""
@@ -287,11 +289,12 @@ def _get_edges(self):
287
289
# get edge info in the form of (source, target, label)
288
290
for edge in self .edges :
289
291
edges .append ((edge .source_arn , edge .destination_arn , edge .association_type ))
292
+ edges .append ((self .edges [1 ].destination_arn , self .edges [1 ].source_arn , self .edges [1 ].association_type ))
290
293
return edges
291
294
292
295
def visualize (self ):
293
296
"""Visualize lineage query result."""
294
- cyto , JupyterDash , html = self ._import_visual_modules ()
297
+ cyto , JupyterDash , html , Input , Output = self ._import_visual_modules ()
295
298
296
299
cyto .load_extra_layouts () # load "klay" layout (hierarchical layout) from extra layouts
297
300
app = JupyterDash (__name__ )
@@ -314,7 +317,7 @@ def visualize(self):
314
317
app .layout = html .Div (
315
318
[
316
319
cyto .Cytoscape (
317
- id = "cytoscape-layout-1 " ,
320
+ id = "cytoscape-graph " ,
318
321
elements = elements ,
319
322
style = {"width" : "100%" , "height" : "350px" },
320
323
layout = {"name" : "klay" },
@@ -326,6 +329,9 @@ def visualize(self):
326
329
"font-size" : "3.5vw" ,
327
330
"height" : "10vw" ,
328
331
"width" : "10vw" ,
332
+ "border-width" : "0.8" ,
333
+ "border-opacity" : "0" ,
334
+ "border-color" : "#232f3e"
329
335
},
330
336
},
331
337
{
@@ -334,11 +340,13 @@ def visualize(self):
334
340
"label" : "data(label)" ,
335
341
"color" : "gray" ,
336
342
"text-halign" : "left" ,
337
- "text-margin-y" : "3px" ,
338
- "text-margin-x" : "-2px" ,
339
- "font-size" : "3%" ,
340
- "width" : "1%" ,
341
- "curve-style" : "taxi" ,
343
+ "text-margin-y" : "2.5" ,
344
+ "font-size" : "3" ,
345
+ "width" : "1" ,
346
+ "curve-style" : "bezier" ,
347
+ "control-point-step-size" : "15" ,
348
+ # "taxi-direction": "rightward",
349
+ # "taxi-turn": "50%",
342
350
"target-arrow-color" : "gray" ,
343
351
"target-arrow-shape" : "triangle" ,
344
352
"line-color" : "gray" ,
@@ -350,12 +358,25 @@ def visualize(self):
350
358
{"selector" : ".TrialComponent" , "style" : {"background-color" : "#f6cf61" }},
351
359
{"selector" : ".Action" , "style" : {"background-color" : "#88c396" }},
352
360
{"selector" : ".startarn" , "style" : {"shape" : "star" }},
361
+ {"selector" : ".select" , "style" : { "border-opacity" : "0.7" }},
353
362
],
354
363
responsive = True ,
355
364
)
356
365
]
357
366
)
358
367
368
+ @app .callback (Output ("cytoscape-graph" , "elements" ),
369
+ Input ("cytoscape-graph" , "tapNodeData" ))
370
+ def selectNode (data ):
371
+ for n in nodes :
372
+ if data != None and n ["data" ]["id" ] == data ["id" ]:
373
+ n ["classes" ] += " select"
374
+ else :
375
+ n ["classes" ] = n ["classes" ].replace ("select" , "" )
376
+
377
+ elements = nodes + edges
378
+ return elements
379
+
359
380
return app .run_server (mode = "inline" )
360
381
361
382
0 commit comments