Rockbox.org home
releases
current build
extras FAQ
manual
wiki
docs index mailing lists
IRC
forums bugs
patches



Welcome | Register | Changes | Topics | Index | Search | Go
TWiki > TWiki > DirectedGraphPlugin > HowtoDirectedGraphs

Overview of directed graph editing

Introduction

Support for creating advanced directed graphs has been installed on this TWiki installation. Directed graphs are rendered by Graphviz. Only the most important basics are covered here, you should consult the dotguide.pdf from Graphviz's homepage for a more thourough guide on creating directed graphs.

What are directed graphs?

The graph:

digraph G { "a" -> "b"; "a" -> "c"; { rank = same; "b"; "c"; } }

To the left here you can see a simple directed graph with three "nodes", one on the top and two below (which are connected from top to bottom). Connecting these nodes you can also see two "edges", which is the technical term for the arrow connecting the three nodes.

When entering directed graphs in TWiki, everything you do is to define nodes and their edges (or connections); the directed graph engine then does all placing by itself, fully automatic.

No layout more than which nodes and their relationship, together with node and edge style is defined by the author; the engine takes care of all layout and placing of nodes, which makes creating advanced graphs extremely simple and fast.

Using more advanced syntax very advanced graphs can be created, including subgraphs and balanced trees and record graphs. This document only focusses on "normal" directed graphs; if you want to experiment more with the graph engine, consult the dotguide on www.graphviz.org.

Examples

A simple graph with two nodes

The graph:

digraph G { a -> b; }

The code:

<dot>
digraph G {
 a -> b;
}
</dot>
Explanation:

In order to describe a graph you start by typing:

