Graphviz dot画图学习
Dot是开源工具包Graphviz上用来画图的一门脚本语言。通过布局引擎解析脚本得到图像,然后可以将图像导出为各种格式以满足需求,有了它,我们就可以很方便地通过编写脚本来画各种结构示意图和流程图。 常用关键字:
- graph:定义当前图属性
- node:定义各结点属性,如fontname
- subgraph:定义子图,需要以cluster开头,否则引擎不识别
digraph service_map { graph [dpi="300"]; node [color="gray";shape="record";fontname="Microsoft YaHei"]; label="Service Map"; Request; github_pages [label="GitHub Pages"]; subgraph cluster_web{ label="Web front end server"; nginx [label="Reverse Proxy Server"]; docker [label="Docker Container Manager"]; } subgraph cluster_docker{ label="Docker Container Manager"; openproject [label="OpenProject"]; gitlab [label="GitLab"]; wordpress [label="WordPress"]; mysql [label="Common Mysql Database"]; } subgraph cluster_filesystem{ label="Mount at where"; openproject_mnt [label="/opt/openproject/data:/var/lib/postgresql/9.6/main\l\n/opt/openproject/logs:/var/log/supervisor\l\n/opt/openproject/static:/var/db/openproject\l"]; gitlab_mnt [label="/opt/gitlab/config:/etc/gitlab\l\n/opt/gitlab/logs:/var/log/gitlab\l\n/opt/gitlab/data:/var/opt/gitlab\l"]; wordpress_mnt [label="/opt/wordpress/www:/var/www/html"]; mysql_mnt [label="/opt/mysql/data:/var/lib/mysql"]; } Request->nginx; nginx->docker; nginx->github_pages; docker->wordpress [label="hostname=wordpress.endercaster.com"]; docker->openproject [label="hostname=openproject.endercaster.com"]; docker->gitlab [label="hostname=gitlab.endercaster.com"]; wordpress->mysql; wordpress->wordpress_mnt [label="mount"]; openproject->openproject_mnt [label="mount"]; gitlab->gitlab_mnt [label="mount"]; mysql->mysql_mnt [label="mount"]; }
上述代码生成如下图片