【问题标题】:best way to originate a graph with graphviz使用 graphviz 生成图形的最佳方法
【发布时间】:2020-06-16 19:37:06
【问题描述】:

这是我在这里的第一篇文章,我不确定它是否属于正确的子。

假设我们在某些数据结构中定义了以下工作流:

使用以下信息绘制此有向图的最佳方法是什么:

  • 节点有2种(矩形最多1进1出,菱形最多2进2出
  • 给出初始节点和最终节点
  • 节点(边)之间的链接是已知的

我使用此信息生成的代码如下图:

我在这里错过了什么?

Edit1:添加源代码

digraph flow_view {
rankdir = TB;  
graph[fontsize="22"];
node [shape="box", fontsize="11.0", style="filled", fillcolor="peachpuff", fontcolor="black"];
 "Case created" [fillcolor="seagreen1"];
 "Case created" -> "Case assigned" ; 
 "Case assigned" -> "Case review and initial analysis" ; 
 "Case review and initial analysis" -> "Further action required?" ; 
 "Close case" [fillcolor="lightpink"];
 "Further action required?" -> "Close case"[label="No", fontsize="8.5"]
 "Further action required?" [shape="diamond", fillcolor="peachpuff"] ; 
 "Further action required?" -> "Further work"[label="Yes", fontsize="8.5"]
 "Further action required?" [shape="diamond", fillcolor="peachpuff"] ; 
 "Close case" [fillcolor="lightpink"];
 "Satisfactory explanations?" -> "Close case"[label="Yes", fontsize="8.5"]
 "Satisfactory explanations?" [shape="diamond", fillcolor="peachpuff"] ; 
 "Case escalated / reassigned" -> "Further action required?" ; 
 "Satisfactory explanations?" -> "Case escalated / reassigned"[label="No", fontsize="8.5"]
 "Satisfactory explanations?" [shape="diamond", fillcolor="peachpuff"] ; 
 "Further work" -> "Satisfactory explanations?" ; 
}

【问题讨论】:

  • 预期图和实际图之间的差异对您来说究竟是个问题?颜色?图形风格?角度?位置?字体和换行符?还显示您到目前为止尝试的点源代码。
  • 这主要是位置:我尝试创建一个集群并使用 rank = same,添加不可见的节点,但它很快变得无法扩展其他元数据(即,如果我们添加一些节点,我们不能重复使用完全相同的代码生成算法)
  • 这是我得到的最好的代码,但远非最佳,它是反复试验,没有背后的逻辑
  • 为什么图必须完全一致?我没有很好的经验说graphviz如何准确地渲染任何图形。对于一般数据,任何对一个实例的特定黑客帮助都会对另一个实例造成伤害。 graphviz 设计的布局对我来说看起来也更合乎逻辑,因为如果不一定必须向上流动,则没有边缘向上流动。您可以使用splines=ortho 对其进行美化。或者尝试不同的工具,我对flowchart.js.org 有很好的经验。
  • 这种布局看起来更简单.. splines=ortho 在这里没有多大帮助

标签: graphviz dot


【解决方案1】:

我设法调整它以匹配您的示例图像,但不确定它的可扩展性如何。 我大致做了以下事情:

  • 结构化代码(只是为了便于阅读):
    • 根据形状首先在两组中定义节点
    • 第二个边缘定义
    • 按照图形顺序的语法中的有序连接
    • 添加了 fontsize 定义作为全局边缘属性而不是每个连接
  • 添加了一些格式调整(可选)
    • 添加了更现代的字体(Arial)
    • 使背景透明,以防导出为 png。
  • portPos 用于某些节点(例如"Further work":s)。这表明节点的哪一侧(north,east,south,west)边缘应该连接。
  • 为某些连接添加了constraint=false。这表明在订购节点时不应考虑该连接。
  • 为两组节点添加了rank=same
  • 添加了weight 以缩短/拉直一些边缘
digraph flow_view {
rankdir = TB;
splines=splines
graph[fontsize="22", bgcolor="transparent", fontname="Arial"];
//Node definition
node [shape="box", fontsize="11.0", style="filled", fillcolor="peachpuff", fontcolor="black", fontname="Arial"];
    "Case created"               [ fillcolor="seagreen1"];
    "Close case"                 [ fillcolor="lightpink"];
    "Case assigned"
    "Case review and initial analysis"
    "Further work"
    "Case escalated / reassigned"
 node [shape="diamond"];
    "Further action required?"  
    "Satisfactory explanations?"
// Chart definition
edge [fontsize="8.5", fontname="Arial"]
    "Case created"                     -> "Case assigned" ;
    "Case assigned"                    -> "Case review and initial analysis" ;
    "Case review and initial analysis" -> "Further action required?" ;
    "Further action required?":w       -> "Close case":e[label="No", weight=100000, constraint=false]
    "Further action required?":s       -> "Further work":n[label="Yes", weight=10]
    "Further work":s                   -> "Satisfactory explanations?":n [weight=10] ;
    "Satisfactory explanations?":w     -> "Close case":s[label="Yes"]
    "Satisfactory explanations?"       -> "Case escalated / reassigned"[label="No"]
    "Case escalated / reassigned":n    -> "Further action required?":e
// Tweaks
{rank=same "Further action required?";"Close case"}
{rank=same "Satisfactory explanations?";"Case escalated / reassigned"}
}

【讨论】:

    猜你喜欢
    • 2013-04-16
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    • 2011-09-23
    • 2013-01-29
    • 2016-05-24
    • 2011-05-18
    • 1970-01-01
    相关资源
    最近更新 更多