Show Me the Graph

Talk is cheap, Show me the Graph.

I have always hated those guys who put hundreds and thousands of words on a single page of presentation. IT REALLY S**KS. Well, assume there is not a handy tool, I believe Graphviz can be really really helpful to those troubled by this problem.

Here is what you need to know to draw a BEAUTIFUL graph. Documentation can be found here.

What I am trying to describe here is just a tip of the iceberg.

It seems that there won’t be Windows support in the near future. 2333333

A sample can be like this:

digraph G {
  {
    node [margin=0 fontcolor=blue fontsize=32 width=0.5 shape=circle style=filled]
    b [fillcolor=yellow fixedsize=true label="a very long label"]
    d [fixedsize=shape label="an even longer label"]
  }
  a -> {c d}
  b -> {c d}
}

The Dot Language

Group by (), optional items enclosed by [], Like attrs etc. e.g abc [fillcolor = red]. Full list here Main keywords are node, edge, graph, digraph, subgraph, strict. Node is exactly what you assume. Edge is somehow arrow or something like that.

Command-line Invocation

dot [flags] [input files]

By assign -T flags, you can output to all these formats, bmp,png,jpg,pdf, even psd.

Do use -o to specify a name for a output filename. Or use redirect.

Attrs

Most commonly used I believe is arrowhead, arrowtail, arrowsize, bgcolor, color, comment, colorscheme, fillcolor, fontcolor, fontname, fontsize, label, height, rank, rankdir, rotate, scale, size, skew

Use {} to enclose different sections

Shapes

Shape is also an attribute. Complete list box, polygon, ellipse, oval, circle ,egg, point, triangle, diamond, rectangle, square, star, folder, box3d, ……

Here is an example:

digraph R {
  rankdir=LR
  node [style=rounded]
  node1 [shape=box]
  node2 [fillcolor=yellow, style="rounded,filled", shape=diamond]
  node3 [shape=record, label="{ a | b | c }"]

  node1 -> node2 -> node3
}

Arrow Shapes

Usage here box, crow, curve, diamond, dot, icurve, inv, none, normal, tee,vee

The Best Part: Color

See this for the reference

There is an official guide here.

And, of course, the best part. UTF-8!