Graphviz:创建三个簇中节点之间具有直边的流程图

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Graphviz:创建三个簇中节点之间具有直边的流程图相关的知识,希望对你有一定的参考价值。

我正在尝试重新创建此区块链流程图

Do you need blockchain?

即使将边缘权重设置为100并使用不可见节点,我也无法将某些边缘设为水平边缘。我写的代码如下。在此过程中,我创建了三个群集,在其中两个群集中(第2个和第3d个),我在节点之间放置了虚假边。

digraph S {
    rankdir=TB

    subgraph cluster1 {
            graph [style="invis"]
            rank="same"

     node [fixedsize="true", width="3", height="1", shape="diamond", style="filled"]
     A [label="Is multi-party
required?", fillcolor=""]
     B [label="Is trusted_authority
required?", fillcolor=""]
     C [label="Is operation
centralized?", fillcolor=""]
     D [label="Is immutability
required?", fillcolor=""]
     E [label="Is high performace
required?", fillcolor=""]
     F [label="Is transparency
required?", fillcolor=""]

     A -> B [label="Yes"]
     B -> C [label="No"]
     C -> D [label="No"]
     D -> E [label="Yes"]
     E -> F [label="No"]

    }


subgraph cluster2 {
     graph [style="invis"]
     rank="same"

     node [shape="diamond", fixedsize="true", width="3", height="1", style="filled"]

     P [label="Is trusted authority
decentralizable", fillcolor=""]
     P1 [style="invis"]
     P2 [style="invis"] 
     Q [label="Can big data be
stored off-chain", fillcolor=""]
     R [label="Can encrypted data
be shared", fillcolor=""]

     P -> P1 -> P2 -> Q -> R [style="invis", dir="none"]
   }                           

     B -> P [label="Yes", weight=200]
     P -> C [label="Yes"]
     E -> Q [label="Yes", weight=1]
     Q -> F [label="Yes"]
     F -> R [label="No", weight=1]


subgraph cluster3 {
     graph [style="invis"]
     rank="same"

     node [shape="box", style="filled"]
     X [label="Consider Conventional
Database", fillcolor=""]
     Y [label="Consider Blockchain", fillcolor=""]
     Z [label="Consider DLTs", fillcolor=""]

     X -> Y -> Z [style="invis", dir="none"]
}

     A -> X [label="No"]
     P -> X [label="No", weight=100]
     C -> X [label="Yes", weight=200]
     D -> X [label="No"]

     Q -> X [label="No"]
     F -> Y [label="Yes"]

     R -> Y [label="Yes"]
     R -> Z [label="No", weight=100] 
}

但是,即使修改了不同的weights并将constraints设置为false,第三个簇也始终位于前两个簇之间。或者第一个群集(应该是最左侧的群集)位于中间。

这里是输出之一。

Output received

砝码无法正常工作。我想念什么吗?请帮忙!谢谢

答案

我已经接近了,但是需要两个步骤才能到达那里。1.将以下内容另存为myfile.gv,然后运行dot -tdot myfile.gv> myfile.dot固定节点]

digraph S {
  graph [splines=polyline compound=true]

  subgraph clusterA {
     graph [style="invis" margin=30]
     rank="min"

     node [fixedsize="true", width="3", height="1", shape="diamond", style="filled"]
     A [label="Is multi-party
required?", fillcolor=""]
     B [label="Is trusted_authority
required?", fillcolor=""]
     C [label="Is operation
centralized?", fillcolor=""]
     D [label="Is immutability
required?", fillcolor=""]
     E [label="Is high performace
required?", fillcolor=""]
     F [label="Is transparency
required?", fillcolor=""]

     A:s -> B:n [label="Yes"]
     B:s -> C:n [label="No"]
     C:s -> D:n [label="No"]
     D:s -> E:n [label="Yes"]
     E:s -> F:n [label="No"]

    }

   subgraph clusterB {
     graph [style="invis" margin=30] 
     rank="same"

     node [shape="diamond", fixedsize="true", width="3", height="1", style="filled"]

     P [label="Is trusted authority
decentralizable", fillcolor=""]
     Q [label="Can big data be
stored off-chain", fillcolor=""]
     R [label="Can encrypted data
be shared", fillcolor=""]
     node [label="" style="invis" shape=plain]
     x0 
     x1 
     x2 

     x0 -> P -> x1 -> x2 -> Q -> R [style="invis"]  // , dir="none"]

   }                           

    subgraph clusterC {
     graph [style="invis" margin=30]
     rank="max"

     node [shape="box", style="filled"]
     X [label="Consider Conventional
Database", fillcolor=""]
     Y [label="Consider Blockchain", fillcolor=""]
     Z [label="Consider DLTs", fillcolor=""]
     node [label="" style="invis" shape=plain]
     z0 
     z1 
     z2 

     z0 -> z1 -> X -> z2 -> Y -> Z [style="invis"]  // , dir="none"]
  }
}

2,将以下内容添加到myfile.dot中,直到最后一个括号并运行neato -n1 -Tpng myfile.dot> myfile.png这将路由边缘。

 [B:e -> P:w [label="Yes" constraint=false];
 P:sw -> C:ne [label="Yes" constraint=false]
 E:e -> Q:w [label="Yes" constraint=false]
 Q:sw -> F:ne [label="Yes" constraint=false]
 F:e -> R:w [label="No" constraint=false]

 A:e -> X:n [label="No" constraint=false]
 P -> X [label="No" constraint=false]
 C:e -> X:w [label="Yes" constraint=false]
 D:e -> X [label="No" constraint=false]

 Q -> X [label="No" constraint=false]
 F -> Y [label="Yes" constraint=false]

 R -> Y [label="Yes" constraint=false]
 R -> Z [label="No" constraint=false]

E -> Q [ltail=clusterA,lhead=clusterB];
Q -> Y [ltail=clusterB,lhead=clusterC];][1]

以上是关于Graphviz:创建三个簇中节点之间具有直边的流程图的主要内容,如果未能解决你的问题,请参考以下文章

更改Graphviz中节点之间的距离

Graphviz 在不同级别的节点之间强制排序

图形渲染软件,尊重节点和边的相对顺序

纯 JavaScript Graphviz 等效 [关闭]

用于具有非加权双向边缘的流分辨率的算法的C实现以及具有流容量的节点

导出 SVG 时,Cytoscape 等效于 graphviz URL/href 节点属性?