Example dot files

From Notes_Wiki
Revision as of 16:58, 24 January 2013 by Saurabh (talk | contribs) (Created page with "<yambe:breadcrumb>Dot|Dot</yambe:breadcrumb> =Example dot files= Dot is explained further with example dot files which can generate various types of graphs. ==Example 1== T...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<yambe:breadcrumb>Dot|Dot</yambe:breadcrumb>

Example dot files

Dot is explained further with example dot files which can generate various types of graphs.

Example 1

The following dot file can be used to generate a graph of various types of input devices:

graph input_devices_graph
{
        "Input Devices" -- "Keyboard";
        "Input Devices" -- "Mouse";
        "Input Devices" -- "Joystick";
        "Input Devices" -- "Scanner";
}


Assuming above graph is saved in file '=01-input_devices.dot=' an SVG graph for the given dot input can be generated using:

dot -Tsvg -o 01-input_devices.svg 01-input_devices.dot

Few things to note from this example are:

  • Nodes are automatically created if they are used in edge specification. Separate declaration of nodes, before they are used in an edge, is not required.
  • Names and values should be enclosed in double-quotes ("").
  • In absence of separate declaration label for a node is assumed to be same as name of the node.


Example 2

The above example generates same type of node for both "Input Devices" category and for "Keyboard", "Mouse", etc. which are objects belonging to given category. If it is desired to have different types of nodes to make this distinction clearer then one can use following dot file:

graph input_devices_graph
{
        node ["shape"="box"];
        "Input Devices" ["shape"="circle"];
        "Input Devices" -- "Keyboard";
        "Input Devices" -- "Mouse";
        "Input Devices" -- "Joystick";
        "Input Devices" -- "Scanner";
}

Note the following things in above example:

  • Default node shape is set to box, so that unless specified other wise nodes are represented using boxes.
  • For node "Input devices" shape is specifically set to "circle" which overrides previously specified default "box".


Example 3

The following example shows how attributes of the edges can be used to modify properties of an edge

graph input_devices_graph
{
        node ["shape"="box"];
        "Input Devices" ["shape"="circle"];
        "Input Devices" -- "Keyboard" [label="PS/2 or USB"];
        "Input Devices" -- "Mouse"  [label="PS/2 or USB"];
        "Input Devices" -- "Joystick" [label="USB"];
        "Input Devices" -- "Scanner" [label="USB"];
}

Note that the output of above dot file is not very clear as the labels overlap each other. This problem can be solved to some extent by chaning the layout as done in next example.


Example 4

In the previous example the labels for various edges overlap each other as the edges as various nodes are placed next to each other horizontally. If the layout is changed so that node "Input Devices" comes in center of the graph and all other nodes are arranged in circular fasion around it, then this problem will get resolved. The same is done in this example using layout as "circo" and by specifying "Input Devices" node as root node.

graph input_devices_graph
{
	"layout"="circo";
        node ["shape"="box"];
        "Input Devices" ["shape"="circle","root"="true"];
        "Input Devices" -- "Keyboard" [label="PS/2 or USB"];
        "Input Devices" -- "Mouse"  [label="PS/2 or USB"];
        "Input Devices" -- "Joystick" [label="USB"];
        "Input Devices" -- "Scanner" [label="USB"];
}


Example 5

This example shows how to create an directed graph. It also uses default attributes for edges.

digraph shapes
{
	edge ["dir"="back"];
	"Shapes" -> "Quadrilateral";
	"Shapes" -> "Ellipse";
	"Ellipse" -> "Circle";
	"Quadrilateral" -> "Rectangle";
	"Rectangle" -> "Square";
	"Quadrilateral" -> "Rhombus";
	"Rhombus" -> "Square";
}

Note the following important points in this example:

  • Use of "->" instead of "--" in edge specification.
  • Use of default edge attribute specification to reverse direction of all edge arrows.



<yambe:breadcrumb>Dot|Dot</yambe:breadcrumb>