Skip to content

Commit e119009

Browse files
author
Yi-Ting Lee
committed
generate legend divs programmatically
1 parent c1be765 commit e119009

File tree

1 file changed

+25
-31
lines changed

1 file changed

+25
-31
lines changed

src/sagemaker/lineage/query.py

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,25 @@ def _node_color(self, entity):
314314
"""Return node color by background-color specified in graph styles."""
315315
return self.graph_styles[entity]["style"]["background-color"]
316316

317+
def _get_legend_line(self, component_name):
318+
"""Generate lengend div line for each graph component in graph_styles."""
319+
if self.graph_styles[component_name]["isShape"] == "False":
320+
return '<div><div style="background-color: {color}; width: 1.6vw; height: 1.6vw;\
321+
display: inline-block; font-size: 1.5vw; vertical-align: -0.2em;"></div>\
322+
<div style="width: 0.3vw; height: 1.5vw; display: inline-block;"></div>\
323+
<div style="display: inline-block; font-size: 1.5vw;">{name}</div></div>'.format(
324+
color=self.graph_styles[component_name]["style"]["background-color"],
325+
name=self.graph_styles[component_name]["name"],
326+
)
327+
else:
328+
return '<div style="background-color: #ffffff; width: 1.6vw; height: 1.6vw;\
329+
display: inline-block; font-size: 0.9vw; vertical-align: -0.2em;">{shape}</div>\
330+
<div style="width: 0.3vw; height: 1.5vw; display: inline-block;"></div>\
331+
<div style="display: inline-block; font-size: 1.5vw;">{name}</div></div>'.format(
332+
shape=self.graph_styles[component_name]["style"]["shape"],
333+
name=self.graph_styles[component_name]["name"],
334+
)
335+
317336
def _add_legend(self, path):
318337
"""Embed legend to html file generated by pyvis."""
319338
f = open(path, "r")
@@ -322,38 +341,13 @@ def _add_legend(self, path):
322341
legend = """
323342
<div style="display: inline-block; font-size: 1vw; font-family: verdana;
324343
vertical-align: top; padding: 1vw;">
325-
<div>
326-
<div style="background-color: rgb(246, 207, 97); width: 1.6vw; height: 1.6vw;
327-
display: inline-block; font-size: 1.5vw; vertical-align: -0.2em;"></div>
328-
<div style="width: 0.3vw; height: 1.5vw; display: inline-block;"></div>
329-
<div style="display: inline-block; font-size: 1.5vw;">Trial Component</div>
330-
</div>
331-
<div>
332-
<div style="background-color: rgb(255, 153, 0); width: 1.6vw; height: 1.6vw;
333-
display: inline-block; font-size: 1.5vw; vertical-align: -0.2em;"></div>
334-
<div style="width: 0.3vw; height: 1.5vw; display: inline-block;"></div>
335-
<div style="display: inline-block; font-size: 1.5vw;">Context</div>
336-
</div>
337-
<div>
338-
<div style="background-color: rgb(136, 195, 150); width: 1.6vw; height: 1.6vw;
339-
display: inline-block; font-size: 1.5vw; vertical-align: -0.2em;"></div>
340-
<div style="width: 0.3vw; height: 1.5vw; display: inline-block;"></div>
341-
<div style="display: inline-block; font-size: 1.5vw;">Action</div>
342-
</div>
343-
<div>
344-
<div style="background-color: rgb(20, 110, 180); width: 1.6vw; height: 1.6vw;
345-
display: inline-block; font-size: 1.5vw; vertical-align: -0.2em;"></div>
346-
<div style="width: 0.3vw; height: 1.5vw; display: inline-block;"></div>
347-
<div style="display: inline-block; font-size: 1.5vw;">Artifact</div>
348-
</div>
349-
<div>
350-
<div style="background-color: rgb(255, 255, 255); width: 1.6vw; height: 1.6vw;
351-
display: inline-block; font-size: 0.9vw;">star</div>
352-
<div style="width: 0.3vw; height: 1.5vw; display: inline-block;"></div>
353-
<div style="display: inline-block; font-size: 1.5vw;">StartArn</div>
354-
</div>
355-
</div>
356344
"""
345+
# iterate through graph styles to get legend
346+
for component in self.graph_styles.keys():
347+
legend += self._get_legend_line(component_name=component)
348+
349+
legend += "</div>"
350+
357351
legend_div = self.BeautifulSoup(legend, "html.parser")
358352

359353
content.div.insert_after(legend_div)

0 commit comments

Comments
 (0)