Graphviz DOT 将节点排列成圆形,布局过于“紧凑”

发布于 2024-08-29 10:13:41 字数 552 浏览 7 评论 0原文

我已经完成一半,请查看编辑

好的,这是我的问题,我正在生成一个 python 模块的图表,包括所有文件及其函数/方法/类。

我想这样安排,节点围绕其父节点聚集成圆圈,当前所有内容都在一个巨大的水平行上,这使得该内容> 50k 像素宽,并且还让 svg 转换器失败(仅渲染大约一半的内容)图形)。

我浏览了 docs 但找不到任何似乎可以做到的内容诡计。

所以问题是:
有没有一种简单的方法可以做到这一点,或者我必须自己布局整个事情? :/

编辑:
感谢安德鲁斯的评论,我已经有了正确的布局,现在唯一的问题是它有点“紧凑”......所以现在的问题是,如何解决这个问题?

测试

I'm halfway there please see the edit

OK here's my problem, I'm generating a graph of a python module, including all the files with their functions/methods/classes.

I want to arrange it so, that nodes gather in circles around their parent nodes, currently everything is on one gargantuan horizontal row, which makes the thing >50k pixels wide and also let's the svg converter fail(only renders about the half of the graph).

I went through the docs but couldn't find anything that seems to do the trick.

So the question is:
Is there a simple way to do this or do I have to layout the whole thing by myself? :/

EDIT:
Thanks to Andrews comment I've got the right layout, the only problem now is that it's a bit to "compact"... so the question now is, how to fix this?

Test

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

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

发布评论

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

