Skip to content

Commit

Permalink
Merge pull request #114 from Pierre-VF/feature/generate_html_str
Browse files Browse the repository at this point in the history
Support of direct HTML string from Network (for use in APIs)
  • Loading branch information
jhunpingco committed Oct 21, 2021
2 parents 1215204 + 3558dcc commit 4a045e5
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions pyvis/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,18 @@ def save_graph(self, name):
check_html(name)
self.write_html(name)

def write_html(self, name, notebook=False):
def generate_html(self, notebook=False):
"""
This method gets the data structures supporting the nodes, edges,
and options and updates the template to write the HTML holding
This method generates HTML from the data structures supporting the nodes, edges,
and options and updates the template to generate the HTML holding
the visualization.
:type name_html: str
:type notebook: bool
Returns
:type out: str
"""
check_html(name)

# here, check if an href is present in the hover data
use_link_template = False
for n in self.nodes:
Expand Down Expand Up @@ -444,19 +447,32 @@ def write_html(self, name, notebook=False):
else:
physics_enabled = self.options.physics.enabled

self.html = template.render(height=height,
width=width,
nodes=nodes,
edges=edges,
heading=heading,
options=options,
physics_enabled=physics_enabled,
use_DOT=self.use_DOT,
dot_lang=self.dot_lang,
widget=self.widget,
bgcolor=self.bgcolor,
conf=self.conf,
tooltip_link=use_link_template)
out = template.render(height=height,
width=width,
nodes=nodes,
edges=edges,
heading=heading,
options=options,
physics_enabled=physics_enabled,
use_DOT=self.use_DOT,
dot_lang=self.dot_lang,
widget=self.widget,
bgcolor=self.bgcolor,
conf=self.conf,
tooltip_link=use_link_template)

return out

def write_html(self, name, notebook=False):
"""
This method gets the data structures supporting the nodes, edges,
and options and updates the template to write the HTML holding
the visualization.
:type name_html: str
"""
check_html(name)
self.html = self.generate_html(notebook=notebook)

with open(name, "w+") as out:
out.write(self.html)
Expand Down

0 comments on commit 4a045e5

Please sign in to comment.