X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Futil%2FGraphViz.java;h=ef08fae8ab8a028d443b84bb9f056e248141396b;hb=eda544585c2304faa82d249c4744fd5cecbf9211;hp=13899bb2540b108404b4774eebd4dc9f0a57bd5b;hpb=d95659dd73e9dee2d18417535e4c7d5a010033b6;p=sbp.git diff --git a/src/edu/berkeley/sbp/util/GraphViz.java b/src/edu/berkeley/sbp/util/GraphViz.java index 13899bb..ef08fae 100644 --- a/src/edu/berkeley/sbp/util/GraphViz.java +++ b/src/edu/berkeley/sbp/util/GraphViz.java @@ -20,14 +20,17 @@ public class GraphViz { public class Node { private final int idx = master_idx++; public String label; + public String comment; public boolean directed = false; public String color="black"; public ArrayList edges = new ArrayList(); + public ArrayList labels = new ArrayList(); public ArrayList inbound = new ArrayList(); - public void edge(ToGraphViz o) { + public void edge(ToGraphViz o, Object label) { Node n = o.toGraphViz(GraphViz.this); if (n==null) return; edges.add(n); + labels.add(label); n.inbound.add(this); } public String name() { @@ -37,8 +40,11 @@ public class GraphViz { } public void edges(PrintWriter pw) { if (simple()) return; - for(Node n : edges) - pw.println(" "+name()+" -> " + n.name() + " [color="+color+"];\n"); + for(int i=0; i " + n.name() + " [color="+color+" " +(label==null?"":("label=\""+label+"\""))+ "];\n"); + } } public int numEdges() { return edges.size(); } public boolean simple() { @@ -84,6 +90,7 @@ public class GraphViz { pw.print("\""); } pw.print("color="+color); + if (comment!=null) pw.print(" comment=\""+StringUtil.escapify(comment,"\\\"")+"\" "); pw.print("];\n"); } } @@ -106,9 +113,13 @@ public class GraphViz { public boolean isHidden(); } + public void show() throws IOException { + Runtime.getRuntime().exec(new String[] { "dot", "-Tsvg" }); + } + public void dump(PrintWriter pw) { IdentityHashMap done = new IdentityHashMap(); - pw.println("digraph G { rankdir=LR; \n"); + pw.println("digraph G { rankdir=LR; ordering=out; \n"); for(Group g : groups.values()) { pw.println(" { rank=same;\n"); for(Node n : groups.keySet()) @@ -124,6 +135,7 @@ public class GraphViz { } for(Node n : ihm.values()) n.edges(pw); pw.println("}\n"); + pw.flush(); } }