GraphViz DOT有向图 - 复杂案例分析(3)

案例

案例来源

https://stackoverflow.com/questions/7115870/creating-straight-edges-in-graphviz

案例代码

digraph start_up {
    { 
/* fake levels (level0 -> level1) and support nodes
 *
 * graphviz to charts is what latex is to documents, 
 * sometimes you'll have to fight it.
 * This is typically done by defining levels and connection points that
 * don't really have anything to do with your graph, but are used to 
 * force the graph to appear in a certain way.
 */
        node [shape=none, /*label="."*/]; l1a; l2a; l3a; l4a; l5a; l6a;
        node [shape=square label="no"]; l20a; 
    }

    {   /* connectiong point for the no arrow above "arrived" */
        node [width=0 shape=point label=""];
        d1; no;
    }

    node [style = rounded]; 
    node [shape = rect] start end;
    node [style = ""];

    node [shape = diamond]; {
        node [label="USB\nCommand\nArrived"]; arrived; 
        node [label="Has USB 3.0\nInterface Been\nSelected"]; selected;
        node [label="Initialize\nCode"]; init;
    }

    start -> init; 
    /*init -> arrived; */
    init -> d1 [arrowhead=none]; 
            d1 -> arrived;

/* 
 * tricky part:
 * since nodes in a digrap go either from top to bottom or left to right, we 
 * can usually not connect (->) two nodes and have them appear on the same 
 * level unless the connection is specified within a block that has the 
 * parameter `rank' set to `same'
 */
            l20a->no [arrowhead=none];

    {   rank=same; no -> arrived [dir=back arrowtail=none]; }
    {   rank=same; l20a -> d1; }

    /*arrived       -> arrived;*/ /*  [label="No" tailport=w headport=n]; */
    arrived     -> selected [label = "Yes"];
    selected    -> end


    /* just to demonstrate */
    l1a-> l2a-> l3a-> l4a-> l5a-> l6a;
}

在这里插入图片描述

案例精简保留重点,分析实现

digraph start_up {
    // 定义两个隐藏不可见节点d1, d2
    {
        node [width=0 shape=point label=""];
        d1; d2;
    }
    // 默认节点样式为diamond, 定义3个节点
    node [shape = diamond]; 
    {
        node [label="USB"]; usb; 
        node [label="USB 3.0\nInterface Been"]; usb3;
        node [label="do .."]; nodo;
    }

    // 开始节点指向隐藏节点d1, d1指向usb
    init -> d1 [arrowhead=none]; 
            d1 -> usb;

    // no节点指向隐藏节点d2
    nodo->d2 [arrowhead=none];

    // no节点和d1节点设置为同等级,并且指向
    {   rank=same; nodo -> d1; }
    // d2节点和usb节点设置为同等级, 并且提向
    {   rank=same; d2 -> usb [dir=back arrowtail=none label="no"]; }

    // yes 流程
    usb-> usb3[label = "Yes"];
}

在这里插入图片描述

分析实现点

  • 流程线条借助于两个隐藏节点
  • no节点指向d2确定上下关系,d1和usb节点确定上下关系
  • 隐藏节点和相应的节点rank对齐

案例中左侧进度实现原理是: 节点深度一样,它们就会处在同样的行中

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值