为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

DOT语言_GUIDE

2013-06-17 14页 pdf 374KB 17阅读

用户头像

is_806862

暂无简介

举报
DOT语言_GUIDE DOT 语言 GUIDE By cloudygoose 第一部分 设置点和线的形状和颜色 //先来看一个例子,我们创建一个文档graph1.dot: //digraph是有向图,graph是无向图,要注意,->用在有向图中,--用在无向图中表 示一条边,不能混用。 1: digraph G { 第一行给出了图的类型和名字 2: main -> parse -> execute; 当一个点第一次出现,它就 被创建了 3: main -> init; 用->标示符创建一条边 4: main -> ...
DOT语言_GUIDE
DOT 语言 GUIDE By cloudygoose 第一部分 设置点和线的形状和颜色 //先来看一个例子,我们创建一个文档graph1.dot: //digraph是有向图,graph是无向图,要注意,->用在有向图中,--用在无向图中 示一条边,不能混用。 1: digraph G { 第一行给出了图的类型和名字 2: main -> parse -> execute; 当一个点第一次出现,它就 被创建了 3: main -> init; 用->标示符创建一条边 4: main -> cleanup; 5: execute -> make_string; 6: execute -> printf 7: init -> make_string; 8: main -> printf; 9: execute -> compare; 10: } //然后在cmd下用这个文件运行dot dot -Tps graph1.dot -o graph1.ps //这是ps格式,你也可以改成jpg等格式。 //-Tps选择了postscript output, //就画出了这个图。 //来看下一个稍微复杂点的例子,我们开始手动的设置一下图的属性。可以给点设置属性, 也可以给边设置属性。先来讲讲怎么设置边的属性,在每条边后面的双括号里设置边的 属性。也可以在用edge设置边的默认值。 //而给点设置属性就必须给每个点单独的设置一个属性,node表示点的默认值。 //点的默认参数是shape=ellipse, width=.75, height=.5 and labeled by the node name. //一些点的形状在 appendix.h 中,一些常用的形状有 bos,circle,record,plaintext。 1: digraph G { 2: size ="4,4"; 把图的尺寸设为4 inch,4 inch 3: main [shape=box]; /* this is a comment */ 把main点的形状设 为方形 4: main -> parse [weight=8]; weight是设置了这条边 的重要程度,默认是1。 5: parse -> execute; 6: main -> init [style=dotted]; 让这条线是点状的 7: main -> cleanup; 8: execute -> { make_string; printf} 这条语句一次连了两 条线 9: init -> make_string; 10: edge [color=red]; // so is this 把边的默认颜色设为 了red 11: main -> printf [style=bold,label="100 times"]; label就是在边 上写了一行字 12: make_string [label="make a\nstring"]; 让make_string 变成了一个两行的字符串(注意那个\n)。 13: node [shape=box,style=filled,color=".7 .3 1.0"]; 设置了一下点的 默认参数,蓝色,这个被用在了compare中。 14: execute -> compare; 15: } 画出以下图形: //可以设置每条边箭头的方向,用 dir,有 forward(default),back,both,none 四种。 digraph html { A -> B[dir = both]; B -> C[dir = none]; C -> D[dir = back]; D -> A[dir = forward]; } //点的 shape 除了 record 和 Mrecord 这两种之外,其他的形状都是多边形,而我们可以对多 边形进行一下属性上的设置,shape = polygon。Sides 用于设置它的边数,peripheries 用于设 置多边形的外框的层数,regular = true 可以让你的多边形是一个的多边形,orientation = *,可以让你的多边形旋转一个角度,如 orientation = 15 就是转了 15 度。Skew 后面跟一个 (-1.0~1.0)的小数,能让你的图形斜切一个角度,distortion 是让你的图形产生透视效果。 1: digraph G { 2: a -> b -> c; 3: b -> d; 4: a [shape=polygon,sides=5,peripheries=3,color=lightblue,style=filled]; 5: c [shape=polygon,sides=4,skew=.4,label="hello world"] 6: d [shape=invtriangle]; 7: e [shape=polygon,sides=4,distortion=.7]; 8: } digraph A{ A -> B; A[orientation = 15, regular = true, shape = polygon, sides = 8, peripheries = 4, color = red style = filled]; B[shape = polygon, sides = 4, skew = 0.5, color = blue]; } //record 和 Mrecord 的区别就是 Mrecord 的角是圆的。Record 就是由衡的和竖的矩形组成的 图形。 1: digraph structs { 2: node [shape=record]; 3: struct1 [shape=record,label=" left| mid\ dle| right"]; 4: struct2 [shape=record,label=" one| two"]; 5: struct3 [shape=record,label="hello\nworld |{ b |{c| d|e}| f}| g | h"]; 6: struct1 -> struct2; 7: struct1 -> struct3; 8: } //当你的线和线 label 比较多时,可以给线的属性 decorate = true,使得每条线的 label 与所属 线之间连线。你还可以给每条线加上 headlabel 和 taillabel,给每条线的起始点和终点加上 label,他们的颜色由 labelfontcolor 来决定,而 label 的颜色由 fontcolor 来决定。 graph A{ label = "I love you"; //给这幅图设置,名字 labelloc = b; //图名字的位置在 bottom,也可以是 t labeljust = l; //图名字的位置在 left,也可以是 r edge[decorate = true]; C -- D[label = "s1"]; C -- E[label = "s2"]; C -- F[label = "s3"]; D -- E[label = "s4"]; D -- F[label = "s5"]; edge[decorate = false, labelfontcolor = blue, fontcolor = red]; C1 -- D1[headlabel = "c1", taillabel = "d1", label = "c1 - d1"]; } //在 dot 中我们可以用 html 语言写一个 table。在 label 后用< >而不是” ”就能引入 html 语 言。 1: digraph html { 2: abc [shape=none, margin=0, label=< 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
hello
world
bgh
cde
f
>]; 16: } //这样创造了一个 5 行 5 列的表格,我们可以在表格中打字。 digraph html { abc [shape=none, margin=0, label=<
01234
1
2
3
4
>]; } 第二部分 设置点和线的位置,子图的概念 //默认时图中的线都是从上到下的,我们可以将其改为从左到右,在文件的最上层打入 rankdir=LR 就是从左到右,默认是 TB(top -> bottom),也可以是 RL,BT。 //当图中时间表之类的东西时,我们会需要点能排在一行(列),这时要用到 rank,用花括 号把 rank=same,然后把需要并排的点一次输入。 digraph html { rankdir = LR; { node[shape = plaintext]; 1995 -> 1996 -> 1997 -> 1998 -> 1999 -> 2000 -> 2001; } { node[shape = box, style = filled]; WAR3 -> Xhero -> Footman -> DOTA; WAR3 -> Battleship; } {rank = same; 1996; WAR3;} {rank = same; 1998; Xhero; Battleship;} {rank = same; 1999; Footman;} {rank = same; 2001; DOTA;} } 设立一条边时,我们可以制定这条边从起点的那个位置射出和从哪个位置结束。控制符 有"n", "ne","e", "se", "s", "sw", "w" 和 "nw",具体效果见下: digraph html { node[shape = box]; c:n -> d[label = n]; c1:ne -> d1[label = ne]; c2:e -> d2[label = e]; b:se -> a[label = se]; c3:s -> d3[label = s]; c4:sw -> d4[label = sw]; c5:w -> d5[label = w]; c6:nw -> d6[label = nw]; } 我们也可以在 record 中给点定义一些 port,因为 record 类型中都是一个个格子。 digraph html { label = "Binary search tree"; node[shape = record]; A[label = " | A | "]; B[label = " | B | "]; C[label = " | C | "]; D[label = " | D | "]; E[label = " | E | "]; A:f0:sw -> B:f1; A:f2:se -> C:f1; B:f0:sw -> D:f1; B:f2:se -> E:f1; } Administrator 线条 //构造一个 HASH 表 1: digraph G { 2: nodesep=.05; 3: rankdir=LR; 4: node [shape=record,width=.1,height=.1]; 5: 6: node0 [label = " | | | | | | | ",height=2.5]; 7: node [width = 1.5]; 8: node1 [label = "{ n14 | 719 |

}"]; 9: node2 [label = "{ a1 | 805 |

}"]; 10: node3 [label = "{ i9 | 718 |

}"]; 11: node4 [label = "{ e5 | 989 |

}"]; 12: node5 [label = "{ t20 | 959 |

}"] ; 13: node6 [label = "{ o15 | 794 |

}"] ; 14: node7 [label = "{ s19 | 659 |

}"] ; 15: 16: node0:f0 -> node1:n; 17: node0:f1 -> node2:n; 18: node0:f2 -> node3:n; 19: node0:f5 -> node4:n; 20: node0:f6 -> node5:n; 21: node2:p -> node6:n; 22: node4:p -> node7:n; 23: } Figure 17: Hash table graph file n14 719 a1 805 i9 718 e5 989 t20 959 o15 794 s19 659 Figure 18: Drawing of hash table 画一个子图就是 subgraph cluster#,必须有 cluster前缀。 Administrator 线条 当你想把一条边连到一个子图的边界上,先输入 compound = true,然后就能用 lhead 和 ltail 来设置连接的子图了。

/
本文档为【DOT语言_GUIDE】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索