How to use the pygraphviz.agraph.Node function in pygraphviz

To help you get started, we’ve selected a few pygraphviz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pygraphviz / pygraphviz / pygraphviz / agraph.py View on Github external
def successors_iter(self, n):
        """Return iterator over successor nodes of n.

        Note: modifying the graph structure while iterating over
        node successors may produce unpredictable results.  Use
        successors() as an alternative.
        """
        n = Node(self, n)
        nh = n.handle
        eh = gv.agfstout(self.handle, nh)
        while eh is not None:
            (s, t) = Edge(self, eh=eh)
            if s == n:
                yield Node(self, t)
            else:
                yield Node(self, s)
            try:
                eh = gv.agnxtout(self.handle, eh)
            except StopIteration:
                return
github philipaxer / pygraphviz / pygraphviz / agraph.py View on Github external
def to_undirected(self):
        """Return undirected copy of graph."""
        if not self.directed:
            return self.copy()
        else:
            U=AGraph(strict=self.strict)
            U.graph_attr.update(self.graph_attr)
            U.node_attr.update(self.node_attr)
            U.edge_attr.update(self.edge_attr)
            for n in self.nodes():
                U.add_node(n)
                new_n=Node(U,n)
                new_n.attr.update(n.attr)
            for e in self.edges():
                (u,v)=e
                U.add_edge(u,v)
                uv=U.get_edge(u,v)
                uv.attr.update(e.attr)
            return U
github pygraphviz / pygraphviz / pygraphviz / agraph.py View on Github external
def to_directed(self, **kwds):
        """Return directed copy of graph.

        Each undirected edge u-v is represented as two directed
        edges u->v and v->u.
        """
        if not self.directed:
            D = AGraph(strict=self.strict, directed=True)
            D.graph_attr.update(self.graph_attr)
            D.node_attr.update(self.node_attr)
            D.edge_attr.update(self.edge_attr)
            for n in self.nodes():
                D.add_node(n)
                new_n = Node(D, n)
                new_n.attr.update(n.attr)
            for e in self.edges():
                (u, v) = e
                D.add_edge(u, v)
                D.add_edge(v, u)
                uv = D.get_edge(u, v)
                vu = D.get_edge(v, u)
                uv.attr.update(e.attr)
                uv.attr.update(e.attr)
                vu.attr.update(e.attr)
            return D
        else:
            return self.copy()
github philipaxer / pygraphviz / pygraphviz / agraph.py View on Github external
def predecessors_iter(self,n):
        """Return iterator over predecessor nodes of n.

        Note: modifying the graph structure while iterating over
        node predecessors may produce unpredictable results.  Use
        predecessors() as an alternative.
        """
        n=Node(self,n)
        nh=n.handle
        eh=gv.agfstin(self.handle,nh)
        while eh is not None:
            (s,t)=Edge(self,eh=eh)
            if s==n:
                yield Node(self,t)
            else:
                yield Node(self,s)
            eh=gv.agnxtin(self.handle,eh)
        raise StopIteration
github pygraphviz / pygraphviz / pygraphviz / agraph.py View on Github external
def neighbors_iter(self, n):
        """Return iterator over the nodes attached to n.

        Note: modifying the graph structure while iterating over
        node neighbors may produce unpredictable results.  Use neighbors()
        as an alternative.
        """
        n = Node(self, n)
        nh = n.handle
        eh = gv.agfstedge(self.handle, nh)
        while eh is not None:
            (s, t) = Edge(self, eh=eh)
            if s == n:
                yield Node(self, t)
            else:
                yield Node(self, s)
            try:
                eh = gv.agnxtedge(self.handle, eh, nh)
            except StopIteration:
                return
github pygraphviz / pygraphviz / pygraphviz / agraph.py View on Github external
def predecessors_iter(self, n):
        """Return iterator over predecessor nodes of n.

        Note: modifying the graph structure while iterating over
        node predecessors may produce unpredictable results.  Use
        predecessors() as an alternative.
        """
        n = Node(self, n)
        nh = n.handle
        eh = gv.agfstin(self.handle, nh)
        while eh is not None:
            (s, t) = Edge(self, eh=eh)
            if s == n:
                yield Node(self, t)
            else:
                yield Node(self, s)
            try:
                eh = gv.agnxtin(self.handle, eh)
            except StopIteration:
                return
github philipaxer / pygraphviz / pygraphviz / agraph.py View on Github external
"""

        if nbunch is None:   # all nodes
            nh=gv.agfstnode(self.handle)
            while nh is not None:
                eh=gv.agfstout(self.handle,nh)
                while eh is not None:
                    e=Edge(self,eh=eh)
                    if keys:
                        yield (e[0],e[1],e.name)
                    else:
                        yield e
                    eh=gv.agnxtout(self.handle,eh)
                nh=gv.agnxtnode(self.handle,nh)
        elif nbunch in self: # if nbunch is a single node
            n=Node(self,nbunch)
            nh=n.handle
            eh=gv.agfstout(self.handle,nh)
            while eh is not None:
                e=Edge(self,eh=eh)
                if keys:
                    yield (e[0],e[1],e.name)
                else:
                    yield e
                eh=gv.agnxtout(self.handle,eh)
        else:                # if nbunch is a sequence of nodes
            try: bunch=[n for n in nbunch if n in self]
            except TypeError:
                raise TypeError("nbunch is not a node or a sequence of nodes.")
            for n in nbunch:
                try:
                    nh=Node(self,n).handle
github pygraphviz / pygraphviz / pygraphviz / agraph.py View on Github external
def prepare_nbunch(self, nbunch=None):
        # private function to build bunch from nbunch
        if nbunch is None:   # include all nodes via iterator
            bunch = self.nodes_iter()
        elif nbunch in self: # if nbunch is a single node
            bunch = [Node(self, nbunch)]
        else:                # if nbunch is a sequence of nodes
            try:   # capture error for nonsequence/iterator entries.
                bunch = [Node(self, n) for n in nbunch if n in self]
                # bunch=(n for n in nbunch if n in self) # need python 2.4
            except TypeError:
                raise TypeError("nbunch is not a node or a sequence of nodes.")
        return bunch
github pygraphviz / pygraphviz / pygraphviz / agraph.py View on Github external
def successors_iter(self, n):
        """Return iterator over successor nodes of n.

        Note: modifying the graph structure while iterating over
        node successors may produce unpredictable results.  Use
        successors() as an alternative.
        """
        n = Node(self, n)
        nh = n.handle
        eh = gv.agfstout(self.handle, nh)
        while eh is not None:
            (s, t) = Edge(self, eh=eh)
            if s == n:
                yield Node(self, t)
            else:
                yield Node(self, s)
            try:
                eh = gv.agnxtout(self.handle, eh)
            except StopIteration:
                return
github pygraphviz / pygraphviz / pygraphviz / agraph.py View on Github external
def predecessors_iter(self, n):
        """Return iterator over predecessor nodes of n.

        Note: modifying the graph structure while iterating over
        node predecessors may produce unpredictable results.  Use
        predecessors() as an alternative.
        """
        n = Node(self, n)
        nh = n.handle
        eh = gv.agfstin(self.handle, nh)
        while eh is not None:
            (s, t) = Edge(self, eh=eh)
            if s == n:
                yield Node(self, t)
            else:
                yield Node(self, s)
            try:
                eh = gv.agnxtin(self.handle, eh)
            except StopIteration:
                return