您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 能源与动力工程 > DOT语言-GUIDE
DOT语言GUIDEBycloudygoose第一部分设置点和线的形状和颜色//先来看一个例子,我们创建一个文档graph1.dot://digraph是有向图,graph是无向图,要注意,-用在有向图中,--用在无向图中表示一条边,不能混用。1:digraphG{第一行给出了图的类型和名字2:main-parse-execute;当一个点第一次出现,它就被创建了3:main-init;用-标示符创建一条边4:main-cleanup;5:execute-make_string;6:execute-printf7:init-make_string;8:main-printf;9:execute-compare;10:}//然后在cmd下用这个文件运行dotdot-Tpsgraph1.dot-ograph1.ps//这是ps格式,你也可以改成jpg等格式。//-Tps选择了postscriptoutput,//就画出了这个图。//来看下一个稍微复杂点的例子,我们开始手动的设置一下图的属性。可以给点设置属性,也可以给边设置属性。先来讲讲怎么设置边的属性,在每条边后面的双括号里设置边的属性。也可以在用edge设置边的默认值。//而给点设置属性就必须给每个点单独的设置一个属性,node表示点的默认值。//点的默认参数是shape=ellipse,width=.75,height=.5andlabeledbythenodename.//一些点的形状在appendix.h中,一些常用的形状有bos,circle,record,plaintext。1:digraphG{2:size=4,4;把图的尺寸设为4inch,4inch3:main[shape=box];/*thisisacomment*/把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];//soisthis把边的默认颜色设为了red11:main-printf[style=bold,label=100times];label就是在边上写了一行字12:make_string[label=makea\nstring];让make_string变成了一个两行的字符串(注意那个\n)。13:node[shape=box,style=filled,color=.7.31.0];设置了一下点的默认参数,蓝色,这个被用在了compare中。14:execute-compare;15:}画出以下图形://可以设置每条边箭头的方向,用dir,有forward(default),back,both,none四种。digraphhtml{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:digraphG{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=helloworld]6:d[shape=invtriangle];7:e[shape=polygon,sides=4,distortion=.7];8:}digraphA{A-B;A[orientation=15,regular=true,shape=polygon,sides=8,peripheries=4,color=redstyle=filled];B[shape=polygon,sides=4,skew=0.5,color=blue];}//record和Mrecord的区别就是Mrecord的角是圆的。Record就是由衡的和竖的矩形组成的图形。1:digraphstructs{2:node[shape=record];3:struct1[shape=record,label=f0left|f1mid\dle|f2right];4:struct2[shape=record,label=f0one|f1two];5:struct3[shape=record,label=hello\nworld|{b|{c|hered|e}|f}|g|h];6:struct1-struct2;7:struct1-struct3;8:}//当你的线和线label比较多时,可以给线的属性decorate=true,使得每条线的label与所属线之间连线。你还可以给每条线加上headlabel和taillabel,给每条线的起始点和终点加上label,他们的颜色由labelfontcolor来决定,而label的颜色由fontcolor来决定。graphA{label=Iloveyou;//给这幅图设置,名字labelloc=b;//图名字的位置在bottom,也可以是tlabeljust=l;//图名字的位置在left,也可以是redge[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:digraphhtml{2:abc[shape=none,margin=0,label=3:TABLEBORDER=0CELLBORDER=1CELLSPACING=0CELLPADDING=44:TRTDROWSPAN=3FONTCOLOR=redhello/FONTBR/world/TD5:TDCOLSPAN=3b/TD6:TDROWSPAN=3BGCOLOR=lightgreyg/TD7:TDROWSPAN=3h/TD8:/TR9:TRTDc/TD10:TDPORT=hered/TD11:TDe/TD12:/TR13:TRTDCOLSPAN=3f/TD14:/TR15:/TABLE];16:}//这样创造了一个5行5列的表格,我们可以在表格中打字。digraphhtml{abc[shape=none,margin=0,label=TABLEBORDER=0CELLBORDER=1CELLSPACING=0CELLPADDING=4TRTD0/TDTD1/TDTD2/TDTD3/TDTD4/TD/TRTRTD1/TDTD/TDTD/TDTD/TDTD/TD/TRTRTD2/TDTD/TDTD/TDTD/TDTD/TD/TRTRTD3/TDTD/TDTD/TDTD/TDTD/TD/TRTRTD4/TDTD/TDTD/TDTD/TDTD/TD/TR/TABLE];}第二部分设置点和线的位置,子图的概念//默认时图中的线都是从上到下的,我们可以将其改为从左到右,在文件的最上层打入rankdir=LR就是从左到右,默认是TB(top-bottom),也可以是RL,BT。//当图中时间表之类的东西时,我们会需要点能排在一行(列),这时要用到rank,用花括号把rank=same,然后把需要并排的点一次输入。digraphhtml{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,具体效果见下:digraphhtml{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类型中都是一个个格子。digraphhtml{label=Binarysearchtree;node[shape=record];A[label=f0|f1A|f2];B[label=f0|f1B|f2];C[label=f0|f1C|f2];D[label=f0|f1D|f2];E[label=f0|f1E|f2];A:f0:sw-B:f1;A:f2:se-C:f1;B:f0:sw-D:f1;B:f2:se-E:f1;}//构造一个HASH表1:digraphG{2:nodesep=.05;3:rankdir=LR;4:node[shape=record,width=.1,height=.1];5:6:node0[label=f0|f1|f2|f3|f4|f5|f6|,height=2.5];7:node[width=1.5];8:node1[label={nn14|719|p}];9:node2[label={na1|805|p}];10:node3[label={ni9|718|p}];11:node4[label={ne5|989|p}];12:node5[label={nt20|959|p}];13:node6[label={no15|794|p}];14:node7[label={ns19|659|p}];15:16:node0:f0-node1:n;17:node0:f1-node2:n;18:node0:f2-node3:n;19:node
本文标题:DOT语言-GUIDE
链接地址:https://www.777doc.com/doc-3132133 .html