在graphviz中水平组织盒子然后垂直组织盒子

puk*_*puk 6 graph graphviz

有些方法可以在某些情况下水平显示框,而在其他情况下垂直显示框?(见 相关问题).

这是我得到的代码和输出:

码:

/**
** Diagram representing the Simulator Engine
**/
digraph G {
        graph [
            rankdir = "TB"
        ];

        /**
        ** The simulator engine rectangle
        **/
    subgraph cluster_simulator_engine {
        style=filled;
        color=lightgrey;
        node [style=filled,color=white];
        label = "Simulator Engine";

                /**
                ** The first topology
                **/
                subgraph cluster_T1 {
                        color=white;
                        node [style=filled];

                        /**
                        ** The n^th neuron
                        **/
                        subgraph cluster_T1_N3 {
                                color=lightgrey;
                                node [style=filled];
                                label = "Neuron n";

                                /**
                                ** The n^th synapse 
                                **/
                                "T1_N3_S3" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse n"
                                ];

                                /**
                                ** The second synapse 
                                **/
                                "T1_N3_S2" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 2"
                                ];

                                /**
                                ** The first synapse 
                                **/
                                "T1_N3_S1" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 1"
                                ];

                                /*"T1_N1_S3" -> "T1_N1_S2" [style=invis];*/
                        }

                        /**
                        ** The second neuron
                        **/
                        subgraph cluster_T1_N2 {
                                color=lightgrey;
                                node [style=filled];
                                label = "Neuron 2";

                                /**
                                ** The n^th synapse 
                                **/
                                "T1_N2_S3" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse n"
                                ];

                                /**
                                ** The second synapse 
                                **/
                                "T1_N2_S2" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 2"
                                ];

                                /**
                                ** The first synapse 
                                **/
                                "T1_N2_S1" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 1"
                                ];

                                /*"T1_N1_S3" -> "T1_N1_S2" [style=invis];*/
                        }


                        /**
                        ** The third neuron
                        **/
                        subgraph cluster_T1_N1 {
                                color=lightgrey;
                                node [style=filled];
                                label = "Neuron 1";

                                /**
                                ** The n^th synapse 
                                **/
                                "T1_N1_S3" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse n"
                                ];

                                /**
                                ** The second synapse 
                                **/
                                "T1_N1_S2" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 2"
                                ];

                                /**
                                ** The first synapse 
                                **/
                                "T1_N1_S1" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 1"
                                ];

                                /*"T1_N1_S3" -> "T1_N1_S2" [style=invis];*/
                        }


                        label = "Topology 1";
                }

                /**
                ** The second topology
                **/
                subgraph cluster_T2 {
                        color=white;
                        node [style=filled];

                        /**
                        ** The n^th neuron
                        **/
                        subgraph cluster_T2_N3 {
                                color=lightgrey;
                                node [style=filled];
                                label = "Neuron n";

                                /**
                                ** The n^th synapse 
                                **/
                                "T2_N3_S3" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse n"
                                ];

                                /**
                                ** The second synapse 
                                **/
                                "T2_N3_S2" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 2"
                                ];

                                /**
                                ** The first synapse 
                                **/
                                "T2_N3_S1" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 1"
                                ];

                                /*"T1_N1_S3" -> "T1_N1_S2" [style=invis];*/
                        }

                        /**
                        ** The second neuron
                        **/
                        subgraph cluster_T2_N2 {
                                color=lightgrey;
                                node [style=filled];
                                label = "Neuron 2";

                                /**
                                ** The n^th synapse 
                                **/
                                "T2_N2_S3" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse n"
                                ];

                                /**
                                ** The second synapse 
                                **/
                                "T2_N2_S2" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 2"
                                ];

                                /**
                                ** The first synapse 
                                **/
                                "T2_N2_S1" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 1"
                                ];

                                /*"T1_N1_S3" -> "T1_N1_S2" [style=invis];*/
                        }


                        /**
                        ** The third neuron
                        **/
                        subgraph cluster_T2_N1 {
                                color=lightgrey;
                                node [style=filled];
                                label = "Neuron 1";

                                /**
                                ** The n^th synapse 
                                **/
                                "T2_N1_S3" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse n"
                                ];

                                /**
                                ** The second synapse 
                                **/
                                "T2_N1_S2" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 2"
                                ];

                                /**
                                ** The first synapse 
                                **/
                                "T2_N1_S1" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 1"
                                ];

                                /*"T1_N1_S3" -> "T1_N1_S2" [style=invis];*/
                        }


                        label = "Topology 2";
                }

    }

}
Run Code Online (Sandbox Code Playgroud)

输出:

第一个图

显然这太长了.我想要的是将每个突触移动到它自己的行中(我认为它在Graphviz-jargon中被称为'rank').显然,没有办法做到这一点,但有一个技巧.因此,我采用上面相同的代码,并引入不可见的边缘

码:

