Graphviz

Graph visualization is a way of representing structural information as diagrams of abstract graphs and networks. Automatic graph drawing has many important applications in software engineering, database and web design, networking, and in visual interfaces for many other domains.

语法

http://www.graphviz.org/documentation/

操作入口

20190121202444.png

示例

Clusters

Graphviz - 图2

  1. digraph G {
  2.  
  3. subgraph cluster_0 {
  4. style=filled;
  5. color=lightgrey;
  6. node [style=filled,color=white];
  7. a0 -> a1 -> a2 -> a3;
  8. label = "process #1";
  9. }
  10.  
  11. subgraph cluster_1 {
  12. node [style=filled];
  13. b0 -> b1 -> b2 -> b3;
  14. label = "process #2";
  15. color=blue
  16. }
  17. start -> a0;
  18. start -> b0;
  19. a1 -> b3;
  20. b2 -> a3;
  21. a3 -> a0;
  22. a3 -> end;
  23. b3 -> end;
  24.  
  25. start [shape=Mdiamond];
  26. end [shape=Msquare];
  27. }

Data Structures

Graphviz - 图3

  1. digraph g {
  2. graph [
  3. rankdir = "LR"
  4. ];
  5. node [
  6. fontsize = "16"
  7. shape = "ellipse"
  8. ];
  9. edge [
  10. ];
  11. "node0" [
  12. label = "<f0> 0x10ba8| <f1>"
  13. shape = "record"
  14. ];
  15. "node1" [
  16. label = "<f0> 0xf7fc4380| <f1> | <f2> |-1"
  17. shape = "record"
  18. ];
  19. "node2" [
  20. label = "<f0> 0xf7fc44b8| | |2"
  21. shape = "record"
  22. ];
  23. "node3" [
  24. label = "<f0> 3.43322790286038071e-06|44.79998779296875|0"
  25. shape = "record"
  26. ];
  27. "node4" [
  28. label = "<f0> 0xf7fc4380| <f1> | <f2> |2"
  29. shape = "record"
  30. ];
  31. "node5" [
  32. label = "<f0> (nil)| | |-1"
  33. shape = "record"
  34. ];
  35. "node6" [
  36. label = "<f0> 0xf7fc4380| <f1> | <f2> |1"
  37. shape = "record"
  38. ];
  39. "node7" [
  40. label = "<f0> 0xf7fc4380| <f1> | <f2> |2"
  41. shape = "record"
  42. ];
  43. "node8" [
  44. label = "<f0> (nil)| | |-1"
  45. shape = "record"
  46. ];
  47. "node9" [
  48. label = "<f0> (nil)| | |-1"
  49. shape = "record"
  50. ];
  51. "node10" [
  52. label = "<f0> (nil)| <f1> | <f2> |-1"
  53. shape = "record"
  54. ];
  55. "node11" [
  56. label = "<f0> (nil)| <f1> | <f2> |-1"
  57. shape = "record"
  58. ];
  59. "node12" [
  60. label = "<f0> 0xf7fc43e0| | |1"
  61. shape = "record"
  62. ];
  63. "node0":f0 -> "node1":f0 [
  64. id = 0
  65. ];
  66. "node0":f1 -> "node2":f0 [
  67. id = 1
  68. ];
  69. "node1":f0 -> "node3":f0 [
  70. id = 2
  71. ];
  72. "node1":f1 -> "node4":f0 [
  73. id = 3
  74. ];
  75. "node1":f2 -> "node5":f0 [
  76. id = 4
  77. ];
  78. "node4":f0 -> "node3":f0 [
  79. id = 5
  80. ];
  81. "node4":f1 -> "node6":f0 [
  82. id = 6
  83. ];
  84. "node4":f2 -> "node10":f0 [
  85. id = 7
  86. ];
  87. "node6":f0 -> "node3":f0 [
  88. id = 8
  89. ];
  90. "node6":f1 -> "node7":f0 [
  91. id = 9
  92. ];
  93. "node6":f2 -> "node9":f0 [
  94. id = 10
  95. ];
  96. "node7":f0 -> "node3":f0 [
  97. id = 11
  98. ];
  99. "node7":f1 -> "node1":f0 [
  100. id = 12
  101. ];
  102. "node7":f2 -> "node8":f0 [
  103. id = 13
  104. ];
  105. "node10":f1 -> "node11":f0 [
  106. id = 14
  107. ];
  108. "node10":f2 -> "node12":f0 [
  109. id = 15
  110. ];
  111. "node11":f2 -> "node1":f0 [
  112. id = 16
  113. ];
  114. }

