【问题标题】:Distribute nodes on the same rank of a wide graph to different lines将宽图的同一等级上的节点分布到不同的行
【发布时间】:2012-06-23 11:57:12
【问题描述】:

我有一个图表(组织结构图):

digraph G {
nodesep=0.3;
ranksep=0.2;
margin=0.1;
node [shape=rectangle];
edge [arrowsize=0.8];
1 -> 2;
1 -> 3;
1 -> 4;
1 -> 5;
1 -> 6;
1 -> 7;
1 -> 8;
1 -> 9;
1 -> 10;
}

我有 70 人的组织结构图,无法用 A4 打印。如何将节点放在 2 或 3 行中?

【问题讨论】:

    标签: nodes graphviz dot


    【解决方案1】:

    这里有两种可能性(另见this question):

    1。使用unflatten 实用程序

    Graphviz 提供了一个名为unflatten 的工具。如果您使用此命令行预处理图形:

    unflatten -l 3 wide.gv | dot -Tpng -o wide.png
    

    输出图像将类似于下图。它的宽度稍小,您可以使用-l 选项。

    2。使用 `rank=same' 和不可见的边缘

    您可以使用标准技术使自动布局的图表看起来更像您想要的:

    • rank=same子图中的节点进行分组并定义哪些节点应位于同一行
    • 不可见的边,确保不同的子图出现在不同的等级上
    • 可能是constraint=false 的某些边缘会影响布局
    • group 节点的属性以鼓励直边。

    输出图不一定会更漂亮...

    这是一个示例,您可能可以做得更好。此外,如果图形是动态生成的,这可能不太实用。

    digraph G {
    nodesep=0.3;
    ranksep=0.2;
    margin=0.1;
    node [shape=rectangle];
    edge [arrowsize=0.8];
    
    
    edge[style=invis];
    node[group=a];
    2->5->8;
    node[group=b];
    1->3->6->9;
    node[group=c];
    4->7->10;
    
    
    edge[style=solid];
    1 -> 2;
    1 -> 3;
    1 -> 4;
    edge[constraint=false];
    1 -> 5;
    1 -> 6;
    1 -> 7;
    1 -> 8;
    1 -> 9;
    1 -> 10;
    }
    

    【讨论】:

    • unflatten 不支持 Unicode 字符
    • unflatten 不支持 Unicode 字符。但那是因为您使用 PowerShell!如果您使用 Bash,它可以正常工作。见the differences between the output here
    猜你喜欢
    • 2021-05-21
    • 2015-03-20
    • 2018-05-30
    • 2016-08-19
    • 1970-01-01
    • 1970-01-01
    • 2021-08-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多