评论(3

蓝眼泪 2024-09-05 10:13:41

我已经提到了影响当前布局的所有最重要的参数,然后是这些参数的建议值。不过,我怀疑您只需应用这些建议即可获得您想要的布局。

  • 减小边权重,例如[weight=0.5];这将使
    边缘较长,导致紧
    您当前在中看到的集群
    图形“扇出”。

  • 去掉节点边界,node_A
    [颜色=无;形状=明文];
    特别是对于椭圆形节点,
    占总数的很大一部分
    节点空间“未使用”(即,未使用
    显示节点标签)。

  • 显式设置字体大小
    节点(节点边界是
    放大,使它们包围
    节点文本,表示字体
    给定的文本大小和数量
    节点对其影响很大
    尺寸); [fontsize=11] 应该大
    足够清晰但也减少
    “杂乱”的外观(
    默认大小为 14)。

  • 增加之间的最小间隔
    节点,通过“nodesep”
    ;例如,nodesep=2.0;这将
    直接提出您的反对意见
    关于你的图表“太
    紧凑。”('nodesep' 和 'ranksep'
    可能会影响 dot 绘制图表的方式
    比任何其他参数都多
    节点、边或图。就你而言,
    看起来你只有两个等级
    节点数; 'ranksep' 设置最小值
    不同节点之间的距离
    排名——看起来像所有节点
    组成你的图表的是
    相同等级(少数顶级除外)
    中心的节点)。

  • 显式设置总图表大小,例如,
    size="7.75,10.25" (确保您的
    图表适合 8.5 x 11 页面,并且
    它占据了整个空间)

  • 还有一个纯粹的美学建议
    这最多只会帮助你
    图表显得不那么混乱:
    两个边缘的默认字体颜色和
    节点是黑色的。大多数
    你的图表上的墨水来自这两个
    结构(特别是如果你
    删除节点边框),所以我会
    例如设置节点
    (文本)字体颜色或边缘
    字体颜色改为“蓝色”以帮助眼睛
    区分两组图
    结构。

i've mentioned all of the most significant parameters that influence your current layout and then suggested values for those parameters. Still, i suspect you can get the layout that you want just from applying a couple of these suggestions.

  • reduce the edge weight, eg, [weight=0.5]; this will make the
    edges longer, causing the tight
    clusters you currently see in your
    graph to 'fan out'.

  • get rid of the node borders, node_A
    [color=none; shape=plaintext];
    especially for oval-shaped nodes, a
    substantial fraction of the total
    node space is 'unused' (ie, not used
    to display the node label).

  • explicitly set the font size for
    the nodes
    (the node borders are
    enlarged so that they surround the
    node text, which means that the font
    size and amount of text for a given
    node has a significant effect on its
    size); [fontsize=11] should be large
    enough to be legible yet also reduce
    the 'cluttered' appearance (the
    default size is 14).

  • increase minimum separation between
    nodes, via 'nodesep'
    ; eg, nodesep=2.0; this will
    directly address your objection
    regarding your graph being "too
    compact." ('nodesep' and 'ranksep'
    probably affect how dot draws a graph
    more than any other parameters for
    node, edge, or graph. In your case,
    it looks like you have only two ranks
    of nodes; 'ranksep' sets the minimum
    distance between nodes of different
    ranks--it looks like all of the nodes
    that comprise your graph are of the
    same rank (except for few top level
    nodes in the centers).

  • explicitly set total graph size, eg,
    size="7.75,10.25" (ensures that your
    graph fits on an 8.5 x 11 page and
    that it occupies the entire space)

  • And one purely aesthetic suggestion
    that at most will only help your
    graph appear less cluttered: the
    default fontcolor for both edges and
    nodes is black. The majority of the
    ink on your graph is from those two
    structures (particularly if you
    remove the node borders), so i would
    for instance set either the node
    (text) fontcolor or the edge
    fontcolor to "blue" to help the eye
    distinguish the two sets of graph
    structures.

待"谢繁草 2024-09-05 10:13:41

如果它太紧凑,你会想要弄乱边缘长度。根据图表布局,您有几个选项:

  1. 如果您的布局是 sfdp 或 fdp,请调整图表属性K。默认值为 0.3。
  2. 对于neato(或fdp),调整edge属性len。 neato 的默认值为 1.0,fdp 的默认值为 0.3。
  3. 对于点,您可以使用edge属性minlen,它是最小边缘长度。默认值为 1。

您可能还想修改决定聚类行为的图形属性 model。具体来说,尝试子集。我相信这可以为您处理len
http://www.graphviz.org/doc/info/attrs.html #d:model

另外,您可以使用缩放技术来删除重叠:http://www.graphviz.org/doc/info/attrs.html#d:overlap

If it is too compact, you will want to mess with the edge length. You have a couple options depending on the graph layout:

  1. If your layout is sfdp or fdp, tweak the graph property K. Default is 0.3.
  2. For neato (or fdp), tweak the edge property len. Default is 1.0 for neato and 0.3 for fdp.
  3. For dot you can use the edge property minlen which is the minimum edge length. Default is 1.

You might also want to mess with the graph property model which determines clustering behavior. Specifically, try subset. I believe this handles len for you:
http://www.graphviz.org/doc/info/attrs.html#d:model

Also, you can remove overlaps all together with scaling techniques: http://www.graphviz.org/doc/info/attrs.html#d:overlap

困倦 2024-09-05 10:13:41

我有大约 500 个节点并使用了 doug 的推荐。

这是我的示例代码(在 python 中):

f = Digraph('companies',filename='companies.gv',
          edge_attr={'weight':'1',
                     'fontsize':'11',
                     'fontcolor':'blue',
                     'len':'4'},
          graph_attr={'fixedsize':'false', 
                      'bgcolor':'transparent'},
          node_attr={'fontsize':'11', 
                     'shape':'plaintext', 
                     'color':'none',
                     'fontcolor':'black'})

f.attr(layout="neato")
f.attr(nodesep='3')
f.attr(ranksep='3')
f.attr(size='5000,5000')

I have around 500 nodes and used doug's recommendation.

This is my sample code that works (in python):

f = Digraph('companies',filename='companies.gv',
          edge_attr={'weight':'1',
                     'fontsize':'11',
                     'fontcolor':'blue',
                     'len':'4'},
          graph_attr={'fixedsize':'false', 
                      'bgcolor':'transparent'},
          node_attr={'fontsize':'11', 
                     'shape':'plaintext', 
                     'color':'none',
                     'fontcolor':'black'})

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