Graphviz

From Noah.org
Revision as of 01:02, 6 April 2008 by Root (talk | contribs) (New page: Category:Engineering Graphviz is a collection of tools for creating pictures from descriptions of graphs. It is not a GUI drawing tool. Instead, you write a description of a graph and ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Graphviz is a collection of tools for creating pictures from descriptions of graphs. It is not a GUI drawing tool. Instead, you write a description of a graph and Graphviz will draw it for you.

The main tool is `dot`. Without any options it doesn't do much. Usually you want to tell it to create a PNG.

dot -T png -o example.png example.dot

A dot script file is pretty simple. You pretty much just list nodes and denote connections between them with a '--' operator. You can repeat node names on different lines or you can list multiple connections on one line. Some special characters need quoting (note how I quote www.noah.org).

# This is simple, undirected graph of nodes. This just lists nodes. The edges have no labels.
graph example
{
    user -- internet
    internet -- "www.noah.org"
    database -- "www.noah.org"
    "Noah's home" -- "staging server" -- "www.noah.org"
}

You can also label the edges. Note how I broke the last two edges into two lines ("Noah's home" -- "staging server" -- "www.noah.org") so I could label each edge separately.

# This is simple, undirected graph of nodes. This adds labels to the edges.
graph example
{
    user -- internet [label="ISP"]
    internet -- "www.noah.org" [label="port 80"]
    database -- "www.noah.org" [label="port 3306"]
    "Noah's home" -- "staging server" [label="local"]
    "staging server" -- "www.noah.org" [label="port 22"]
}

You can create directed graphs using digraph instead of graph. Note that edges always point left->right. If you want an edge to point both directions then add "dir=both" to the properties (database -> "www.noah.org" [dir=both, label = "port 3306"]).

# This creates a directed graph.
digraph example
{
    user -> internet [label="ISP"]
    internet -> "www.noah.org" [label="port 80"]
    database  -> "www.noah.org" [dir=both, label="port 3306"]
    "Noah's home" -> "staging server" [label="local"]
    "staging server" -> "www.noah.org" [label="port 22"]
}