GraphViz - 当主图从上到下时如何使子图从左到右?

发布于 2024-08-08 08:14:55 字数 454 浏览 5 评论 0原文

我有一个像这样的图形文件:

digraph {
    "Step1" -> "Step2" -> "Step3";

    subgraph step2detail {
        "Step2" -> "note1";
        "Step2" -> "note2";
        "Step2" -> "note3";
        "Step2" -> "note4";
        rankdir=TB
   }
}

我希望子图 step2detail 挂在“Step2”的右侧。

现在看起来像这样:

在此处输入图像描述

我希望 Step1、Step2 和 Step3 都垂直位于彼此下方,并且在 1 列中。

I have a graph file like this:

digraph {
    "Step1" -> "Step2" -> "Step3";

    subgraph step2detail {
        "Step2" -> "note1";
        "Step2" -> "note2";
        "Step2" -> "note3";
        "Step2" -> "note4";
        rankdir=TB
   }
}

I want the subgraph step2detail to hang off to the right of 'Step2'.

Right now it looks like this:

enter image description here

I want Step1, Step2 and Step3 to all be vertically under each other and in 1 column.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

清风不识月 2024-08-15 08:14:55

获取您所描述的图表的技巧是使用两个子图并从一个子图链接到另一个子图。 “细节”中看不见的边缘使音符保持对齐。

digraph {
    rankdir="LR";

    subgraph steps {
        rank="same";
        "Step1" -> "Step2" -> "Step3";
    }

    subgraph details {
        rank="same";
        edge[style="invisible",dir="none"];
        "note1" -> "note2" -> "note3" -> "note4";
    }

    "Step2" -> "note1";
    "Step2" -> "note2";
    "Step2" -> "note3";
    "Step2" -> "note4";
}

结果是:

“在此处输入图像描述"

The trick to get the graph you described is to use two subgraphs and link from one to the other. The invisible edges in "details" are what keep the notes aligned.

digraph {
    rankdir="LR";

    subgraph steps {
        rank="same";
        "Step1" -> "Step2" -> "Step3";
    }

    subgraph details {
        rank="same";
        edge[style="invisible",dir="none"];
        "note1" -> "note2" -> "note3" -> "note4";
    }

    "Step2" -> "note1";
    "Step2" -> "note2";
    "Step2" -> "note3";
    "Step2" -> "note4";
}

The result is:

enter image description here

月亮邮递员 2024-08-15 08:14:55

这很简单 - 只需使用 group 属性即可让 graphviz 更喜欢直接
边缘:

digraph {
    node[group=a, fontname="Arial", fontsize=14];
    "Step1" -> "Step2" -> "Step3";

    node[group=""];
    "Step2" -> "note1";
    "Step2" -> "note2";
    "Step2" -> "note3";
    "Step2" -> "note4";
}

graphviz 输出

Here's as simple as it gets - just use the group attribute to have graphviz prefer straight
edges:

digraph {
    node[group=a, fontname="Arial", fontsize=14];
    "Step1" -> "Step2" -> "Step3";

    node[group=""];
    "Step2" -> "note1";
    "Step2" -> "note2";
    "Step2" -> "note3";
    "Step2" -> "note4";
}

graphviz output

秋风の叶未落 2024-08-15 08:14:55

通过将 Step 节点分组为聚类子图,输出如下:

digraph {
    subgraph cluster_0 {
        color=invis;
        "Step1" -> "Step2" -> "Step3";
    }

    subgraph cluster_1 {
        color=invis;
        "Step2" -> "note4";
        "Step2" -> "note3";
        "Step2" -> "note2";
        "Step2" -> "note1";
   }
}

color=invis 删除原本会在簇周围绘制的边框

By grouping the Step nodes into a clustered subgraph, the output is as follows:

digraph {
    subgraph cluster_0 {
        color=invis;
        "Step1" -> "Step2" -> "Step3";
    }

    subgraph cluster_1 {
        color=invis;
        "Step2" -> "note4";
        "Step2" -> "note3";
        "Step2" -> "note2";
        "Step2" -> "note1";
   }
}

color=invis removes the border that would otherwise be drawn around the cluster

臻嫒无言 2024-08-15 08:14:55

rankdir 不能直接在子图中工作,但是如果您添加另一组花括号 - 不管它叫什么 -rankdir 可以工作:

digraph {
    "Step1" -> "Step2" -> "Step3";

    subgraph step2detail {
        {
            "Step2" -> "note1";
            "Step2" -> "note2";
            "Step2" -> "note3";
            "Step2" -> "note4";
            rankdir=TB
            rank=same
        }
   }
}

在此处输入图像描述

rankdir doesn't work directly in the subgraph, but if you add another set of curly braces - whatever that's called - rankdir works:

digraph {
    "Step1" -> "Step2" -> "Step3";

    subgraph step2detail {
        {
            "Step2" -> "note1";
            "Step2" -> "note2";
            "Step2" -> "note3";
            "Step2" -> "note4";
            rankdir=TB
            rank=same
        }
   }
}

enter image description here

靖瑶 2024-08-15 08:14:55

使用命令:rankdir=LR;

digraph {
rankdir=LR;

    "Step1" -> "Step2" -> "Step3";

    subgraph step2detail {
        "Step2" -> "note1";
        "Step2" -> "note2";
        "Step2" -> "note3";
        "Step2" -> "note4";
        rankdir=TB
   }

}

Use the command: rankdir=LR;

digraph {
rankdir=LR;

    "Step1" -> "Step2" -> "Step3";

    subgraph step2detail {
        "Step2" -> "note1";
        "Step2" -> "note2";
        "Step2" -> "note3";
        "Step2" -> "note4";
        rankdir=TB
   }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文