@@ -262,6 +262,8 @@ def __init__(self, graph_styles):
262
262
(
263
263
self .Network ,
264
264
self .Options ,
265
+ self .IFrame ,
266
+ self .BeautifulSoup
265
267
) = self ._import_visual_modules ()
266
268
267
269
self .graph_styles = graph_styles
@@ -302,13 +304,22 @@ def _import_visual_modules(self):
302
304
get_module ("pyvis" )
303
305
from pyvis .network import Network
304
306
from pyvis .options import Options
307
+ from IPython .display import IFrame
305
308
306
- return Network , Options
309
+ get_module ("bs4" )
310
+ from bs4 import BeautifulSoup
311
+
312
+ return Network , Options , IFrame , BeautifulSoup
307
313
308
314
def _node_color (self , entity ):
309
315
"""Return node color by background-color specified in graph styles."""
310
316
return self .graph_styles [entity ]["style" ]["background-color" ]
311
317
318
+ def _add_legend (self , path ):
319
+ f = open (path , "r+" )
320
+ soup = self .BeautifulSoup (f , 'html.parser' )
321
+ print (soup .prettify ())
322
+
312
323
def render (self , elements , path = "pyvisExample.html" ):
313
324
"""Render graph for lineage query result.
314
325
@@ -345,7 +356,10 @@ def render(self, elements, path="pyvisExample.html"):
345
356
for src , dest , asso_type in elements ["edges" ]:
346
357
net .add_edge (src , dest , title = asso_type , width = 2 )
347
358
348
- return net .show (path )
359
+ net .write_html (path )
360
+ self ._add_legend (path )
361
+
362
+ return self .IFrame (path , width = "100%" , height = "500px" )
349
363
350
364
351
365
class LineageQueryResult (object ):
0 commit comments