/**
** Diagram representing the Simulator Engine
**/
digraph G {
        graph [
            rankdir = "TB"
        ];

        /**
        ** The simulator engine rectangle
        **/
    subgraph cluster_simulator_engine {
        style=filled;
        color=lightgrey;
        node [style=filled,color=white];
        label = "Simulator Engine";

                /**
                ** The first topology
                **/
                subgraph cluster_T1 {
                        color=white;
                        node [style=filled];

                        /**
                        ** The n^th neuron
                        **/
                        subgraph cluster_T1_N3 {
                                color=lightgrey;
                                node [style=filled];
                                label = "Neuron n";

                                /**
                                ** The n^th synapse 
                                **/
                                "T1_N3_S3" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse n"
                                ];

                                /**
                                ** The second synapse 
                                **/
                                "T1_N3_S2" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 2"
                                ];

                                /**
                                ** The first synapse 
                                **/
                                "T1_N3_S1" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 1"
                                ];

                                "T1_N3_S1" -> "T1_N3_S2" [style=invis];
                                "T1_N3_S2" -> "T1_N3_S3" [style=invis];
                        }

                        /**
                        ** The second neuron
                        **/
                        subgraph cluster_T1_N2 {
                                color=lightgrey;
                                node [style=filled];
                                label = "Neuron 2";

                                /**
                                ** The n^th synapse 
                                **/
                                "T1_N2_S3" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse n"
                                ];

                                /**
                                ** The second synapse 
                                **/
                                "T1_N2_S2" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 2"
                                ];

                                /**
                                ** The first synapse 
                                **/
                                "T1_N2_S1" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 1"
                                ];

                                "T1_N2_S2" -> "T1_N2_S3" [style=invis];
                                "T1_N2_S1" -> "T1_N2_S2" [style=invis];
                        }


                        /**
                        ** The third neuron
                        **/
                        subgraph cluster_T1_N1 {
                                color=lightgrey;
                                node [style=filled];
                                label = "Neuron 1";

                                /**
                                ** The n^th synapse 
                                **/
                                "T1_N1_S3" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse n"
                                ];

                                /**
                                ** The second synapse 
                                **/
                                "T1_N1_S2" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 2"
                                ];

                                /**
                                ** The first synapse 
                                **/
                                "T1_N1_S1" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 1"
                                ];

                                "T1_N1_S1" -> "T1_N1_S2" [style=invis];
                                "T1_N1_S2" -> "T1_N1_S3" [style=invis];
                        }


                        label = "Topology 1";
                }

                /**
                ** The second topology
                **/
                subgraph cluster_T2 {
                        color=white;
                        node [style=filled];

                        /**
                        ** The n^th neuron
                        **/
                        subgraph cluster_T2_N3 {
                                color=lightgrey;
                                node [style=filled];
                                label = "Neuron n";

                                /**
                                ** The n^th synapse 
                                **/
                                "T2_N3_S3" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse n"
                                ];

                                /**
                                ** The second synapse 
                                **/
                                "T2_N3_S2" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 2"
                                ];

                                /**
                                ** The first synapse 
                                **/
                                "T2_N3_S1" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 1"
                                ];

                                "T2_N3_S1" -> "T2_N3_S2" [style=invis];
                                "T2_N3_S2" -> "T2_N3_S3" [style=invis];
                        }

                        /**
                        ** The second neuron
                        **/
                        subgraph cluster_T2_N2 {
                                color=lightgrey;
                                node [style=filled];
                                label = "Neuron 2";

                                /**
                                ** The n^th synapse 
                                **/
                                "T2_N2_S3" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse n"
                                ];

                                /**
                                ** The second synapse 
                                **/
                                "T2_N2_S2" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 2"
                                ];

                                /**
                                ** The first synapse 
                                **/
                                "T2_N2_S1" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 1"
                                ];

                                "T2_N2_S1" -> "T2_N2_S2" [style=invis];
                                "T2_N2_S2" -> "T2_N2_S3" [style=invis];
                        }


                        /**
                        ** The third neuron
                        **/
                        subgraph cluster_T2_N1 {
                                color=lightgrey;
                                node [style=filled];
                                label = "Neuron 1";

                                /**
                                ** The n^th synapse 
                                **/
                                "T2_N1_S3" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse n"
                                ];

                                /**
                                ** The second synapse 
                                **/
                                "T2_N1_S2" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 2"
                                ];

                                /**
                                ** The first synapse 
                                **/
                                "T2_N1_S1" [
                                    style=filled
                                    shape=box
                                    color=white
                                    label="Synapse 1"
                                ];

                                "T2_N1_S1" -> "T2_N1_S2" [style=invis];
                                "T2_N1_S2" -> "T2_N1_S3" [style=invis];
                        }


                        label = "Topology 2";
                }

    }

}
Run Code Online (Sandbox Code Playgroud)

现在输出看起来更有吸引力.

输出: 第二个较小的图

但现在突触盒之间存在巨大差距.设置nodesep=0.1len=0.1无效.任何人都可以告诉我如何解决这个问题,或者如何重新设计它.

注意:如果有人好奇为什么我从1到2变为n,那是因为我打算在那里放一个省略号,但我不知道如何做到这一点......当我到达那个时,越过那座桥.

mar*_*pet 8

这是ranksep你要找的-这行添加到该图形的属性:

ranksep = 0.1
Run Code Online (Sandbox Code Playgroud)

在点中,这给出了所需的等级间隔,以英寸为单位.这是一个级别中节点底部与下一个节点顶部之间的最小垂直距离.