Dot is an abstract grammar defining language. We can use dot to represent graphs also. In this post, I will show how different graphs can be generated with different codes from dot language. I will still use the Java api for dot language which I mentioned in GraphViz Java post.
Since these are just a few examples, you can find other attributes and styles from Graphviz dot attr page or the dot manual.
Simple Directed Graph
Since these are just a few examples, you can find other attributes and styles from Graphviz dot attr page or the dot manual.
digraph G { A B A -> B A -> C; }Output Notes
You see that you don't have to introduce each node at the beginning. Any node in the edges will automatically inserted.
Simple Graph without Edges
digraph G { A B C D }Output Notes
From this example, we see that we have to introduce all edges if there are no edges that consists of these nodes.
Simple Undirected Graph
graph G { A B A -- B A -- C }Output
Different Shape and Colors for Nodes
graph G { A [shape=box, peripheries=2,color=black, style=filled, fontcolor=white] B [style=filled, color=gray84, fillcolor=gray84,fontcolor=white] C [color=red, style=filled, fontcolor=white] D [shape=polygon,sides=4,distortion=.7] A -- B A -- C }Output Notes
You can find many different node styles in this manual.
Different Edge Styles
digraph G { A B C D A -> B [arrowhead=obox, style=dotted, color=red] A -> C [taillabel="tail"] A -> D [label="g'", weight=4] }Output Notes
Heavier weight means shorter, straighter and more vertical the edge is.
No comments:
Post a Comment