Skip to content

Commit a9e5114

Browse files
author
Yi-Ting Lee
committed
split generate html file & display
1 parent 1a3b5f3 commit a9e5114

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/sagemaker/lineage/query.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ def __init__(self, graph_styles):
262262
(
263263
self.Network,
264264
self.Options,
265+
self.IFrame,
266+
self.BeautifulSoup
265267
) = self._import_visual_modules()
266268

267269
self.graph_styles = graph_styles
@@ -302,13 +304,22 @@ def _import_visual_modules(self):
302304
get_module("pyvis")
303305
from pyvis.network import Network
304306
from pyvis.options import Options
307+
from IPython.display import IFrame
305308

306-
return Network, Options
309+
get_module("bs4")
310+
from bs4 import BeautifulSoup
311+
312+
return Network, Options, IFrame, BeautifulSoup
307313

308314
def _node_color(self, entity):
309315
"""Return node color by background-color specified in graph styles."""
310316
return self.graph_styles[entity]["style"]["background-color"]
311317

318+
def _add_legend(self, path):
319+
f = open(path, "r+")
320+
soup = self.BeautifulSoup(f, 'html.parser')
321+
print(soup.prettify())
322+
312323
def render(self, elements, path="pyvisExample.html"):
313324
"""Render graph for lineage query result.
314325
@@ -345,7 +356,10 @@ def render(self, elements, path="pyvisExample.html"):
345356
for src, dest, asso_type in elements["edges"]:
346357
net.add_edge(src, dest, title=asso_type, width=2)
347358

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")
349363

350364

351365
class LineageQueryResult(object):

0 commit comments

Comments
 (0)