Force GraphViz force distance between nodes

2019-05-10 20:34发布

问题:

I use GraphViz with the following dot file:

digraph G
{
    rankdir=LR;
    subgraph commits
    {
        "5c071a6b2c" -> "968bda3251" -> "9754d40473" -> "9e59700d33" -> "2a3242efa4";
    }
    subgraph annotations
    {
        "V1.0" [shape=box];
        "br/HEAD" [shape=box];
        "V1.0" -> "9e59700d33" [weight=0];
        "br/HEAD" -> "2a3242efa4" [weight=0];
    }
}

It give me something like that:

But I want something like that:

                                        V1.0         br/HEAD
                                          |             |
                                         \/            \/

5c071a6b2c -> 968bda3251 -> 9754d40473 -> 9e59700d33 -> 2a3242efa4

How can I do that?

For your help, Thanks by advance.

回答1:

This will align the annotations with the commits:

digraph G
{
    rankdir=LR;
    subgraph commits
    {
        "5c071a6b2c" -> "968bda3251" -> "9754d40473" -> "9e59700d33" -> "2a3242efa4";
    }
    subgraph annotations1
    {
        rank="same";
        "V1.0" [shape=box];
        "V1.0" -> "9e59700d33" [weight=0];
    }
    subgraph annotations2
    {
        rank="same";
        "br/HEAD" [shape=box];
        "br/HEAD" -> "2a3242efa4" [weight=0];
    }
}

Since the rank="same"; effects the whole subgraph I had to split the annotations in two different subgraphs.

Result is: