## DOT and Graphviz
### What is DOT?
DOT is a plain text graph description language. It is a simple way of describing graphs that both humans and computer programs can read.
### What is Graphviz?
Graphviz is open source graph visualization software. Graph visualization is a way of representing structural information as diagrams of abstract graphs and networks.
You can read a tutorial on how to use DOT here: <https://www.tonyballantyne.com/graphs.html>
The following code produces this graph:
![[dotgraphvizimage.png]]
```
try {
PrintWriter pout = new PrintWriter(new FileWriter("mygraph.gv"));
pout.println("digraph sample{");
pout.println("a -> b;");
pout.println("b -> c;");
pout.println("a -> e;");
pout.println("}");
pout.close();
} catch (IOException ex) {
System.out.println(ex.toString());
}
You can launch Graphviz and open the graph using the following code (note, you may have to adjust the path to Graphviz. Check that it's installed on your machine if you're doing this at home)
try {
Process process = new ProcessBuilder("C:\\Program Files (x86)\\Graphviz2.38\\bin\\gvedit.exe","mygraph.gv").start();
} catch (IOException ex) {
System.out.println(ex.toString());
}
```
## SVG: Scalable Vector Graphics
* SVG stands for Scalable Vector Graphics
* SVG is used to define vector-based graphics for the Web
* SVG defines the graphics in XML format
* Every element and every attribute in SVG files can be animated
You can see some examples here:
* <https://www.w3schools.com/graphics/svg_intro.asp>
* <https://developer.mozilla.org/en-US/docs/Web/SVG>
The following code will produce an SVG file that displays a red circle, and then opens it in chrome.
```
PrintWriter pout;
try {
pout = new PrintWriter(new FileWriter("mysvg.svg"));
pout.println("<svg width=\"200\" height=\"250\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">");
pout.println("<circle cx=\"25\" cy=\"75\" r=\"20\" stroke=\"red\" fill=\"transparent\" stroke-width=\"5\"/>");
pout.println("</svg>");
pout.close();
} catch (IOException ex) {
System.out.println(ex.toString());
}
try {
Process process = new ProcessBuilder("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\\","mysvg.svg").start();
} catch (IOException ex) {
System.out.println(ex.toString());
}
```