为什么选择 Graphviz
总找不到一个称心如意的绘图工具。
很早就知道Graphviz,但感觉不易用就没怎么用它。
最近在写Markdown的时候,图片编辑让我头疼。
怎样让图片也能像文本一样编辑呢? 答案就是 Dot 转 Svg
操作方法
先搜索 Graphviz和Dot了解一下基础知识
然后安装 Graphviz 和 DotEditor (推荐)
如果你以绘图为生,可以选择其它编辑器(比如 VSCode、Atom 依个人所好)
Dot语言有好多属性,笔者脑子记不住也不打算记。所以开启 DotEditor 如下图:
简单入门
Dot分“有方向/Digraph”和“无方向/Graph”图
Node代表节点,Edge代表连线
在 DotEditor 上可以方便的添加节点、连接和修改属性
可惜 Oschina 的 Markdown 阉割了一些功能,无法直接嵌入 Svg 代码
使用 DotEditor 可以导出 Svg 文件,或者以 Windows 为例,用Graphviz命令行转换:
D:\App\Graphviz2.38\bin\dot.exe -Tsvg DotEditor.dot -o demo.svg
源码分享
digraph DeployRule {
fontname="monospace";
colorscheme="svg";
edge [comment="全局默认设定",
fontname="sans-serif",
fontsize=10,
colorscheme="blues3",
color=2,
fontcolor=3];
node [fontname="serif",
fontsize=13,
fillcolor="1",
colorscheme="blues4",
color="2",
fontcolor="4",
style="filled"];
"工单系统" [comment="以工单为新项目部署的流程入口",
URL="https://www.tapd.cn",
shape="hexagon",
target="_blank",
color="blue",
label="工单系统"];
"操作人员" [label="操作人员"];
subgraph "cluster0" {
label="发布系统v1.0";
"Ansible" [shape="circle",style="diagonals",label="Ansible"];
"Gitlab代码库" [shape="circle",style="diagonals",label="Gitlab代码库"];
"Ftp文件共享" [shape="circle",style="diagonals",label="Ftp文件共享"];
subgraph "cluster01" {
label="测试环境";
"功能测试环境" [shape="box3d",label="功能测试环境"];
"集成测试环境" [shape="box3d",label="集成测试环境"];
"OpsMng-测试环境" [label="OpsMng-测试环境"];
"Jenkins-测试环境" [label="Jenkins-测试环境"];
"OpsMng-测试环境" -> "Jenkins-测试环境" [style="dotted",label="构建任务"];
}
subgraph "cluster02" {
center="true";
label="生产环境";
"预发布环境" [shape="box3d",label="预发布环境"];
"线上生产环境" [shape="box3d",label="线上生成环境"];
"Jenkins-生产环境" [label="Jenkins-生产环境"];
"OpsMng-生产环境" [label="OpsMng-生产环境"];
"OpsMng-生产环境" -> "Jenkins-生产环境" [style="dotted",label="构建任务"];
}
"Gitlab代码库" -> "Ansible" [style="dashed",label="拉取"];
"Gitlab代码库" -> "Jenkins-测试环境" [style="dashed",label="拉取"];
"Gitlab代码库" -> "Jenkins-生产环境" [style="dashed",label="拉取"];
"Ftp文件共享" -> "Ansible" [style="dashed",label="拉取"];
"OpsMng-测试环境" -> "Ansible" [color="blue",style="bold",label="发布"];
"OpsMng-生产环境" -> "Ansible" [color="blue",style="bold",label="发布"];
"Jenkins-测试环境" -> "Ftp文件共享" [style="dotted",label="推送"];
"Jenkins-生产环境" -> "Ftp文件共享" [style="dotted",label="推送"];
"Ansible" -> "功能测试环境" [color="blue",label="部署"];
"Ansible" -> "线上生产环境" [color="blue",label="部署"];
"Ansible" -> "集成测试环境" [color="blue",label="部署"];
"Ansible" -> "预发布环境" [color="blue",label="部署"];
{
rank=same;
"预发布环境";
"线上生产环境";
"功能测试环境";
"集成测试环境";
}
{
rank=same;
"Gitlab代码库";
"Ftp文件共享";
}
}
subgraph "cluster1" {center="true";label="发布系统v2.0";}
"工单系统" -> "操作人员" [label="审批"];
"操作人员" -> "OpsMng-测试环境" [color="blue",style="bold",label="管理发布"];
"操作人员" -> "OpsMng-生产环境" [color="blue",style="bold",label="管理发布"];
}