11

I want to create a graph like the one shown below... but way too complex. I want to use separate images for each of the square nodes and the same image for each of the circle nodes.

I want to know whether using GraphViz is the best option or are there any other options?

Also, I would like to know if I can create a template node in GraphViz for the circle one and reuse it? I don't want to specify the attributes like image, shape, etc. again and again.

Sample Graph

2 Answers 2

15

Sure, here's the code to draw the graph in your Question (and which is shown rendered by dot, below).

digraph g {
rankdir = TB;
bgcolor = white;

edge[arrowsize=.7, color=black];
node[shape=box, color=black]

{rank=same; a, b, c};
{rank=same; d, e, f};
{rank=same; g, h};
{rank=same; i, j, k};

d[color=blue; shape=circle];
e[color=blue; shape=circle];
k[color=blue; shape=circle];

a -> d;
b -> d;
b -> e;
c -> e;
d -> g;
e -> h;
d -> i;
d -> j;
j -> k;
h -> k;
k -> f;
}


  1. the first line digraph is for directed graph (for graphs in which the edges have a direction).

  2. The fourth and fifth lies above set default attributes for edges and nodes, respectively. In other words, once you've done this, you only need to style (include attribues + values) nodes (or edges) which you want to style differently than the default values. You can have more than one node "template" by creating subgraphs, or discrete groups nodes (see the dot Manual).

  3. rank=same allows you to specifiy a group of nodes having the same vertical position (provided rankdir is set to TB, which meant "top-to-bottom").

  4. By default, the node name (e.g., a, b, c in my graph) is used as the node's label. If you don't want this shown in the rendered graph, just set label=""

enter image description here

11

Graphviz is definitely appropriate for what you are asking. The main graphviz.org site appears to be down for the moment, but someone has kindly mirrored the gallery examples (with source) to Flickr.

http://www.flickr.com/photos/kentbye/sets/72157601523153827/

As far as I am aware, you cannot create "templates", but you can do something like this for the circles:

node[shape=circle, color=white, style=solid];
node1;node2;node3;

This will define a node (think of it as a "state" when evaluating the file line-by-line) and then you can define your circle nodes in that "state" before switching to your rectangles.

Depending on your platform, you may also be able to import your .dot file and fine-tune it for publication. There are also a large number of generators and convertors for the format.

Mind you, if you are working on Mac OS X 10.7 "Lion", I have not been able to find or build a working version of Graphviz yet. In which case I would say it is not yet appropriate for your needs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.