@@ -214,17 +214,7 @@ def __init__(self, graph_styles):
214
214
215
215
self .graph_styles = graph_styles
216
216
217
- def _import_visual_modules (self ):
218
- """Import modules needed for visualization."""
219
- get_module ("pyvis" )
220
- from pyvis .network import Network
221
- from pyvis .options import Options
222
-
223
- return Network , Options
224
-
225
- def _get_options (self ):
226
- """Get pyvis graph options."""
227
- options = """
217
+ self ._options = """
228
218
var options = {
229
219
"configure":{
230
220
"enabled": false
@@ -253,28 +243,36 @@ def _get_options(self):
253
243
}
254
244
}
255
245
"""
256
- return options
257
246
258
- def _node_color (self , n ):
247
+ def _import_visual_modules (self ):
248
+ """Import modules needed for visualization."""
249
+ get_module ("pyvis" )
250
+ from pyvis .network import Network
251
+ from pyvis .options import Options
252
+
253
+ return Network , Options
254
+
255
+ def _node_color (self , entity ):
259
256
"""Return node color by background-color specified in graph styles."""
260
- return self .graph_styles [n [ 2 ] ]["style" ]["background-color" ]
257
+ return self .graph_styles [entity ]["style" ]["background-color" ]
261
258
262
259
def render (self , elements , path = "pyvisExample.html" ):
263
260
"""Render graph for lineage query result."""
264
261
net = self .Network (height = "500px" , width = "100%" , notebook = True , directed = True )
265
- options = self ._get_options ()
266
- net .set_options (options )
262
+ net .set_options (self ._options )
267
263
268
264
# add nodes to graph
269
- for n in elements ["nodes" ]:
270
- if n [3 ]: # startarn
271
- net .add_node (n [0 ], label = n [1 ], title = n [2 ], color = self ._node_color (n ), shape = "star" )
265
+ for arn , source , entity , is_start_arn in elements ["nodes" ]:
266
+ if is_start_arn : # startarn
267
+ net .add_node (
268
+ arn , label = source , title = entity , color = self ._node_color (entity ), shape = "star"
269
+ )
272
270
else :
273
- net .add_node (n [ 0 ] , label = n [ 1 ] , title = n [ 2 ] , color = self ._node_color (n ))
271
+ net .add_node (arn , label = source , title = entity , color = self ._node_color (entity ))
274
272
275
273
# add edges to graph
276
- for e in elements ["edges" ]:
277
- net .add_edge (e [ 0 ], e [ 1 ] , title = e [ 2 ] )
274
+ for src , dest , asso_type in elements ["edges" ]:
275
+ net .add_edge (src , dest , title = asso_type )
278
276
279
277
return net .show (path )
280
278
0 commit comments