fsm

Graphviz - 图4

  1. digraph finite_state_machine {
  2. rankdir=LR;
  3. size="8,5"
  4. node [shape = doublecircle]; LR_0 LR_3 LR_4 LR_8;
  5. node [shape = circle];
  6. LR_0 -> LR_2 [ label = "SS(B)" ];
  7. LR_0 -> LR_1 [ label = "SS(S)" ];
  8. LR_1 -> LR_3 [ label = "S($end)" ];
  9. LR_2 -> LR_6 [ label = "SS(b)" ];
  10. LR_2 -> LR_5 [ label = "SS(a)" ];
  11. LR_2 -> LR_4 [ label = "S(A)" ];
  12. LR_5 -> LR_7 [ label = "S(b)" ];
  13. LR_5 -> LR_5 [ label = "S(a)" ];
  14. LR_6 -> LR_6 [ label = "S(b)" ];
  15. LR_6 -> LR_5 [ label = "S(a)" ];
  16. LR_7 -> LR_8 [ label = "S(b)" ];
  17. LR_7 -> LR_5 [ label = "S(a)" ];
  18. LR_8 -> LR_6 [ label = "S(b)" ];
  19. LR_8 -> LR_5 [ label = "S(a)" ];
  20. }

UNIX Family 'Tree'

Graphviz - 图5

  1. /* courtesy Ian Darwin and Geoff Collyer, Softquad Inc. */
  2. digraph unix {
  3. size="6,6";
  4. node [color=lightblue2, style=filled];
  5. "5th Edition" -> "6th Edition";
  6. "5th Edition" -> "PWB 1.0";
  7. "6th Edition" -> "LSX";
  8. "6th Edition" -> "1 BSD";
  9. "6th Edition" -> "Mini Unix";
  10. "6th Edition" -> "Wollongong";
  11. "6th Edition" -> "Interdata";
  12. "Interdata" -> "Unix/TS 3.0";
  13. "Interdata" -> "PWB 2.0";
  14. "Interdata" -> "7th Edition";
  15. "7th Edition" -> "8th Edition";
  16. "7th Edition" -> "32V";
  17. "7th Edition" -> "V7M";
  18. "7th Edition" -> "Ultrix-11";
  19. "7th Edition" -> "Xenix";
  20. "7th Edition" -> "UniPlus+";
  21. "V7M" -> "Ultrix-11";
  22. "8th Edition" -> "9th Edition";
  23. "1 BSD" -> "2 BSD";
  24. "2 BSD" -> "2.8 BSD";
  25. "2.8 BSD" -> "Ultrix-11";
  26. "2.8 BSD" -> "2.9 BSD";
  27. "32V" -> "3 BSD";
  28. "3 BSD" -> "4 BSD";
  29. "4 BSD" -> "4.1 BSD";
  30. "4.1 BSD" -> "4.2 BSD";
  31. "4.1 BSD" -> "2.8 BSD";
  32. "4.1 BSD" -> "8th Edition";
  33. "4.2 BSD" -> "4.3 BSD";
  34. "4.2 BSD" -> "Ultrix-32";
  35. "PWB 1.0" -> "PWB 1.2";
  36. "PWB 1.0" -> "USG 1.0";
  37. "PWB 1.2" -> "PWB 2.0";
  38. "USG 1.0" -> "CB Unix 1";
  39. "USG 1.0" -> "USG 2.0";
  40. "CB Unix 1" -> "CB Unix 2";
  41. "CB Unix 2" -> "CB Unix 3";
  42. "CB Unix 3" -> "Unix/TS++";
  43. "CB Unix 3" -> "PDP-11 Sys V";
  44. "USG 2.0" -> "USG 3.0";
  45. "USG 3.0" -> "Unix/TS 3.0";
  46. "PWB 2.0" -> "Unix/TS 3.0";
  47. "Unix/TS 1.0" -> "Unix/TS 3.0";
  48. "Unix/TS 3.0" -> "TS 4.0";
  49. "Unix/TS++" -> "TS 4.0";
  50. "CB Unix 3" -> "TS 4.0";
  51. "TS 4.0" -> "System V.0";
  52. "System V.0" -> "System V.2";
  53. "System V.2" -> "System V.3";
  54. }

