Graphviz

DOT Language 主要有三種對象: 圖 graph, 邊 edge, 節(jié)點 node;
其中graph 又包括有向圖(directed graph) digraph 和 無向圖graph;
在圖內,{} 大括號中定義的內容(節(jié)點和邊)叫做 subgraph

DotLanguage.jpg
digraph dotLanguage{ 
  "DOT Language" -> {"graph" , "edge", "node"};
  "graph" -> {"digraph", "graph "};
} 
  • 當ID(Name/名稱)含有關鍵字或空白字符時要使用雙引號括起來
  • 結尾的分號 ; 可要可不要

Graphviz

軟件下載

  • 將包含 Graphviz 可執(zhí)行文件的目錄 D:\Graphviz2.38\bin 添加到環(huán)境變量 Path

  • 選擇 Layout 預覽結果

    layout.PNG

  • 在命令行窗口執(zhí)行命令生成 jpg 圖片: dot -Tjpg DotLanguage.gv -o DotLanguage.jpg


小示例

smallGraph.jpg
digraph G {
  main -> init -> make_string;
  main -> {parse, cleanup};
  main -> printf;
  parse -> execute -> {make_string, compare, printf};
}
  • 節(jié)點名 創(chuàng)建節(jié)點
  • -> 創(chuàng)建有向邊,-- 創(chuàng)建無向邊

屬性

attr.jpg
digraph G {
  /* 一個示例的圖 */
  /* 節(jié)點和邊的屬性定義在方括號中 */

  size = "4, 4";  # 設置圖的大小(4, 4 inches) 太大的尺寸會自動調整成合適的大小
  main -> parse [weight=8]; # 設置邊的權重(默認為1),增加權重使邊變值并且位于正中間
  main [shapde=box];
  parse -> execute;
  main -> init [style=dotted];
  main -> cleanup;
  execute -> {make_string; printf}; # 同時指向兩個節(jié)點
  init -> make_string;
  edge [color=red]; # 下面創(chuàng)建的邊都為紅色
  main -> printf [style=bold, label="100 times"];
  make_string [label="make a \nstring"];
  node [shape=box, style=filled, color=".7 .3 1.0"]; # 為下面下面創(chuàng)建的節(jié)點設置默認屬性
  execute -> compare;
}
  • 屬性直接寫出來 --> 為圖設置屬性
  • 節(jié)點和邊的屬性定義在方括號中
  • 同時指向多個節(jié)點可以用 {} 大括號表示,用 分號 分隔
  • 屬性用 逗號 分隔,
  • 關鍵字 node 為后面創(chuàng)建的節(jié)點設置默認屬性,edge 為后面的邊設置默認屬性

常用屬性

dot_01.jpg
dot_02.jpg
dot_03.jpg

Node 屬性

  • shape = box | circle | record | plaintext | point

node_shapes.jpg
digraph NodeShape {
  node_shape [label="Node Shape"]
  polygon_base [label="polygon-base"]
  record_base [label="record-base"]

  node_shape -> {polygon_base; record_base}
  polygon_base -> "all others node shapes"
  record_base -> {"record"; "Mrecord"}
} 
  • Node Shapes 分為兩大類:polygon-base 和 record-base;
  • 除了 record 和 Mrecord 外,其他都是 polygon ,可以設置 polygon 屬性,比如 sides (circle, ellipse 除外)
  • regular=true 強制設置形狀為矩形
  • 節(jié)點的大小默認是大于里面文字所需的空間,fixedsize=true 強制 widthheight 屬性

polygon-base 多邊形

peripheries & orientation
peripheries_orientation.jpg
digraph G {
  a[shape=polygon, sides=5, peripheries=3,color=lightblue, style=filled, label="peripheries=3", width=1, height=2]
  b[shape=polygon, orientation=45, label="orientation=45°", width=1, height=2]
}

distortion & skew
digraph G {
  origin [shape=polygon]
  a[shape=polygon, distortion=.1, label="polygon\ndistortion: .1"]
  b[shape=polygon, distortion=.9, label="polygon\ndistortion: .9"]
  c[shape=polygon, distortion=-.9, label="polygon\ndistortion: -.9"]
  s1[shape=polygon, skew=.1, label="polygon\nskew=.1"]
  s2[shape=polygon, skew=.9, label="polygon\nskew=.9"]
  s3[shape=polygon, skew=-.9, label="polygon\nskew=-.9"]
  
  a -> b -> c
  s1 -> s2 -> s3
}
polygon.jpg
  • distortion : 正數(shù)從上向下縮?。ㄌ菪危?/li>
  • skew: 傾斜程度,正數(shù)頂部向右移動(平行四邊形)

record-base

record 和 Mrecord 的區(qū)別是 Mrecord 時圓角的;

record_example.jpg
digraph structs {
  node [shape=record]
  struct1 [shape=record, label="<f0> left|<f1> mid\ dle|<f2> right"];
  struct2 [shape=record, label="<f0> one|<f1> two"];
  struct3 [shape=record, label="hello\nworld |{ b |{c|<here> d|e}| f}| g | h"];
}
  • record 里面的結構由屬性 label 定義
  • record 用于表示一系列可嵌套的項(field)
  • 項由 <name>"field string label" 組成
  • 項之間用 | 分隔
  • 嵌套項用 {} 表示,嵌套表示為平行/垂直相減的項

在節(jié)點中,label 默認時節(jié)點的名稱

record.jpg

field.jpg
digraph Field {
    main [shape=record, label="{field | {\<name\>\ optional | field\ string\ label}}"]
}
  • 項由 <name>"field string label" 組成

由于項定在 label 屬性中,所以在創(chuàng)建項時使用 " 雙引號時會和 label ,因此不能直接使用雙引號,而是 轉義序列 空格,<>{}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

  • <一> graphviz dot 使用步驟 安裝graphvizbrew install graphviz (ma...
    元亨利貞o閱讀 25,401評論 9 24
  • graphviz 畫流程圖 brew install graphvizvi lz.dot dot -Tjpg lz...
    神刀閱讀 3,705評論 0 0
  • brew install graphvizvi lz.dot dot -Tjpg lz3.dot -o lz3.j...
    神刀閱讀 2,723評論 0 0
  • Spring Cloud為開發(fā)人員提供了快速構建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,525評論 19 139
  • 技能的意義是建立在這樣的關系上的:相對于增加個人利益,要更重視向客戶交付價值。羅胖曰:我們來翻譯一下作者講的道理—...
    過河卒閱讀 295評論 0 2

友情鏈接更多精彩內容