子图聚类点排序

发布于 2024-08-26 08:57:05 字数 660 浏览 4 评论 0原文

我正在尝试使用媒体维基上的 graphviz 作为软件的文档工具。

首先,我记录了一些运行良好的类关系。一切都按预期垂直排列。

但是,我们的一些模块是 dll,我想将它们分成一个盒子。当我将节点添加到集群时,它们变得边缘化,但集群似乎有 LR 排名规则。或者添加到集群会破坏节点的 TB 排名,因为集群现在出现在图表的一侧。

该图代表了我正在尝试做的事情:目前,cluster1 和 cluster2 出现在 cluster0 的右侧

我希望/需要它们出现在下面。

<graphviz>
digraph d {
    subgraph cluster0 {
      A -> {B1 B2}
      B2 -> {C1 C2 C3}
      C1 -> D;
    }
    subgraph cluster1 {
      C2 -> dll1_A;
      dll1_A -> B1;
    }
    subgraph cluster2 { 
      C3 -> dll2_A;
    }
    dll1_A -> dll2_A;
}
</graphviz>

I'm trying to use graphviz on media wiki as a documentation tool for software.

First, I documented some class relationships which worked well. Everything was ranked vertically as expected.

But, then, some of our modules are dlls, which I wanted to seperate into a box. When I added the nodes to a cluster, they got edged, but clusters seem to have a LR ranking rule. Or being added to a cluster broke the TB ranking of the nodes as the cluster now appears on the side of the graph.

This graph represents what I am trying to do: at the moment, cluster1 and cluster2 appear to the right of cluster0.

I want/need them to appear below.

<graphviz>
digraph d {
    subgraph cluster0 {
      A -> {B1 B2}
      B2 -> {C1 C2 C3}
      C1 -> D;
    }
    subgraph cluster1 {
      C2 -> dll1_A;
      dll1_A -> B1;
    }
    subgraph cluster2 { 
      C3 -> dll2_A;
    }
    dll1_A -> dll2_A;
}
</graphviz>

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

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

发布评论

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

评论(3

满身野味 2024-09-02 08:57:05

这种布局是 Dot 试图最小化整体高度的尝试。

布局比所需布局更紧凑的原因之一是使用了从 dll1_aB1 的相反方向的边缘。它尝试将集群拉回尽可能靠近目标节点的位置。为了避免此边缘影响图形,请放松向上边缘的约束(如图所示),或者沿向前方向绘制边缘并使用dir属性反转箭头。

这将有助于许多布局,但仅靠它还不足以修复给出的示例。为了防止 Dot 保持紧凑的布局,您可以向应保持(接近)垂直的边缘添加 minlen 属性。一般来说,这可能很难计算,但对于手动调整的布局来说很实用。

digraph d {
    subgraph cluster0 {
        A -> {B1 B2}    
        B2 -> {C1 C2 C3}
        C1 -> D;
    }
    subgraph cluster1 {
        C2 -> dll1_A [minlen = 2];
        dll1_A -> B1 [constraint = false];
        /* B1 -> dll1_A [dir = back]; */
    }
    subgraph cluster2 {
        C3 -> dll2_A;
    }
    dll1_A -> dll2_A;
}

更正的布局

The layout is an attempt by Dot to minimise the overall height.

One reason for the more compact than required layout is the use of the edge that goes in the reverse direction from dll1_a to B1. It tries to pull the cluster as close back to the destination node as possible. To avoid this edge affecting the graph, either relax the constraint on the upwards edges as shown, or draw the edge in the forward direction and use the dir attribute to reverse the arrow.

This will help with many layouts but it alone is not sufficient to fix the example given. To prevent Dot from maintaining the compact layout it prefers you can add a minlen attribute to edges that should remain (near) vertical. This may be difficult to calculate in general but is practical for manually tuned layouts.

digraph d {
    subgraph cluster0 {
        A -> {B1 B2}    
        B2 -> {C1 C2 C3}
        C1 -> D;
    }
    subgraph cluster1 {
        C2 -> dll1_A [minlen = 2];
        dll1_A -> B1 [constraint = false];
        /* B1 -> dll1_A [dir = back]; */
    }
    subgraph cluster2 {
        C3 -> dll2_A;
    }
    dll1_A -> dll2_A;
}

Corrected layout

你爱我像她 2024-09-02 08:57:05

我的经验表明,constraint=false 通常会产生不必要的复杂边缘。看来 weight=0 给出了更好的结果:

digraph d {
    subgraph cluster0 {
        A -> {B1 B2}    
        B2 -> {C1 C2 C3}
        C1 -> D;
    }
    subgraph cluster1 {
        C2 -> dll1_A [minlen = 2];
        dll1_A -> B1 [weight = 0];
        /* B1 -> dll1_A [dir = back]; */
    }
    subgraph cluster2 {
        C3 -> dll2_A;
    }
    dll1_A -> dll2_A;
}

My experience shows that constraint=false commonly gives unnecessarily convoluted edges. It seems that weight=0 gives better results:

digraph d {
    subgraph cluster0 {
        A -> {B1 B2}    
        B2 -> {C1 C2 C3}
        C1 -> D;
    }
    subgraph cluster1 {
        C2 -> dll1_A [minlen = 2];
        dll1_A -> B1 [weight = 0];
        /* B1 -> dll1_A [dir = back]; */
    }
    subgraph cluster2 {
        C3 -> dll2_A;
    }
    dll1_A -> dll2_A;
}
深海少女心 2024-09-02 08:57:05

这将生成您正在寻找的图表:

digraph d {
  subgraph cluster0 {
    A -> {B1 B2}
    B2 -> {C1 C2 C3}
    C1 -> D;
  }

  subgraph {
    rankdir="TB"
    subgraph cluster1 {
      C2 -> dll1_A;
      dll1_A -> B1;
    }

    subgraph cluster2 {
      C3 -> dll2_A;
    }
  }
  dll1_A -> dll2_A;
}

它的作用是创建一个仅用于布局目的的子图,以提供您想要的从上到下的排序。

This will produce the graph you are looking for:

digraph d {
  subgraph cluster0 {
    A -> {B1 B2}
    B2 -> {C1 C2 C3}
    C1 -> D;
  }

  subgraph {
    rankdir="TB"
    subgraph cluster1 {
      C2 -> dll1_A;
      dll1_A -> B1;
    }

    subgraph cluster2 {
      C3 -> dll2_A;
    }
  }
  dll1_A -> dll2_A;
}

What this does is creat a subgraph that is used only for layout purposes to provide the top to bottom ordering that you desire.

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