在过去的 15 分钟里,我一直在谷歌上搜索,试图找到这个问题的答案。但我似乎无法弄清楚。
我的任务是为我在工作中开发的一些应用程序构建一些小流程图。他们不需要任何花哨的东西,因为他们将在 vizio 中将其转换为他们喜欢的格式。他们甚至说我们可以用笔和纸来做。所以我想我应该玩一下 graphviz/dot。
他们有 6 种喜欢使用的预定义形状/颜色,所以我想我会使用它们。我已经用点构建了它们......但是如果我打算多次重复使用它们,我想找到一种方法将它们保存为某种模板。
那可能吗?
例如...这些是预定义的形状。
digraph G {
node [color="#4271C6"]
process [
shape=Mrecord,
style=filled, fillcolor="#E1F4FF",
label="{1. Process\l | Description}"];
subprocess [
shape=record,
style=filled, color="#FFFFFF", fillcolor="#A5A5A5",
label="| Sub-Process |"];
database [
shape=cylinder, color="#18589A",
label="Database"];
inputoutput [
shape=polygon,
style=filled, fontcolor=white,
fixedsize=true, skew=0.3, margin=0,
width=2, label="Input / Output"];
file [
shape=folder,
label="File"];
external [
shape=box3d,
label="External entity"];
}
Run Code Online (Sandbox Code Playgroud)
好吧,所以我想通了。我没有意识到你可以这样做......但显然你可以将节点定义分解为多个部分......所以这就是我想出的,它解决了我的问题......
我有一个位于顶部的“样式”部分。在这里我可以定义每个节点的样式。我使用注释作为命名它们的方式。而且我不需要复制粘贴,因为我可以将多个节点定义为逗号分隔的列表。
我还发现您也可以将它们放入子图中,例如subgraph style_file {...}. 但仅使用注释作为命名样式的方式似乎更简单。
digraph G {
newrank=true;
///////////////////////////////////////////////////////////
// Styles
///////////////////////////////////////////////////////////
node [color="#4271C6"];
edge [color="#4271C6"];
//process
createfile, uploadfile
[shape=Mrecord, style=filled, fillcolor="#E1F4FF"];
//subprocess
exportfile, wait
[shape=record, style=filled, color="#FFFFFF", fillcolor="#A5A5A5"];
//external
ftp
[shape=box3d];
//datastore
database
[shape=cylinder, color="#18589A"];
//io
exportproc
[shape=polygon, style=filled, fontcolor=white, margin=0, width=3.1, fixedsize=true, skew=0.3];
//file
workfile
[shape=folder];
///////////////////////////////////////////////////////////
// Clusters
///////////////////////////////////////////////////////////
subgraph cluster_0 {
createfile [label="{1. Process\l | Create file}"];
exportfile [label="|Export Data\nfrom DB|"];
database [label="Database"];
exportproc [label="Export Data"];
workfile [label="Generated file\n(Archived on server)"];
}
subgraph cluster_1 {
uploadfile [label="{2. Process\l | Upload file}"];
ftp [label="FTP Server"];
wait [label="|Wait for\nresponse file|"];
}
///////////////////////////////////////////////////////////
// Relationships
///////////////////////////////////////////////////////////
{
rank=same;
createfile;
uploadfile;
}
///////////////////////////////////////////////////////////
// Relationships
///////////////////////////////////////////////////////////
# cluster_0
createfile -> exportfile;
exportfile -> database;
database -> exportproc;
exportproc -> workfile [style=dashed];
workfile -> uploadfile;
# cluster_1
uploadfile -> ftp [style=dashed];
ftp -> wait;
}
Run Code Online (Sandbox Code Playgroud)
产生这个: