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

247 阅读1分钟

文章目录

案例

来源

stackoverflow.com/questions/3…

  • Nodes in the same group are placed on a straight line down the rank.
  • All your edges assist nicely in ranking if given the right dir attribute.
digraph g
{
    rankdir=RL
    node [shape = record, height=0.1];
    subgraph {
        node [group=2]
        M_2; M_5; M_9;
    }
    subgraph {
        node [group=1]
        M_1; M_4; M_8; M_11;
    }
    subgraph {
        node [group=3]
        M_3; M_6; M_10;
    }
    M_7;
    subgraph {
        edge [style=dotted]
        M_1 -> M_4;
        M_4 -> M_8;
        M_8 -> M_11;
        M_2 -> M_5;
        M_5 -> M_9;
        M_3 -> M_6;
        M_6 -> M_10;
    }
    subgraph {
        edge [dir=back]
        M_1 -> M_2;
        M_2 -> M_4;
        M_1 -> M_3;
        M_3 -> M_4;
        M_4 -> M_5;
        M_4 -> M_6;
        M_5 -> M_8;
        M_6 -> M_8;
        M_4 -> M_7;
        M_7 -> M_8;
        M_8 -> M_9;
        M_8 -> M_10;
        M_10 -> M_11;
        M_9 -> M_11;
    }
}

在这里插入图片描述

digraph g
{
    rankdir=RL
    ranksep=0.5
    nodesep=0.5
    splines=line
    node [shape = record, height=0.1];
    Dummy [style=invisible];
    subgraph {
        node [group=2]
        M_2; M_5; M_9;
    }
    subgraph {
        node [group=1]
        M_1; M_4; M_8; M_11;
    }
    subgraph {
        node [group=3]
        M_3; M_6; M_10;
    }
    M_7;
    subgraph {
        edge [style=dotted]
        M_1 -> M_4;
        M_4 -> M_8;
        M_8 -> M_11;
        M_2 -> M_5;
        M_5 -> M_9;
        M_3 -> M_6;
        M_6 -> M_10;
    }
    subgraph {
        edge [dir=back]
        M_1 -> M_2;
        M_2 -> M_4;
        M_1 -> M_3;
        M_3 -> M_4;
        M_4 -> M_5;
        M_4 -> M_6;
        M_5 -> M_8;
        M_6 -> M_8;
        M_4 -> M_7;
        M_7 -> M_8;
        M_8 -> M_9;
        M_8 -> M_10;
        M_10 -> M_11;
        M_9 -> M_11;
    }
    subgraph {
        edge [dir=none style=invisible]
        M_4 -> Dummy;
        Dummy -> M_8;
    }
}

在这里插入图片描述

digraph g
{
    rankdir=RL
    ranksep=0.5
    nodesep=0.5
    splines=line
    node [shape = record, height=0.1];
    Dummy [style=invisible];
    subgraph {
        node [group=2]
        M_2; M_5; M_9;
    }
    subgraph {
        node [group=1]
        M_1; M_4; M_8; M_11;
    }
    subgraph {
        node [group=3]
        M_3; M_6; M_10;
    }
    M_7 [style=invisible];
    subgraph {
        edge [style=dotted]
        M_1 -> M_4;
        M_4 -> M_8;
        M_8 -> M_11;
        M_2 -> M_5;
        M_5 -> M_9;
        M_3 -> M_6;
        M_6 -> M_10;
    }
    subgraph {
        edge [dir=back]
        M_1 -> M_2;
        M_2 -> M_4;
        M_1 -> M_3;
        M_3 -> M_4;
        M_4 -> M_5;
        M_4 -> M_6;
        M_5 -> M_8;
        M_6 -> M_8;
        M_4 -> M_7[dir=none style=invisible];
        M_7 -> M_8[dir=none style=invisible];
        M_8 -> M_9;
        M_8 -> M_10;
        M_10 -> M_11;
        M_9 -> M_11;
    }
    subgraph {
        edge [dir=none style=invisible]
        M_4 -> Dummy;
        Dummy -> M_8;
    }
}

在这里插入图片描述

案例分析

如果nodesep是左右间距那么ranksep就是上下间距,如果nodesep是上下,ranksep就是左右

  • ranksep=0.5 等级间距
  • nodesep=0.5 节点间距
  • group 使用点一至,节点线成直线
  • node[style=invisible]节点不可见
  • edge [dir=none style=invisible] 线不可见