前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Graphviz dot 笔记

Graphviz dot 笔记

作者头像
zucchiniy
发布2020-05-22 12:05:19
1.7K0
发布2020-05-22 12:05:19
举报
文章被收录于专栏:洞明学问

Dot 生成图的默认命令

dot -T<type> -o <outfile> <infile.dot>

dot 可以替换为circo等其他算法,详细见命令的选择章节。

输入文件是 <infile.dot> ,生成的格式由 指定,生成的文件是 。其中 -T 包括:

代码语言:javascript
复制
-Tps (PostScript)
-Tsvg -Tsvgz (Structured Vector Graphics)
-Tfig (XFIG  graphics)
-Tmif  (FrameMaker graphics)
-Thpgl (HP pen plotters)
-Tpcl (Laserjet printers)
-Tpng -Tgif (bitmap graphics)
-Tdia (GTK+ based diagrams)
-Timap (imagemap files for httpd servers for each node or edge  that  has a non-null "href" attribute.)
-Tcmapx (client-side imagemap for use in html and xhtml)

rank

rank 约束了子图的节点位置,有向图中,一个箭头的指向,带有级别,一般是尾端高于尖端,即 a->b a 的级别要高于 b 的级别。

same : 所有节点在同一级别的节点处

min : 所有节点在最小级别节点处

source : 所有节点在最低级别,且只有子图属性为 source 或者 min 的时候,才能使用同样的级别

max : 类似于 source

sink : 类似于 source

NOTE: 最低级别,可以是 最上最下最左最右

rankdir

  • TB : top-to-bottom
  • LR : left-to-right
  • BT : bottom-to-top
  • RL : right-to-left

dot 线条

代码语言:javascript
复制
splines = ortho #直角拆线
splines = spline #曲线(不遮挡)
splines = cuvved #曲线(可遮挡)
splines = line #直线(可遮挡)
splines = polyline #直线(不遮挡)

命令的选择

命令

介绍

dot

渲染图具有明确的方向性

neato

图缺乏方向性

twopi

图采用放射性布局

circo

图采用环形布局

fdp

图缺乏方向性

sfdp

用来渲染大型图,且图片缺乏方向性

静默执行代码

代码语言:javascript
复制
(setq org-confirm-babel-evaluate nil) ;;执行静默语句块

dot 实例

  • 绘制流程图: digraph structs { node[shape=record] struct1 [label="<f0> left|<f1> mid\ dle|<f2> right"]; struct2 [label="{<f0> one|<f1> two\n\n\n}" shape=Mrecord]; struct3 [label="hello\nworld |{ b |{c|<here> d|e}| f}| g | h"]; struct1:f1 -> struct2:f0; struct1:f0 -> struct3:f1; }
代码语言:javascript
复制
  digraph g {
  size="8,6"
  ratio=expand
  edge [dir=both]
  plcnet [shape=box, label="plc network"]
  subgraph cluster_wrapline {
    label="wrapline control system"
    color=purple
    subgraph {
    rank=same
    exec
    sharedmem [style=filled, fillcolor=lightgrey, shape=box]
    }
    edge[style=dotted, dir=none]
    exec -> opserver
    exec -> db
    plc -> exec
    edge [style=line, dir=both]
    exec -> sharedmem
    sharedmem -> db
    plc -> sharedmem
    sharedmem -> opserver
  }
  plcnet -> plc [constraint=false]
  millwide [shape=box, label="millwide system"]
  db -> millwide
  subgraph cluster_opclients {
    color=blue
    label="operator client"
    rankdir=lr
    labelloc=b
    node[label=client]
    opserver -> client1
    opserver -> client2
    opserver -> client3
  }
}
代码语言:javascript
复制
digraph G {
rankdir=LR
node [shape=plaintext]
a [
label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
<TR><TD ROWSPAN="3" BGCOLOR="yellow">class</TD></TR>
<TR><TD PORT="here" BGCOLOR="lightblue">qualifier</TD></TR>
</TABLE>>
]
b [shape=ellipse style=filled
label=<
<TABLE BGCOLOR="bisque">
<TR><TD COLSPAN="3">elephant</TD>
<TD ROWSPAN="2" BGCOLOR="chartreuse"
VALIGN="bottom" ALIGN="right">two</TD> </TR>
<TR><TD COLSPAN="2" ROWSPAN="2">
<TABLE BGCOLOR="grey">
<TR> <TD>corn</TD> </TR>
<TR> <TD BGCOLOR="yellow">c</TD> </TR>
<TR> <TD>f</TD> </TR>
</TABLE> </TD>
<TD BGCOLOR="white">penguin</TD>
</TR>
<TR> <TD COLSPAN="2" BORDER="4" ALIGN="right" PORT="there">4</TD> </TR>
</TABLE>>
]
c [
label=<long line 1<BR/>line 2<BR ALIGN="LEFT"/>line 3<BR ALIGN="RIGHT"/>>
]
subgraph { rank=same b c }
a:here -> b:there [dir=both arrowtail = diamond]
c -> b
d [shape=triangle]
d -> c [label=<
<TABLE>
<TR><TD BGCOLOR="red" WIDTH="10"> </TD>
<TD>Edge labels<BR/>also</TD>
<TD BGCOLOR="blue" WIDTH="10"> </TD>
</TR>
</TABLE>>
]

}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-01-08,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Dot 生成图的默认命令
  • rank
  • rankdir
  • dot 线条
  • 命令的选择
  • 静默执行代码
  • dot 实例
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档