world

Graphviz - 图6

  1. digraph world {
  2. size="7,7";
  3. {rank=same; S8 S24 S1 S35 S30;}
  4. {rank=same; T8 T24 T1 T35 T30;}
  5. {rank=same; 43 37 36 10 2;}
  6. {rank=same; 25 9 38 40 13 17 12 18;}
  7. {rank=same; 26 42 11 3 33 19 39 14 16;}
  8. {rank=same; 4 31 34 21 41 28 20;}
  9. {rank=same; 27 5 22 32 29 15;}
  10. {rank=same; 6 23;}
  11. {rank=same; 7;}
  12.  
  13. S8 -> 9;
  14. S24 -> 25;
  15. S24 -> 27;
  16. S1 -> 2;
  17. S1 -> 10;
  18. S35 -> 43;
  19. S35 -> 36;
  20. S30 -> 31;
  21. S30 -> 33;
  22. 9 -> 42;
  23. 9 -> T1;
  24. 25 -> T1;
  25. 25 -> 26;
  26. 27 -> T24;
  27. 2 -> {3 ; 16 ; 17 ; T1 ; 18}
  28. 10 -> { 11 ; 14 ; T1 ; 13; 12;}
  29. 31 -> T1;
  30. 31 -> 32;
  31. 33 -> T30;
  32. 33 -> 34;
  33. 42 -> 4;
  34. 26 -> 4;
  35. 3 -> 4;
  36. 16 -> 15;
  37. 17 -> 19;
  38. 18 -> 29;
  39. 11 -> 4;
  40. 14 -> 15;
  41. 37 -> {39 ; 41 ; 38 ; 40;}
  42. 13 -> 19;
  43. 12 -> 29;
  44. 43 -> 38;
  45. 43 -> 40;
  46. 36 -> 19;
  47. 32 -> 23;
  48. 34 -> 29;
  49. 39 -> 15;
  50. 41 -> 29;
  51. 38 -> 4;
  52. 40 -> 19;
  53. 4 -> 5;
  54. 19 -> {21 ; 20 ; 28;}
  55. 5 -> {6 ; T35 ; 23;}
  56. 21 -> 22;
  57. 20 -> 15;
  58. 28 -> 29;
  59. 6 -> 7;
  60. 15 -> T1;
  61. 22 -> T35;
  62. 22 -> 23;
  63. 29 -> T30;
  64. 7 -> T8;
  65. 23 -> T24;
  66. 23 -> T1;
  67. }

Entity-Relation Data Model

Layouts made with neato have the property that all edges tend to have about the same length (unless there is a manual adjustment). By default neato uses randomization, so it makes a different layout each time, but this particular example almost always look well. Edge labels are placed at the edge's midpoint.

https://graphviz.gitlab.io/_pages/Gallery/undirected/ER.html

Graphviz - 图7

  1. graph ER {
  2. node [shape=box]; course; institute; student;
  3. node [shape=ellipse]; {node [label="name"] name0; name1; name2;}
  4. code; grade; number;
  5. node [shape=diamond,style=filled,color=lightgrey]; "C-I"; "S-C"; "S-I";
  6.  
  7. name0 -- course;
  8. code -- course;
  9. course -- "C-I" [label="n",len=1.00];
  10. "C-I" -- institute [label="1",len=1.00];
  11. institute -- name1;
  12. institute -- "S-I" [label="1",len=1.00];
  13. "S-I" -- student [label="n",len=1.00];
  14. student -- grade;
  15. student -- name2;
  16. student -- number;
  17. student -- "S-C" [label="m",len=1.00];
  18. "S-C" -- course [label="n",len=1.00];
  19.  
  20. label = "\n\nEntity Relation Diagram\ndrawn by NEATO";
  21. fontsize=20;
  22. }

若有收获,就赏束稻谷吧

0 颗稻谷