【问题标题】:Drawing "interfaces" with Graphviz使用 Graphviz 绘制“接口”
【发布时间】:2022-10-08 20:00:06
【问题描述】:

为了对某种(嵌套/分层)系统架构进行建模,我试图弄清楚如何绘制一个具有多个“入口点”(又名接口)的框。目标是哪个组件使用哪个接口与另一个组件通信。

这是一个手绘示例来说明目标:

请注意,黄色框是由组件组成的系统(蓝色框)。绿点是组件的接口。如果接口暴露给系统外部的组件,则需要在系统级别传播接口(红点)。

对于组件的接口(绿点),"record-based node" 可以解决问题;顶行中的“表格单元格”可用作界面。

我还没有弄清楚的是“系统界面”部分(红点)。有没有一种方法可以将例如“圆形”形状显式放置在子图的边界上?或者您是否有其他解决方案可以模拟“系统接口”的表示?

【问题讨论】:

  • @Progman 我提供了一些关于我的未决问题到底是什么的更多细节。感谢您指出我最初的问题缺乏精确性。

标签: graphviz


【解决方案1】:

您可以通过使用非标准的“箭头”(https://graphviz.org/doc/info/arrows.html)获得相当接近,但很难/不可能获得

  • 边框上的圆圈
  • 边缘“排队”(不能声明从内部节点到它自己的集群的边缘)
  • 见下图

可以通过明确定位节点(包括彩色点)、设置 X、Y 坐标(参见@​​987654322@)来使用 Graphviz 绘制所需的图形。相反,我建议使用其中一种 PIC 语言实现。具体来说,皮克彻(https://pikchr.org/home/doc/trunk/homepage.md)

最佳点版本(无明确定位):

【讨论】:

    【解决方案2】:

    使用额外的隐藏边和节点可以获得部分解决方案,但肯定有更好的工具,正如已经说过的,在 graphviz 中,您不能轻易地将一个点放在集群的边界上并保持代码干净而没有额外的节点。

    带有隐藏元素的变体image 和代码:

    digraph system_architecture {
        graph [
            newrank=true
            ranksep=0
            compound=true
            splines=curved]
    
        subgraph cluster_S1 {
            style=filled
            fillcolor="lightyellow"
            label="Sys 1"
            labelloc="b"
            margin=3
            sys1_rest_dot_1 [shape=point height=0]
            sys1_rest_dot_2 [shape=point height=0]
            comp11_rest_dot [shape=point height=0]
            comp12_graphql_dot [shape=point height=0]
          
            subgraph cluster_C11 {
                label=""
                style="filled"
                fillcolor="cyan"
                comp11 [label="Comp 1.1" shape=none]
            }
          
            subgraph cluster_C12 {
                label=""
                style="filled"
                fillcolor="cyan"
                comp12 [label="Comp 1.2" shape=none]
            }
        }
    
        invis_node [style=invis]
        invis_node -> sys1_rest_dot_1 [lhead="cluster_S1" color=none  minlen=2]
        sys1_rest_dot_1 -> sys1_rest_dot_2 [lhead="cluster_S1" arrowsize=1 penwidth=10 arrowhead=dot color=red headlabel="REST"]
        sys1_rest_dot_2 -> comp11_rest_dot [minlen=4 headlabel="REST" arrowhead=vee ]
        comp11_rest_dot -> comp11 [lhead="cluster_C11" arrowsize=1 penwidth=10 arrowhead=dot color=lime]
    
        comp11 -> comp12_graphql_dot [minlen=3 lhead="cluster_C12" headlabel="GraphQL" arrowhead=vee]
        comp12_graphql_dot -> comp12 [lhead="cluster_C12" arrowsize=1 penwidth=10 arrowhead=dot color=lime]
    
        subgraph cluster_S2 {
            style=filled
            fillcolor="lightyellow"
            label="Sys 2"
            labelloc="b"
            margin=3
            sys2_rest_dot_1 [shape=point height=0]
            sys2_rest_dot_2 [shape=point height=0]
            comp21_rest_dot [shape=point height=0]
            comp22_sql_dot [shape=point height=0]
            
            sys2_soa_dot_1 [shape=point height=0]
            sys2_soa_dot_2 [shape=point height=0]
            comp22_soa_dot [shape=point height=0]
            
            subgraph cluster_C21 {
                label=""
                style="filled"
                fillcolor="cyan"
                comp21 [label="Comp 2.1" shape=none]
            }
          
            subgraph cluster_C22 {
                label=""
                style="filled"
                fillcolor="cyan"
                comp22 [label="Comp 2.2" shape=none]
            }
        }
     
        comp12 -> sys2_rest_dot_1 [arrowhead=vee]
        sys2_rest_dot_1 -> sys2_rest_dot_2 [lhead="cluster_S2" arrowsize=1 penwidth=10 arrowhead=dot color=red headlabel="REST"]
        sys2_rest_dot_2 -> comp21_rest_dot [minlen=4 headlabel="REST" arrowhead=vee ]
        comp21_rest_dot -> comp21 [lhead="cluster_C21" arrowsize=1 penwidth=10 arrowhead=dot color=lime]
    
        comp21 -> comp22_sql_dot [minlen=3 lhead="cluster_C22" headlabel="SQL" arrowhead=vee]
        comp22_sql_dot -> comp22 [lhead="cluster_C22" arrowsize=1 penwidth=10 arrowhead=dot color=lime]
        
        comp12 -> sys2_soa_dot_1 [arrowhead=vee]
        sys2_soa_dot_1 -> sys2_soa_dot_2 [lhead="cluster_S2" arrowsize=1 penwidth=10 arrowhead=dot color=red headlabel="SOA"]
        sys2_soa_dot_2 -> comp22_soa_dot [minlen=7 headlabel="SOA" arrowhead=vee]
        comp22_soa_dot -> comp22 [ head="cluster_C21" arrowsize=1 penwidth=10 arrowhead=dot color=lime]
    }
    

    没有技巧的变体(不适合问题,但代码很干净)image 和代码:

    digraph system_architecture {
        graph [
            overlap=false
            ranksep=.6
            nodesep=.6
            compound=true
            splines=curved
            fontname="Arial"]
    
        subgraph cluster_S1 {
            style=filled
            fillcolor="lightyellow"
            label="Sys 1"
            rest_s1 [shape=circle label="" height=.2 fillcolor=red style=filled xlabel=<<FONT FACE="Arial">REST</FONT>>]
          
            subgraph cluster_C11 {
                label=""
                style="filled"
                fillcolor="cyan"
                rest_c11 [shape=circle label="" height=.2 fillcolor=lime style=filled  xlabel=<<FONT FACE="Arial">REST</FONT>>]
                comp11 [label=<<FONT FACE="Arial">Comp 1.1</FONT>> shape=none]
            }
          
            subgraph cluster_C12 {
                label="";
                style="filled"
                fillcolor="cyan"
                graphql_c12 [shape=circle label="" height=.2 fillcolor=lime style=filled xlabel=<<FONT FACE="Arial">GraphQL</FONT>>]
                comp12 [label=<<FONT FACE="Arial">Comp 1.2</FONT>> shape=none]
            }
        }
        
        rest_s1 -> rest_c11 [arrowhead=vee]
        comp11 -> graphql_c12 [ltail="cluster_C11" arrowhead=vee]
    
        subgraph cluster_S2 {
            style=filled
            fillcolor="lightyellow"
            label="Sys 2"
            rest_s2 [shape=circle label="" height=.2 fillcolor=red style=filled xlabel=<<FONT FACE="Arial">REST</FONT>>]
            soa_s2 [shape=circle label="" height=.2 fillcolor=red style=filled xlabel=<<FONT FACE="Arial">SOA</FONT>>]
            
            subgraph cluster_C21 {
                label=""
                style="filled"
                fillcolor="cyan"
                rest_c21 [shape=circle label="" height=.2 fillcolor=lime style=filled  xlabel=<<FONT FACE="Arial">REST</FONT>>]
                comp21 [label=<<FONT FACE="Arial">Comp 2.1</FONT>> shape=none]
            }
          
            subgraph cluster_C22 {
                label="";
                style="filled"
                fillcolor="cyan"
                sql_c22 [shape=circle label="" height=.2 fillcolor=lime style=filled  xlabel=<<FONT FACE="Arial">SQL</FONT>>]
                soa_c22 [shape=circle label="" height=.2 fillcolor=lime style=filled  xlabel=<<FONT FACE="Arial">SOA</FONT>>]
                comp22 [label="Comp 2.2" shape=none labelfontname="Arial"]
            }
        }
        
        comp12 -> rest_s2 [ltail="cluster_C12" arrowhead=vee]
        comp12 -> soa_s2 [ltail="cluster_C12" arrowhead=vee]
        rest_s2 -> rest_c21 [arrowhead=vee]
        soa_s2 -> soa_c22 [arrowhead=vee]
        comp21 -> sql_c22 [ltail="cluster_C21" arrowhead=vee]
    }
    

    【讨论】:

      猜你喜欢
      • 2021-07-27
      • 1970-01-01
      • 1970-01-01
      • 2019-10-27
      • 2022-01-23
      • 1970-01-01
      • 2017-01-01
      • 2018-04-03
      • 1970-01-01
      相关资源
      最近更新 更多