gpt4 book ai didi

graphviz - 设置预定义的节点样式?

转载 作者:行者123 更新时间:2023-12-04 01:17:13 31 4
gpt4 key购买 nike

在过去的 15 分钟里,我一直在谷歌上搜索,试图找到这个问题的答案。但我似乎无法弄清楚。
我的任务是为我在工作中开发的一些应用程序构建一些小流程图。他们不需要任何花哨的东西,因为他们将在 vizio 中将其转换为他们喜欢的格式。他们甚至说我们可以用纸笔来做。所以我想我会玩弄graphviz/dot。
他们有 6 种他们喜欢使用的预定义形状/颜色,所以我想我会使用它们。我已经在 dot 中构建了它们……但是如果我打算多次重复使用它们,我想找到一种方法将它们保存为一种模板。
那可能吗?
例如...这些是预定义的形状。

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"];
}
Nodes produced from above code

最佳答案

不幸的是,没有办法定义宏或对象并重用——尤其是跨多个图形。但是,也有使用其他工具的方法。有些人使用 m4(宏语言)或 cpp(C 预处理器)两者都可以工作,但存在潜在的操作系统问题。 Python, awk, ... 也可以。
这是一个 gvpr 程序(gvpr 是 Graphviz 包的一部分),它也可以满足您的要求(我认为):

 digraph pre{
a [_type=process label="{1. Process\l | Something}"]
b [_type=process label="{2. Process\l | Something else}"]
c [_type=subprocess label="do it"]
d [_type=database label="lots of data"]
e [_type=database label="a bit of data"]
f [_type=inputoutput label="inOut"]
g [_type=file label="nail file"]
h [_type=external label="outside"]

a->b->c->d->e->f->g->h
}
gvpr 程序:
BEG_G{
$G.newrank="true";
}
N{
$.color="#4271C6"; // default
}
N[_type=="process"]{
$.shape="Mrecord";
$.style="filled";
$.fillcolor="#E1F4FF";
// maybe redo $.label
}
N[_type=="subprocess"]{
$.shape="record";
$.style="filled";
$.color="#FFFFFF";
$.fillcolor="#A5A5A5";
$.label=sprintf("|%s|", $.label); // embed in pipes
}
N[_type=="database"]{
$.shape="cylinder";
$.color="#18589A";
}
N[_type=="inputoutput"]{
$.shape="polygon";
$.style='filled';
$.fontcolor="white",
$.ixedsize="true";
$.skew="0.3";
$.margin="0";
$.width="2";
}
N[_type=="file"]{
$.shape="folder";
}
N[_type=="external"]{
$.shape="box3d";
}
产生:
enter image description here
目前 Windows 上的 gvpr 可能存在问题,但我知道开发团队正在解决这个问题
这是命令行:
gvpr -c -f 预定义.gvpr 预定义2.gv |点-Tpng > 预定义2.png

关于graphviz - 设置预定义的节点样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63140881/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com