71 lines
1.6 KiB
Python
71 lines
1.6 KiB
Python
|
|
|
|
from pyvis.network import Network
|
|
|
|
from .linkmap import LinkMap
|
|
|
|
|
|
def pyvis_graph_from_linkmap(linkmap:LinkMap, heading:str=None) -> Network:
|
|
|
|
pyvis_net = Network(bgcolor="#222222", font_color="#fafafa", width="100%", height="95%", directed=True)
|
|
|
|
pyvis_net.add_nodes(linkmap.links, size=[8]*len(linkmap.links))
|
|
pyvis_net.add_edges(linkmap.link_connections)
|
|
|
|
if heading != None:
|
|
pyvis_net.heading = heading + """
|
|
<style>
|
|
body {
|
|
background-color: #222222;
|
|
}
|
|
h1 {
|
|
font-size: 1.15rem;
|
|
margin: .5rem;
|
|
color: #fafafa;
|
|
font-family: sans-serif;
|
|
}
|
|
#mynetwork {
|
|
border: none !important;
|
|
}
|
|
</style>
|
|
"""
|
|
|
|
pyvis_options = """
|
|
var options = {
|
|
"nodes": {
|
|
"font": {
|
|
"size": 12
|
|
}
|
|
},
|
|
"edges": {
|
|
"arrows": {
|
|
"to": {
|
|
"enabled": true,
|
|
"scaleFactor": 0.3
|
|
}
|
|
},
|
|
"color": {
|
|
"inherit": true
|
|
},
|
|
"smooth": false
|
|
},
|
|
"interaction": {
|
|
"hover": false
|
|
},
|
|
"physics": {
|
|
"barnesHut": {
|
|
"centralGravity": 0,
|
|
"springLength": 200,
|
|
"springConstant": 0.01,
|
|
"avoidOverlap": 0
|
|
},
|
|
"minVelocity": 0.75
|
|
}
|
|
}
|
|
"""
|
|
|
|
# pyvis_net.show_buttons()
|
|
pyvis_net.set_options(pyvis_options)
|
|
|
|
return pyvis_net
|
|
|