Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(attribute values must be strings)
>>> G.add_node(2,color='red')
See http://www.graphviz.org/doc/info/attrs.html
for a list of attributes.
Anonymous Graphviz nodes are currently not implemented.
"""
if not self._is_string_like(n):
n=str(n)
try:
nh=gv.agnode(self.handle,n,_Action.find)
except KeyError:
nh=gv.agnode(self.handle,n,_Action.create)
node=Node(self,nh=nh)
node.attr.update(**attr)
Attributes can be added to nodes on creation
(attribute values must be strings)
>>> G.add_node(2,color='red')
See http://www.graphviz.org/doc/info/attrs.html
for a list of attributes.
Anonymous Graphviz nodes are currently not implemented.
"""
if not self._is_string_like(n):
n=str(n)
try:
nh=gv.agnode(self.handle,n,_Action.find)
except KeyError:
nh=gv.agnode(self.handle,n,_Action.create)
node=Node(self,nh=nh)
node.attr.update(**attr)
def get_handle(self):
"""Return pointer to graphviz node object."""
return gv.agnode(self.ghandle,self.encode(self.encoding),_Action.find)
(attribute values must be strings)
>>> G.add_node(2,color='red')
See http://www.graphviz.org/doc/info/attrs.html
for a list of attributes.
Anonymous Graphviz nodes are currently not implemented.
"""
if not is_string_like(n):
n = str(n)
n = n.encode(self.encoding)
try:
nh = gv.agnode(self.handle, n, _Action.find)
except KeyError:
nh = gv.agnode(self.handle, n, _Action.create)
node = Node(self, nh=nh)
node.attr.update(**attr)
def remove_node(self,n):
"""Remove the single node n.
Attempting to remove a node that isn't in the graph will produce
an error.
>>> G=AGraph()
>>> G.add_node('a')
>>> G.remove_node('a')
"""
if not self._is_string_like(n):
n=str(n)
try:
nh=gv.agnode(self.handle,n,_Action.find)
gv.agdelnode(self.handle,nh)
except KeyError:
raise KeyError("Node %s not in graph."%n.decode(self.encoding))
def __new__(self, graph, name=None, nh=None):
if nh is not None:
n = super(Node, self).__new__(self, gv.agnameof(nh), graph.encoding)
else:
n = super(Node, self).__new__(self, name)
try:
nh = gv.agnode(graph.handle, n.encode(graph.encoding), _Action.find)
except KeyError:
raise KeyError("Node %s not in graph." % n)
n.ghandle = graph.handle
n.attr = ItemAttribute(nh, 1)
n.handle = nh
n.encoding = graph.encoding
return n
def remove_node(self, n):
"""Remove the single node n.
Attempting to remove a node that isn't in the graph will produce
an error.
>>> G=AGraph()
>>> G.add_node('a')
>>> G.remove_node('a')
"""
if not is_string_like(n):
n = str(n)
n = n.encode(self.encoding)
try:
nh = gv.agnode(self.handle, n, _Action.find)
gv.agdelnode(self.handle, nh)
except KeyError:
raise KeyError("Node %s not in graph." % n.decode(self.encoding))