<dot>
digraph G {
After the curly opening bracket ({) the actual graph description is located. When you have defined your graph you close it by typing:
}
</dot>

Inside those two parts you place your graph description. You can define nodes and edges (connection between nodes); you define edges by typing "node1" -> "node2"; which also implicit defines both nodes node1 and node2. If the nodes' names doesn't contain spaces or other special characters, the quotation marks can be ignored.

As you can see in this example we actually only define exactly one edge, the link between node a and node b, by typing a -> b;. Note also how the line is terminated by a semi-colon (;).

Added attributes to nodes and edges

The graph:

digraph G { a [style=filled, color=green]; b [style=filled, color=red];

a -> b [style=dotted, color=blue]; }

The code:

<dot>
digraph G {
 a [style=filled, color=green];
 b [style=filled, color=red];

 a -> b [style=dotted, color=blue];
}
</dot>
Explanation:

This example is very similar to the above example, with the difference that we have defined some attributes to both the nodes and the edge. As you can see the nodes are filled with green and red, respective. The edge has been changed to have a dotted line instead of a solid line.

If you want to assign attributes to nodes, the nodes have to be defined first, which means they appear on a line on their own. The order of node and edge definitions is not important, the whole file is parsed before any layout is begun.

The first line in the graph

a [style=filled, color=green];
defines the node a and assigns the attributes
style=filled
and
color=green
. These two attributes make the node filled with the color green.

As you can see to assign attributes to a node you just type its name (with the optional quotation marks) followed by the attribute definitions separated by commas, as it appears in the example above.

To add attributes to edges (i.e. arrows) just add the attributes to the line of the edge definition as can be seen on the last line of the graph definition.

Adding labels to edges

The graph:

digraph G { a -> b [label="link"]; }

The code:

<dot>
digraph G {
 a -> b [label="link"];
}
</dot>
Explanation:

Edges can be labeled by adding the attribute

label="text"
at the edge definition, as can be seen in the code of this example.

Adding subgraphs

The graph:

digraph G { a -> b; a -> c;

subgraph cluster0 { style=filled; color=lightgrey; rank=same;

node [style=filled, color=white]; b; c; }

c -> d; b -> d; }

The code:

<dot>
digraph G {
  a -> b;
  a -> c;

  subgraph cluster0 {
    node [style=filled, color=white];
    style=filled;
    color=lightgrey;
    rank=same; 
    b;
    c;
  }

  c -> d;
  b -> d;
}
</dot>
Explanation:

If you want to group nodes together, you put the node definitions inside a subgraph clusterXXX { } statement.

Note: the name of the subgraph must begin with cluster.

The subgraph has the attributes

style=filled
and
color=lightgrey
which makes the subgraph filled with the color light grey. The subgraph also has the attribute
rank=same
which makes all nodes defined inside the subgraph appear on the same level (i.e. they have the same rank).

You can also see the nodes b and c are defined in the subgraph by the last two lines in the subgraph.

All nodes defined in the subgraph have the attributes

style=filled, color=white
by adding the line node [style=filled, color=white];.

Grouping nodes

The graph:

digraph G { size="2.5,2";

{ node [shape=plaintext, fontsize=16];

1975 -> 1980 -> 1985; }

{ rank=same; 1975; a; b; c; } { rank=same; 1980; d; e; } { rank=same; 1985; f; g; h; i; }

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

The code:

<dot>

digraph G {
  {
    node [shape=plaintext, fontsize=16];

    1975 -> 1980 -> 1985;
  }

  { rank=same; 1975; a; b; c; }
  { rank=same; 1980; d; e; }
  { rank=same; 1985; f; g; h; i; }

  a -> d;
  b -> e;
  c -> e;
  d -> f;
  e -> g;
  e -> h;
  e -> i;
}
</dot>
Explanation:

In this graph three groups are defined, by putting them inside a block, defined by { }.

The first group defines the nodes 1975, 1980 and 1985, by connecting them together; these nodes are of the type "plaintext" with font size equal to 16. We do this because the years are to be placed to the left as a timeline and therefore the font size is choosen to be a little larger.

The next three groups for example

{ rank=same; 1975; a; b; }
ensures that the nodes 1975, a and b are on the same level, of course, because a and b occured in 1975 (It is left as an exercise to the reader to figure out what a and b actually is).

Following the last group definition we define all edges.

Node types

Choose the shape of a node by adding the attribute shape to the node definition.

digraph G { " " [shape=box]; }
box
digraph G { " " [shape=polygon]; }
polygon
digraph G { " " [shape=ellipse]; }
ellipse
digraph G { " " [shape=circle]; }
circle
digraph G { " " [shape=point]; }
point
digraph G { " " [shape=egg]; }
egg
digraph G { " " [shape=triangle]; }
triangle
digraph G { plaintext [shape=plaintext]; }
plaintext
digraph G { " " [shape=diamond]; }
diamond
digraph G { " " [shape=trapezium]; }
trapezium
digraph G { " " [shape=parallelogram]; }
parallelogram
digraph G { " " [shape=house]; }
house
digraph G { " " [shape=hexagon]; }
hexagon
digraph G { " " [shape=octagon]; }
octagon
digraph G { " " [shape=doublecircle]; }
doublecircle
digraph G { " " [shape=doubleoctagon]; }
doubleoctagon
digraph G { " " [shape=tripleoctagon]; }
tripleoctagon
digraph G { " " [shape=invtriangle]; }
invtriangle
digraph G { " " [shape=invtrapezium]; }
invtrapezium
digraph G { " " [shape=invhouse]; }
invhouse
digraph G { " " [shape=Mdiamond]; }
Mdiamond
digraph G { " " [shape=Msquare]; }
Msquare
digraph G { " " [shape=Mcircle]; }
Mcircle

Arrow types

The form of the edge can be set by using the arrowtail and arrowhead attributes with edges. The attribute arrowtail sets the shape of the arrow at the source node, while arrowhead sets the shape of the arrow at the destination node.

digraph G { a [shape=point];

a -> " " [arrowhead=normal]; }

normal
digraph G { a [shape=point];

a -> " " [arrowhead=dot]; }

dot
digraph G { a [shape=point];

a -> " " [arrowhead=odot]; }

odot
digraph G { a [shape=point];

a -> " " [arrowhead=inv]; }

inv
digraph G { a [shape=point];

a -> " " [arrowhead=invdot]; }

invdot
digraph G { a [shape=point];

a -> " " [arrowhead=invodot]; }

invodot
digraph G { a [shape=point];

a -> " " [arrowhead=none]; }

none

-- TWiki:Main.MikaelOlenfalk - 08 Aug 2005

Attachment Action Size Date Who Comment
png graph0058ce4b5087cba9266ca777c76b1408.png manage 0.2 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph0fbc8637cd6445ac966b9d9ffde33e38.png manage 0.2 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph11e915c267ab6ebbebfc43e0d1d231e5.png manage 0.3 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph12c538f8b237be5316b919f9214fae67.png manage 0.3 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph17c77ca0f032f1ad17143a2b683f705b.png manage 0.3 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph1980afea0e56672ab4b5ee832fd01a0c.png manage 0.3 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph1adb9063107771dc191968afda080ce9.png manage 0.4 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph1d5791947e3635a47f7c75517a950df6.png manage 0.2 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph2061f318f2dbf249101bc237e6d1ffd5.png manage 0.3 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph2478a2c401c37a4a7c5c55d654d3ea4a.png manage 1.3 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph26e60edc0ea523dd3dadfba1dbb46d12.png manage 0.3 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph279498a873cb76c750e3a9c415e3341a.png manage 0.3 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph2ccf0d9c11c168791cff2f61ecb6dbe1.png manage 0.2 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph2d7f4fa9ad366ecbec30e88c9fa48166.png manage 0.5 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph354b8adcba6ff6962137081f39ba37c7.png manage 0.3 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph35cf17852b9dae7ee4673392df55891b.png manage 1.6 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph3755ea6961afdd352062e06965b85baf.png manage 0.3 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph47c90eff8389d9fe4b4e0a321bb75dc8.png manage 0.3 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph693b434009bc60b1527b5ec87fe4897f.png manage 0.2 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph6a3d52f05250ce22eda8527fefb6c20a.png manage 0.3 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph729ab7e957e3250bb2afc64a13f02c10.png manage 0.2 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph8c0d2141e1575167fb0662a88f3d5b4e.png manage 0.3 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graph984f9e8ddc4343ac91e5e0b820953740.png manage 0.3 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png grapha1e508c5cf3f494c4ad920f39a63c9ec.png manage 0.6 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png grapha3d1c8f6e58ae481f3258ddcbdcc44e7.png manage 0.2 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graphb210c0d224eb2ccb7277e9102bff73ee.png manage 0.3 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graphb8fba6dbbb30d1959d0049c529570399.png manage 0.6 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graphbb79f5e45859feaaaf7c52255a6f8329.png manage 0.3 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graphcc160c8fbf9da61faf4cb243119ec80c.png manage 0.2 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graphd7c46c986e809542ff00713fcbf99d0f.png manage 0.3 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graphd80dd3e1a5efcc3488899ad4e2d190f7.png manage 0.1 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graphda9c40928085c0a3b1f4f516210d68cf.png manage 0.1 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graphdee6af6092106ebf0652194b2ee84145.png manage 0.9 K 13 Jun 2006 - 00:56 TWikiAdminGroup Saved by install script
png graphf31818f2ff4290edddbcfa9e66ff24fc.png manage 0.3 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graphf3e69b387bc65de7e6c23fbd7e18d723.png manage 0.1 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script
png graphfbc47cc6c3bdce37d153ae8284a4bd4b.png manage 0.4 K 19 Jul 2006 - 14:07 TWikiAdminGroup Saved by install script

r2 - 19 Jul 2006 - 14:07:48 - TWikiAdminGroup
Edit | View raw | Attach | Ref-By | History: r2 < r1 | More | Refresh cache
Copyright © 1999-2008 by the contributing authors.