Skip to content

Commit

Permalink
Merge pull request #67 from WilsonHChung/master
Browse files Browse the repository at this point in the history
Heading on top of graph outputs
  • Loading branch information
Giancarlo Perrone committed Aug 3, 2020
2 parents faa4b58 + f111d90 commit 4df52be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pyvis/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def __init__(self,
notebook=False,
bgcolor="#ffffff",
font_color=False,
layout=None):
layout=None,
heading=None):
"""
:param height: The height of the canvas
:param width: The width of the canvas
Expand All @@ -53,6 +54,7 @@ def __init__(self,
self.edges = []
self.height = height
self.width = width
self.heading = heading
self.html = ""
self.shape = "dot"
self.font_color = font_color
Expand Down Expand Up @@ -81,7 +83,8 @@ def __str__(self):
"Nodes": self.node_ids,
"Edges": self.edges,
"Height": self.height,
"Width": self.width
"Width": self.width,
"Heading": self.heading
},
indent=4
)
Expand Down Expand Up @@ -380,13 +383,13 @@ def get_network_data(self):
Usage:
>>> nodes, edges, height, width, options = net.get_network_data()
>>> nodes, edges, heading, height, width, options = net.get_network_data()
"""
if isinstance(self.options, dict):
return (self.nodes, self.edges, self.height,
return (self.nodes, self.edges, self.heading, self.height,
self.width, json.dumps(self.options))
else:
return (self.nodes, self.edges, self.height,
return (self.nodes, self.edges, self.heading, self.height,
self.width, self.options.to_json())

def save_graph(self, name):
Expand Down Expand Up @@ -428,7 +431,7 @@ def write_html(self, name, notebook=False):
else:
template = self.template

nodes, edges, height, width, options = self.get_network_data()
nodes, edges, heading, height, width, options = self.get_network_data()

# check if physics is enabled
if isinstance(self.options, dict):
Expand All @@ -443,6 +446,7 @@ def write_html(self, name, notebook=False):
width=width,
nodes=nodes,
edges=edges,
heading=heading,
options=options,
physics_enabled=physics_enabled,
use_DOT=self.use_DOT,
Expand Down
3 changes: 3 additions & 0 deletions pyvis/templates/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.16.1/vis.css" type="text/css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.16.1/vis-network.min.js"> </script>
<center>
<h1>{{heading}}</h1>
</center>

<!-- <link rel="stylesheet" href="../node_modules/vis/dist/vis.min.css" type="text/css" />
<script type="text/javascript" src="../node_modules/vis/dist/vis.js"> </script>-->
Expand Down

0 comments on commit 4df52be

Please sign in to comment.