如何控制子图'点布局?

发布于 2024-12-14 00:04:34 字数 246 浏览 5 评论 0原文

我有一个由许多独立且简单的各种大小的子图组成的有向图。 dot 水平放置所有这些子图,因此我最终得到一个 40000x200 的输出文件,例如:

G1 G2 G3 G.....4 G5

我如何告诉 dot 在两个维度上布局这些子图以获得类似:

G1 G2 G3
G.....4
G5

谢谢。

i have a digraph composed of many independant and simple subgraphs of various sizes. dot lays all these subgraphs horizontally, so i end up with a 40000x200 output file, e.g:

G1 G2 G3 G.....4 G5

How do i tell dot to layout these subgraphs in both dimensions to get something like:

G1 G2 G3
G.....4
G5

Thanks.

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

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

发布评论

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

评论(1

心如荒岛 2024-12-21 00:04:34

实现此目的的步骤使用可以通过管道连接在一起的多个 graphviz 工具

以下行是可能的配置,graph.dot 是包含图表的文件。您可能需要摆弄这些选项。

ccomps -x graph.dot | dot | gvpack -array3 | neato -Tpng -n2 -o graph.png

解释如下:


1. 分离断开的图

工具:ccomps

将图分解为其连接的组件

-x 选项(仅打印连接的组件,作为单独的图)可能就是所需要的。


2. 布局每个图

工具:

每个有向图都被一一布局。需要此步骤来获取节点和边的位置。


3. 将所有布局图打包到一个

工具中:gvpack

读取图形流,将图形组合成单个布局,
并生成一个图作为输入图的并集。

您应该阅读该工具的选项文档并使用这些选项。例如,-array 用于以类似网格的方式布局图形,并提供多个标志来控制布局。


4. 创建输出

工具:neato

选项-n2告诉neato不要布局输入图形,而是使用现有的位置属性。


示例图:

graphiz gvpack

digraph G {
 subgraph G1 {
    a->{b; c;};
 }
 subgraph G2 {
    d -> {e; f;};
 }
 subgraph G3 {
    g -> h;
 }
 subgraph G4 {
    i -> j;
 }
 subgraph G5 {
    {k; l;} -> m;
 }
}

编辑: 对 gvpack 中的二合字母进行排序

以确定外观 od 由 gvpack 创建的组合布局中的子图,每个子图都需要一个 sortv 属性。

例如,以下图形:

digraph G1 {
 sortv=1;
 a->{b; c;};
}
digraph G2 {
 sortv=2;
 d -> {e; f;};
}
digraph G3 {
 sortv=3;
 g -> h;
}
digraph G4 {
 sortv=4;
 i -> j;
}
digraph G5 {
 sortv=5;
 {k; l;} -> m;
}

进行转换

dot graph.dot | gvpack -array_u | neato -Tpng -n2 -o graph.png

可以使用结果

packed graph withordered subgraphs

The steps to achieve this uses multiple graphviz tools which can be piped together.

The following line is a possible configuration, graph.dot being the file which contains your graph(s). You may have to fiddle with the options.

ccomps -x graph.dot | dot | gvpack -array3 | neato -Tpng -n2 -o graph.png

And here's the explanation:


1. Separate disconnected graphs

Tool: ccomps

decomposes graphs into their connected components

The -x option (Only the connected components are printed, as separate graphs) is probably all that is needed.


2. Layout each graph

Tool: dot

Each directed graph is layed out, one by one. This step is needed to get the position of the nodes and edges.


3. Pack all layed out graphs into one

Tool: gvpack

reads in a stream of graphs, combines the graphs into a single layout,
and produces a single graph serving as the union of the input graphs.

You should read the documentation of the options for this tool and play with the options. For example, -array is used to lay out the graphs in a grid like manner, and offers several flags to control the layout.


4. Create the output

Tool: neato

The option -n2 tells neato to not layout the input graphs but to use the existing position attributes.


Example graph:

graphiz gvpack

digraph G {
 subgraph G1 {
    a->{b; c;};
 }
 subgraph G2 {
    d -> {e; f;};
 }
 subgraph G3 {
    g -> h;
 }
 subgraph G4 {
    i -> j;
 }
 subgraph G5 {
    {k; l;} -> m;
 }
}

Edit: Sorting the digraphs in gvpack

In order to determine the order of appearance od the subgraphs in the combined layout created by gvpack, each subgraph will need a sortv attribute.

For example, the following graphs:

digraph G1 {
 sortv=1;
 a->{b; c;};
}
digraph G2 {
 sortv=2;
 d -> {e; f;};
}
digraph G3 {
 sortv=3;
 g -> h;
}
digraph G4 {
 sortv=4;
 i -> j;
}
digraph G5 {
 sortv=5;
 {k; l;} -> m;
}

can be transformed using

dot graph.dot | gvpack -array_u | neato -Tpng -n2 -o graph.png

resulting in

packed graph with ordered subgraphs

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