Skip to content

Commit

Permalink
cleanup and fixed link redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
jhunpingco committed Mar 5, 2021
2 parents 2906996 + 5fa5acd commit 523d541
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyvis/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.8.2' # bump version
__version__ = '0.1.9' # bump version
12 changes: 12 additions & 0 deletions pyvis/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def __init__(self,
self.options = Options(layout)
self.widget = False
self.node_ids = []
self.node_map = {}
self.template = None
self.conf = False
self.path = os.path.dirname(__file__) + "/templates/template.html"
Expand Down Expand Up @@ -212,6 +213,7 @@ def add_node(self, n_id, label=None, shape="dot", **options):
n = Node(n_id, shape, label=node_label, font_color=self.font_color, **options)
self.nodes.append(n.options)
self.node_ids.append(n_id)
self.node_map[n_id] = n.options

def add_nodes(self, nodes, **kwargs):
"""
Expand Down Expand Up @@ -628,6 +630,16 @@ def get_nodes(self):
"""
return self.node_ids

def get_node(self, n_id):
"""
Lookup node by ID and return it.
:param n_id: The ID given to the node.
:returns: dict containing node properties
"""
return self.node_map[n_id]

def get_edges(self):
"""
This method returns an iterable list of edge objects
Expand Down
9 changes: 9 additions & 0 deletions pyvis/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ For the direct Python translation of these attributes, reference the
work as expected, or at all. Pyvis can translate into the JavaScript
elements for VisJS_ but after that it's up to VisJS_!

Indexing a Node
---------------
Use the :meth:`get_node` method to index a node by its ID:

>>> net.add_nodes(["a", "b", "c"])
>>> net.get_node("c")
>>> {'id': 'c', 'label': 'c', 'shape': 'dot'}


Adding list of nodes with properties
------------------------------------
When using the :meth:`network.Network.add_nodes` method optional keyword arguments can be
Expand Down

0 comments on commit 523d541

Please sign in to comment.