Added graphviz

This commit is contained in:
Yorick Rommers
2017-05-31 12:34:36 +02:00
parent 373f82c00e
commit e80ec332d1
6 changed files with 74 additions and 0 deletions
+35
View File
@@ -1,5 +1,17 @@
package com.imegumii;
import guru.nidi.graphviz.engine.Format;
import guru.nidi.graphviz.engine.Graphviz;
import guru.nidi.graphviz.model.Label;
import guru.nidi.graphviz.model.MutableGraph;
import guru.nidi.graphviz.model.Node;
import guru.nidi.graphviz.parse.Parser;
import java.io.*;
import static guru.nidi.graphviz.model.Factory.graph;
import static guru.nidi.graphviz.model.Factory.node;
/**
* Created by kenny on 18-5-2017.
*/
@@ -30,4 +42,27 @@ public class Graph {
return text;
}
public static void generateImage(Automata<String> a, String fileName) {
try {
File f = new File("images/" + a.toString() + ".dot");
PrintWriter w = new PrintWriter(f);
w.println(Graph.generateGraphString(a));
w.flush();
w.close();
MutableGraph g = Parser.read(f);
if (fileName != null) {
Graphviz.fromGraph(g).width(1080).render(Format.PNG).toFile(new File("images/" + fileName + ".png"));
} else {
Graphviz.fromGraph(g).width(1080).render(Format.PNG).toFile(new File("images/" + a.toString() + ".png"));
}
if (f.delete()) {
System.out.println("Succesfully deleted temp file");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}