GraphViz - 如何连接子图? [英] GraphViz - How to connect subgraphs?

查看:44
本文介绍了GraphViz - 如何连接子图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GraphVizDOT 语言中,我试图表示一个依赖关系图.我需要能够在容器内拥有节点,并且能够使节点和/或容器依赖于其他节点和/或容器.

In the DOT language for GraphViz, I'm trying to represent a dependency diagram. I need to be able to have nodes inside a container and to be able to make nodes and/or containers dependent on other nodes and/or containers.

我使用 subgraph 来表示我的容器.节点链接工作正常,但我不知道如何连接子图.

I'm using subgraph to represent my containers. Node linking works just fine, but I can't figure out how to connect subgraphs.

鉴于下面的程序,我需要能够使用箭头连接 cluster_1cluster_2,但是我尝试过的任何操作都会创建新节点而不是连接集群:

Given the program below, I need to be able to connect cluster_1 and cluster_2 with an arrow, but anything I've tried creates new nodes instead of connecting the clusters:

digraph G {

    graph [fontsize=10 fontname="Verdana"];
    node [shape=record fontsize=10 fontname="Verdana"];

    subgraph cluster_0 {
        node [style=filled];
        "Item 1" "Item 2";
        label = "Container A";
        color=blue;
    }

    subgraph cluster_1 {
        node [style=filled];
        "Item 3" "Item 4";
        label = "Container B";
        color=blue;
    }

    subgraph cluster_2 {
        node [style=filled];
        "Item 5" "Item 6";
        label = "Container C";
        color=blue;
    }

    // Renders fine
    "Item 1" -> "Item 2";
    "Item 2" -> "Item 3";

    // Both of these create new nodes
    cluster_1 -> cluster_2;
    "Container A" -> "Container C";
}

推荐答案

DOT 用户手册给出了以下示例,其中包含簇之间具有边的簇:

The DOT user manual gives the following example of a graph with clusters with edges between clusters:

重要提示:初始 compound=true 语句是必需的.

IMPORTANT: The initial compound=true statement is required.

digraph G {
  compound=true;
  subgraph cluster0 {
    a -> b;
    a -> c;
    b -> d;
    c -> d;
  }
  subgraph cluster1 {
    e -> g;
    e -> f;
  }
  b -> f [lhead=cluster1];
  d -> e;
  c -> g [ltail=cluster0,lhead=cluster1];
  c -> e [ltail=cluster0];
  d -> h;
}

... 以及节点和集群之间的边:

... and edges between nodes and clusters:

这篇关于GraphViz - 如何连接子图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