checkpoint
[sbp.git] / src / edu / berkeley / sbp / util / GraphViz.java
index bfef2f6..ff8f46c 100644 (file)
@@ -20,6 +20,7 @@ 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<Node> edges = new ArrayList<Node>();
@@ -89,6 +90,7 @@ public class GraphViz {
                 pw.print("\"");
             }
             pw.print("color="+color);
+            if (comment!=null) pw.print(" comment=\""+StringUtil.escapify(comment,"\\\"")+"\" ");
             pw.print("];\n");
         }
     }
@@ -111,6 +113,10 @@ public class GraphViz {
         public boolean isHidden();
     }
 
+    public void show() throws IOException {
+        Runtime.getRuntime().exec(new String[] { "dot", "-Tsvg" });
+    }
+
     public void dump(PrintWriter pw) {
         IdentityHashMap<Node,Node> done = new IdentityHashMap<Node,Node>();
         pw.println("digraph G { rankdir=LR; \n");
@@ -129,6 +135,7 @@ public class GraphViz {
         }
         for(Node n : ihm.values()) n.edges(pw);
         pw.println("}\n");
+        pw.flush();
     }
 
 }