Commit 49d83026 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Include support for vertex and edge ordering in graph_draw()

parent 3e5e39e5
...@@ -63,13 +63,14 @@ except ImportError: ...@@ -63,13 +63,14 @@ except ImportError:
__all__ = ["graph_draw", "arf_layout", "random_layout"] __all__ = ["graph_draw", "arf_layout", "random_layout"]
def graph_draw(g, pos=None, size=(15, 15), pin=False, layout="neato", def graph_draw(g, pos=None, size=(15, 15), pin=False, layout= "neato",
maxiter=None, ratio="fill", overlap="prism", sep=None, maxiter=None, ratio= "fill", overlap= "prism", sep=None,
splines=False, vsize=0.1, penwidth=1.0, elen=None, gprops={}, splines=False, vsize=0.1, penwidth=1.0, elen=None, gprops={},
vprops={}, eprops={}, vcolor=None, ecolor=None, vprops={}, eprops={}, vcolor=None, ecolor=None,
vcmap=matplotlib.cm.jet, vnorm=True, ecmap=matplotlib.cm.jet, vcmap=matplotlib.cm.jet, vnorm=True, ecmap=matplotlib.cm.jet,
enorm=True, output="", output_format="auto", returngv=False, enorm=True, vorder=None, eorder=None, output= "",
fork=False, return_bitmap=False, seed=0): output_format= "auto", returngv=False, fork=False,
return_bitmap=False, seed=0):
r"""Draw a graph using graphviz. r"""Draw a graph using graphviz.
Parameters Parameters
...@@ -183,6 +184,12 @@ def graph_draw(g, pos=None, size=(15, 15), pin=False, layout="neato", ...@@ -183,6 +184,12 @@ def graph_draw(g, pos=None, size=(15, 15), pin=False, layout="neato",
Edge color map. Edge color map.
enorm : bool (default: True) enorm : bool (default: True)
Normalize edge color values to the [0,1] range. Normalize edge color values to the [0,1] range.
vorder : PropertyMap (default: None)
Scalar vertex property map which specifies the order with which vertices
are drawn.
eorder : PropertyMap (default: None)
Scalar edge property map which specifies the order with which edges
are drawn.
output : string (default: "") output : string (default: "")
Output file name. Output file name.
output_format : string (default: "auto") output_format : string (default: "auto")
...@@ -349,7 +356,11 @@ def graph_draw(g, pos=None, size=(15, 15), pin=False, layout="neato", ...@@ -349,7 +356,11 @@ def graph_draw(g, pos=None, size=(15, 15), pin=False, layout="neato",
nodes = {} nodes = {}
# add nodes # add nodes
for v in g.vertices(): if vorder != None:
vertices = sorted(g.vertices(), lambda a, b: cmp(vorder[a], vorder[b]))
else:
vertices = g.vertices()
for v in vertices:
n = gv.node(gvg, str(g.vertex_index[v])) n = gv.node(gvg, str(g.vertex_index[v]))
if type(vsize) == PropertyMap: if type(vsize) == PropertyMap:
...@@ -385,7 +396,12 @@ def graph_draw(g, pos=None, size=(15, 15), pin=False, layout="neato", ...@@ -385,7 +396,12 @@ def graph_draw(g, pos=None, size=(15, 15), pin=False, layout="neato",
gv.setv(n, k, str(val)) gv.setv(n, k, str(val))
nodes[v] = n nodes[v] = n
for e in g.edges(): # add edges
if eorder != None:
edges = sorted(g.edges(), lambda a, b: cmp(eorder[a], eorder[b]))
else:
edges = g.edges()
for e in edges:
ge = gv.edge(nodes[e.source()], ge = gv.edge(nodes[e.source()],
nodes[e.target()]) nodes[e.target()])
gv.setv(ge, "arrowsize", "0.3") gv.setv(ge, "arrowsize", "0.3")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment