Graphviz中文教程指南

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-Tpsgraphl.dot-ograph1.ps〃这是ps格式,你也可以改成jpg等格式〃・Tps选择fpostscriptoutput,〃就isi出了这个图第一行给出了图的类型和名字当一个点第一次出现,它就被创建了用标示符创建-•条边Figurc2:Drawingofsmallgraph〃來看卜•一个稍微复杂点的例子,我们开始手动的设置一卜•图的属性可以给点设置属性,也可以给边设置属性先来讲讲怎么设置边的属性,在每条边后面的双括号里设置边的属性。
也可以在用edge设置边的默认值〃而给点设置属性就必须给每个点单独的设置一个属性,node表示点的默认值〃点的默认参数是shape=ellipse,width=.75,height=.5andlabeledbythenodename.〃一些点的形状在appendix.h中,一些常用的形状有bos,circlejecord.plaintexto1:digraphG{2:size=”4,4”;把图的尺寸设为4inch,4inch3:main[shape=box];/*thisisacomment*/4:main->parse[weight=8];程度,默认是15:parse->execute;把main点的形状设为方形weight是设置了这条边的重要6:main->init[style=dotted];7:main->cleanup;让这条线是点状的8:execute->{make.string;printf}9:init->niake_string;这条语句一次连了两条线10:edge[coloured];//soisthis11:main->printf[style=boldJabel=M100times"];把边的默认颜色设为了redlabel就是在边上写了一行字12:makerstring[labeI=Hmakea\nstringH];让make.string变成了一个两行的字符串(注意那个\n)o13:node[shape=box,style=filled,color=H.7.31.0H];设置了一下点的默认参数,蓝色,这个被用在了compare中。
14:execute->compare;15:}画出以F图形:mainFigure4:Drawingoffancj.rgraph〃可以设置每条边箭头的方向,用dir,Wforward(default),back,both,none四种digraphhtml{A->B[dir=both];B->C[dir=none];C->D[dir=back];D->A[dir=forward];〃点的shape除了record和Mrecord这两种Z外,其他的形状都是多边形,而我们可以对多边形进行一下属性上的设置,shape=polygonoSides用于设置它的边数,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=.4jabel=,,helloworld'*]6:d[shape=invtriangle];7:e[shape=polygon,sides=4,distortion=.7];&}helloworlddigraphA{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:structI[shape=recordJabel=M
1:digraphhlml{2:abc[shape二none,margin=0・label=v3: 〃当图中时间表之类的东西时,我们会需要点能排在一行(列),这时要用到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;}}A1999A2000»20011998设立一条迦比我们可以制定这条边从起点的那个位置射出和从哪个位置结束控制符有W,”ne”,“e”,“sc”,”s”,”sw“,”w”和”nw”,具体效果见下:digraphhtml{node[shape=box];c:n->dElabel=n];cl:ne->dl[label=ne];c2:e->d2[label=e]:b:se->aElabel=se];c3:s->d3[label=s];c4:sw->d4[label=sw];c5:w->d5[label=w];c6:nw->d6.label=nw];我们也nJ•以在record中给点定义一些port,因为record类型中都是一个个格子。 digraphhtml{AElabel=" digraphG{subgraphclusterO{node[style=filledrcolor=white];style=filled;color=lightgrey;d.0—>1->->a3;label=11process#ln;subgraphcluster1{node[style=filled];bO->bl->b2->b3;label=Mprocess^2H;color=bluestartstartal->b2->a3->d.3->b3->->aO;->bO;b3;a3;aO;end;end;[shape=Mdind];end[shape=Msquare];start.aualFigure:19:Processdiagramwithclusters当你想把一条边连到一个子图的边界上,先输入compound=true,然后就能用lhcad和Itail來设置连接的子图了digraphG{compound=true;subgraphclusterO{a->b;a一〉c;b->d;c一〉d;}subgraphcluster!{e->g;Q->f;}b->f[lh©ad=clustQr1];d->e;c->g[Itail=cluster0,lhead=cLusterl];c->e[ltail=clusterO];d->h;IrwordMi^cordHNodeShapesTtesearetlieprincipalnodeshapes.Amorecompfetedesrriptionofnocteshapescanbefoundalthewebsitewww・graphviz・0忙勺/日00/3口£0/空人吕左总弓・btmlboxcirclepolygonplaintexttrianglepointtrapeziumplaintextcctagonparallelogrmidoubfeoctagonhexagoninvtriangledoubtcircletripleoctagoninvtrapeziumononeMcirclenoneMsquareJColorNamesHerearesomebasiccolornames.Moreinformationaboutcolorscanbefoundatwww•graphviz•orcr/doc/info/colors*htmlwww•graphviz・Qtg/doc/info/attrs.h七ml#k:colorWliitesR«IsYelkwsturquoise11-4]anhquewhite[l-4]coral[1-4]dafkgoldenrod[l-4]azurej1-4]crimsongpid[M]Bluesbisque[1-4]darksalmongoldenrod!1-4]aliceblueblanchedalmonddeeppinlc[l-4]greenyellowblue[K4]conisilk[1-4]tirebrick[l-4]li^htgoldenrod[l-4]bluevioletiloialwhitehotpink[14]lightgoldeiirodye11owcadetblue[1-4]gainsboroindianredf1-4|lightyellow[l-4]corntlowerblueghos(whitelightpink[1-4]palegoldemoddarkslateblnehoneydew[1-4]lightsalmonl1-4]yellow|1-4]deepskybluel1-4]ivory[1-4]maroon[l-4]wllowgreendodgerhlue[1-4]lavendermediunivioletiedindigolavenderblush[l-4]orangcrcd[l-4]Girenslightblue[l-4]lemondiiffon|1-4]palevioleired[1-4]chartreuse[1-4]Lighiskybliic[l・4]linenpink[1-4]daikgreenligh(slaicbluc[l-4]mintcreamred[b4]daikolivegreen[i-4]mediumbluemistyrose[1-4]salmonl1-4]daikseag:reen[1-4]mcdiumslateblucmoccasintomato[1-4]foresrgreenmidnighlbluenavajourhite[l-4]violetrod[1-4]green]17]jiavyoldlacegreenyellownavybluepapayawhipBrownslawngreenpowderbluepeachpuff[1-4]beigelightseagreenroyalblue[1-4]seashell[1-4]brownfl-4]liniegreenskyhlue[1・4]sncMjl-4]bu「lywood[l・4]mediiimseagreeiislateblue11-4]thLSile[l-4]chocolate[1-4]mediuinspringgreensteelbluel1-4]wheai[l-4Jdarkkhakimintcreamwhitekhaki|l-4|olivedrab[1-4]Magentaswhitesmokcpcrupalegreen[1・4]bluevioletrosybiwn[l-4]seagreenl1-4]darkorchid[1-4]Greyssaddlebrownspringgreen[l-4]darkvioletdarkslategray[l-4]sandybrownyellowgreenmagenta[l-4-]dimgraysienna[l-4]mediumorchid[1-4]graytan[1-4]Cvansmediumpurple[1-4]gray[0-100]aquainanne[l-4]mcdiumvioleircdlightgrayOningescjran[b4]orchid[I-4]lightslategraydarkorange[l-4]daitrurquoisepalevioletred[l-4]slategray[1-4]orange[1-4]lightcyan[l-4]plum[1-4Jorangere <7TR>2 <7TR> 3 <7TR>vTRxTD>4<7TR>bottom),也可以是RL,BT。