@@ -204,7 +204,7 @@ def _artifact_to_lineage_object(self):
204
204
class DashVisualizer (object ):
205
205
"""Create object used for visualizing graph using Dash library."""
206
206
207
- def __init__ (self ):
207
+ def __init__ (self , graph_styles ):
208
208
"""Init for DashVisualizer."""
209
209
# import visualization packages
210
210
(
@@ -215,12 +215,7 @@ def __init__(self):
215
215
self .Output ,
216
216
) = self ._import_visual_modules ()
217
217
218
- self .entity_color = {
219
- "TrialComponent" : "#f6cf61" ,
220
- "Context" : "#ff9900" ,
221
- "Action" : "#88c396" ,
222
- "Artifact" : "#146eb4" ,
223
- }
218
+ self .graph_styles = graph_styles
224
219
225
220
def _import_visual_modules (self ):
226
221
"""Import modules needed for visualization."""
@@ -254,12 +249,19 @@ def _import_visual_modules(self):
254
249
255
250
return cyto , JupyterDash , html , Input , Output
256
251
257
- def _create_legend_component (self , text , color , colorText = "" ):
252
+ def _create_legend_component (self , style ):
258
253
"""Create legend component div."""
254
+ text = style ["name" ]
255
+ symbol = ""
256
+ color = "#ffffff"
257
+ if style ["isShape" ] == "False" :
258
+ color = style ["style" ]["background-color" ]
259
+ else :
260
+ symbol = style ["symbol" ]
259
261
return self .html .Div (
260
262
[
261
263
self .html .Div (
262
- colorText ,
264
+ symbol ,
263
265
style = {
264
266
"background-color" : color ,
265
267
"width" : "1.5vw" ,
@@ -282,9 +284,9 @@ def _create_legend_component(self, text, color, colorText=""):
282
284
]
283
285
)
284
286
285
- def _create_entity_selector (self , entity_name , color ):
287
+ def _create_entity_selector (self , entity_name , style ):
286
288
"""Create selector for each lineage entity."""
287
- return {"selector" : "." + entity_name , "style" : { "background-color" : color } }
289
+ return {"selector" : "." + entity_name , "style" : style [ "style" ] }
288
290
289
291
def _get_app (self , elements ):
290
292
"""Create JupyterDash app for interactivity on Jupyter notebook."""
@@ -337,10 +339,9 @@ def _get_app(self, elements):
337
339
"font-family" : "verdana" ,
338
340
},
339
341
},
340
- {"selector" : ".startarn" , "style" : {"shape" : "star" }},
341
342
{"selector" : ".select" , "style" : {"border-opacity" : "0.7" }},
342
343
]
343
- + [self ._create_entity_selector (k , v ) for k , v in self .entity_color .items ()],
344
+ + [self ._create_entity_selector (k , v ) for k , v in self .graph_styles .items ()],
344
345
responsive = True ,
345
346
),
346
347
self .html .Div (
@@ -354,8 +355,7 @@ def _get_app(self, elements):
354
355
),
355
356
# legend section
356
357
self .html .Div (
357
- [self ._create_legend_component (k , v ) for k , v in self .entity_color .items ()]
358
- + [self ._create_legend_component ("StartArn" , "#ffffff" , "★" )],
358
+ [self ._create_legend_component (v ) for k , v in self .graph_styles .items ()],
359
359
style = {
360
360
"display" : "inline-block" ,
361
361
"font-size" : "1vw" ,
@@ -492,8 +492,38 @@ def visualize(self):
492
492
"""Visualize lineage query result."""
493
493
elements = self ._get_visualization_elements ()
494
494
495
+ lineage_graph = {
496
+ # nodes can have shape / color
497
+ "TrialComponent" : {
498
+ "name" : "Trial Component" ,
499
+ "style" : {"background-color" : "#f6cf61" },
500
+ "isShape" : "False" ,
501
+ },
502
+ "Context" : {
503
+ "name" : "Context" ,
504
+ "style" : {"background-color" : "#ff9900" },
505
+ "isShape" : "False" ,
506
+ },
507
+ "Action" : {
508
+ "name" : "Action" ,
509
+ "style" : {"background-color" : "#88c396" },
510
+ "isShape" : "False" ,
511
+ },
512
+ "Artifact" : {
513
+ "name" : "Artifact" ,
514
+ "style" : {"background-color" : "#146eb4" },
515
+ "isShape" : "False" ,
516
+ },
517
+ "StartArn" : {
518
+ "name" : "StartArn" ,
519
+ "style" : {"shape" : "star" },
520
+ "isShape" : "True" ,
521
+ "symbol" : "★" , # shape symbol for legend
522
+ },
523
+ }
524
+
495
525
# initialize DashVisualizer instance to render graph & interactive components
496
- dash_vis = DashVisualizer ()
526
+ dash_vis = DashVisualizer (lineage_graph )
497
527
498
528
dash_server = dash_vis .render (elements = elements , mode = "inline" )
499
529
0 commit comments