@@ -314,6 +314,25 @@ def _node_color(self, entity):
314
314
"""Return node color by background-color specified in graph styles."""
315
315
return self .graph_styles [entity ]["style" ]["background-color" ]
316
316
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
+
317
336
def _add_legend (self , path ):
318
337
"""Embed legend to html file generated by pyvis."""
319
338
f = open (path , "r" )
@@ -322,38 +341,13 @@ def _add_legend(self, path):
322
341
legend = """
323
342
<div style="display: inline-block; font-size: 1vw; font-family: verdana;
324
343
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>
356
344
"""
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
+
357
351
legend_div = self .BeautifulSoup (legend , "html.parser" )
358
352
359
353
content .div .insert_after (legend_div )
0 commit comments