Commit 6ba338ef authored by Tiago Peixoto's avatar Tiago Peixoto

Graph drawing: fix edge properties and other things

parent 869ac654
...@@ -28,7 +28,8 @@ def graph_draw(g, pos=None, size=(15,15), pin=False, layout="neato", ...@@ -28,7 +28,8 @@ def graph_draw(g, pos=None, size=(15,15), pin=False, layout="neato",
mode="ipsep", penwidth=1.0, eweight=None, ewidth=None, gprops={}, mode="ipsep", penwidth=1.0, eweight=None, ewidth=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=None, output_format=None, seed=0): enorm=True, output="", output_format="auto", returngv=False,
seed=0):
"""Draw a graph using graphviz.""" """Draw a graph using graphviz."""
if g.is_directed(): if g.is_directed():
...@@ -51,7 +52,7 @@ def graph_draw(g, pos=None, size=(15,15), pin=False, layout="neato", ...@@ -51,7 +52,7 @@ def graph_draw(g, pos=None, size=(15,15), pin=False, layout="neato",
if splines: if splines:
gv.setv(gvg,"splines", "true") gv.setv(gvg,"splines", "true")
gv.setv(gvg,"ratio", str(ratio)) gv.setv(gvg,"ratio", str(ratio))
gv.setv(gvg,"size", "%f,%f" % (size[0]/2.54,size[0]/2.54)) # centimeters gv.setv(gvg,"size", "%f,%f" % (size[0]/2.54,size[1]/2.54)) # centimeters
if maxiter != None: if maxiter != None:
gv.setv(gvg,"maxiter", str(maxiter)) gv.setv(gvg,"maxiter", str(maxiter))
gv.setv(gvg,"start", str(seed if seed > 0 else time.time())) gv.setv(gvg,"start", str(seed if seed > 0 else time.time()))
...@@ -70,14 +71,13 @@ def graph_draw(g, pos=None, size=(15,15), pin=False, layout="neato", ...@@ -70,14 +71,13 @@ def graph_draw(g, pos=None, size=(15,15), pin=False, layout="neato",
c = vcolor[v] c = vcolor[v]
minmax[0] = min(c,minmax[0]) minmax[0] = min(c,minmax[0])
minmax[1] = max(c,minmax[1]) minmax[1] = max(c,minmax[1])
print minmax
if vnorm: if vnorm:
vnorm = matplotlib.colors.normalize(vmin=minmax[0], vmax=minmax[1]) vnorm = matplotlib.colors.normalize(vmin=minmax[0], vmax=minmax[1])
if ecolor != None and not isinstance(ecolor, str): if ecolor != None and not isinstance(ecolor, str):
minmax = [float("inf"), -float("inf")] minmax = [float("inf"), -float("inf")]
for e in g.edges(): for e in g.edges():
c = ecolor[v] c = ecolor[e]
minmax[0] = min(c,minmax[0]) minmax[0] = min(c,minmax[0])
minmax[1] = max(c,minmax[1]) minmax[1] = max(c,minmax[1])
if enorm: if enorm:
...@@ -162,11 +162,12 @@ def graph_draw(g, pos=None, size=(15,15), pin=False, layout="neato", ...@@ -162,11 +162,12 @@ def graph_draw(g, pos=None, size=(15,15), pin=False, layout="neato",
p = p.split(",") p = p.split(",")
pos[0][g.vertex(n)] = float(p[0]) pos[0][g.vertex(n)] = float(p[0])
pos[1][g.vertex(n)] = float(p[1]) pos[1][g.vertex(n)] = float(p[1])
if output == None:
output = "" if output_format == "auto":
output_format = "xlib" if output == "":
elif output_format == None: output_format = "xlib"
outout_format = output.split(".")[-1] else:
outout_format = output.split(".")[-1]
# if using xlib we need to fork the process, otherwise good ol' graphviz # if using xlib we need to fork the process, otherwise good ol' graphviz
# will call exit() when the window is closed # will call exit() when the window is closed
...@@ -178,5 +179,9 @@ def graph_draw(g, pos=None, size=(15,15), pin=False, layout="neato", ...@@ -178,5 +179,9 @@ def graph_draw(g, pos=None, size=(15,15), pin=False, layout="neato",
os.wait() os.wait()
else: else:
gv.render(gvg, output_format, output) gv.render(gvg, output_format, output)
gv.rm(gvg)
return pos if returngv:
return pos, gv
else:
gv.rm(gvg)
return pos
Markdown is supported
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