CoderHG.iOS程序员IOS

DOT 学习笔记

2018-05-03  本文已影响11人  CoderHG

DOT 是程序员应该了解的一种代码绘图语言。

一、整体格式

digraph G {
      // 核心代码
}

如:

digraph G {
  A -> B1 -> C1;
  A -> B2 -> C2;
}

其效果是:


Study.dot.png

二、定义样式

2.1 标签样式

digraph G {
  # 定义样式
  A  [shape=box,label = "文本-A"];

  A -> B1 -> C1;
  A -> B2 -> C2;
}

效果如下:


study.dot.png

A 标签由之前的的椭圆变成矩形,同时显示文本更改。

2.2 箭头样式

digraph G {
  # 定义样式
  A  [shape=box,label = "文本-A"];
  # 箭头样式
  A -> B1 -> C1 [label=指令, color=red];
  A -> B2 -> C2;
}

效果如下:


study.dot.png

箭头变成红色,添加文本 指令

如果需要那种么有箭头的样式,那么是将 -> 换成 --, 其次还需要将关键字 digraph 换成 graph,代码如下:

graph G {
  # 定义样式
  A  [shape=box,label = "文本-A"];
  # 箭头样式
  A -- B1 -- C1 [label=指令, color=red];
  A -- B2 -- C2;
}

效果如下:


Study.dot.png

没有小箭头、就是一条线。

2.3 板块设计

代码如下:

digraph G {
  # 定义样式
  A  [shape=box,label = "文本-A"];
  # 箭头样式
  A -> B1 -> C1 [label=指令, color=red];
  A -> B2 -> C2;

  subgraph cluster_B3  {
    node [style=filled];
    B3 [shape=box, label="板块设计"]
    B3 -> C31 [label = 第一条子线];
    B3 -> C32 [label = 第二条子线, color = green];

    label = "B3板块";
    color=red;
  }

  A ->  B3;
  # A ->  cluster_B3; 无效
}

效果如下:


Study.dot.png

这是一个怪异的语法,subgraph 的名称一定要以 cluster 开头。

2.4 Tab设计

digraph G {
  # 定义样式
  A  [shape=box,label = "文本-A"];
  # 箭头样式
  A -> B1 -> C1 [label=指令, color=red];
  A -> B2 -> C2;

  subgraph cluster_B3 {
    node [style=filled];
    B3 [shape=box, label="板块设计"]
    B3 -> C31 [label = 第一条子线];
    B3 -> C32 [label = 第二条子线, color = green];

    label = "B3板块";
    color=red;
  }

  A ->  B3;


  subgraph cluster_B4 {
    B4 [shape=record, label="tab1|tab2|tab3|tab4"];
    B41 [shape=record, label="Home|Center"];
    b42 [shape=record, label="我是\nCoderHG|{A1|{A21|A22}|{A31|A32|A33}|A4|{A51|A52|A53|A54|A55}}|帅|美"]

    B4 -> B41;
    B4 -> b42

    label="Tab结构表";
    color = blue;
  }

  A -> B4
}

效果如下:


Study.dot.png

2.5 其它常用的属性

digraph G {
    fontColor [fontcolor=red, label="字体颜色"]

    fontSize  [fontsize=30, label="字体大小"]

    fillColor [style=filled, fillcolor=green, label="填充色"]

    fontColor -> fontSize;
    fontSize  ->  fillColor;
}

效果如下:


other.dot.png
以上应该就是比较常用的功能了
参考:

使用 dot 来绘图

上一篇下一篇

猜你喜欢

热点阅读