当前位置首页 > 办公文档 > 解决方案
搜柄,搜必应! 快速导航 | 使用教程  [会员中心]

Graphviz中文教程指南

文档格式:DOC| 14 页|大小 452.50KB|积分 18|2022-12-19 发布|文档ID:175322662
第1页
下载文档到电脑,查找使用更方便 还剩页未读,继续阅读>>
1 / 14
此文档下载收益归作者所有 下载文档
  • 版权提示
  • 文本预览
  • 常见问题
  • 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=Mleftlmid\dlelright11];4:struct2[shape=recordJabel=Moneltwo11];5:struct3[shape=recordJabel=Hhello\nworldl{bl{cldie}If}lgIhH];6:struct1->struct2;7:struct1->struct3;8:}leftmiddie〃当你的线和线label比较多时,町以给线的属性decorate=true,使得每条线的label与所属线Z间连线你还可以给每条线加上headlabel和taillabel,给每条线的起始点和终点加上label,他们的颜色由labelfontcolor來决定,而label的颜色由fontcolor來决定graphA{label=nIloveyou";labelloc=b;〃给这幅图设置,名字〃图名字的位置在bottom,也可以是tlabeljust=1;〃图名字的位置在left,也可以是redge[decorate=true]:C-D[label="sl"];C-E[label="s2”];C-F[label="s3"];D-E[label=”s4”];D-F[label=”s5”];edge[decorate=false,labelfontcolor=blue,fontcolor=red];Cl-D1[headlabel="c1",taillabel="dl'\label=”c1-d1)sis2I)riIloveyou〃在dot中我们可以用html语言写一个tableo在label后用v>而不是…就能引入html语言。

    1:digraphhlml{2:abc[shape二none,margin=0・label=v3:4:helloworld5:b6:g7:h&9:c10:dH:e12:13:vTRxTDCOLSPAN=H3n>f14:15:01234<7TR>1<7TR>2<7TR>3<7TR>vTRxTD>4<7TR>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;}}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="AI"];BElabel="BI"];C[label="CI"];DElabel="DI"];E[label="EI"];label=Binarysearchtree,z;nodeEshape=record];A:fO:swB:flA:f2:seC:flB:fO:swD:flB:f2:seE:flBmaiysearchhee〃构造一个HASH表1:digraphG{2:nodesep=.05;3:rankdir=LR;4:node[shape=record,width=.l.height=」];5:6:nodeO[label=Mkfl>l<12>kl3>IIII,\height=2.5];7:node[width=1.5):8:nodel[label=u{nl41719l}'*];9:node2[label=u{alI805kp>}'*];10:node3(label=H{i9l718Kp>}u];11:node4(label=”{e51989l}'*];12:node5(label="{1201959kp>}u];13:node6(label=”{vn>ol5I794kp>}n];14:node7(label=,,{sl91659l}'*];15:16:nodeO:f0->nodel:n;17:nodeOifl->node2:n;18:nodeO:f2->node3:n;19:nodeO:f5->node4:n;20:nodeO:f6->node5:n;21:node2:p->node6:n;22:node4:p->node7:n;23:}Figure17:Hashtablegraphfilenl4719al805i9718e5989t20959015794S19659Figure18:DrawingofhashtableFigure1&Drawingofhaslttable画一个子图就是subgraphcluster#,必须有cluster前缀。

    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-4Joranger

    点击阅读更多内容
    卖家[上传人]:小辰12
    资质:实名认证