Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraphViz enforce columns

I have the following dot:

digraph G
{
    rank="same";
    subgraph sys
    {
        1 [shape=record, label="| | Système"];
    }

    subgraph obj
    {
        2 [shape=box, label="Sites"];
        3 [shape=box, label="Sociétés de\nmaintenance"];
        1 -> 2 [arrowhead=none] [label="a"];
        1 -> 3 [arrowhead=none] [label="b"];
    }

    subgraph constraints
    {
        4 [style=dotted, label="Surveiller"];
        5 [style=dotted, label="Effectuer des\ninterventions"];
        4 -> 2 [style=dotted];
        4 -> 3 [style=dotted];
        5 -> 2 [style=dotted];
        5 -> 3 [style=dotted];
    }

}

Which gives me this image:

enter image description here

But I want to have a subgraph by column (1 on the first column, 2-3 on the second and 4-5 on the last).

Is there a way to do that?

For your help, Thanks by advance.

like image 333
GlinesMome Avatar asked Feb 18 '23 20:02

GlinesMome


1 Answers

digraph G
{
    rank=same
    rankdir=LR

    subgraph sys
    {
        1 [shape=record, label="| | Système"]
    }
    subgraph obj
    {
        node [shape=box]
        2 [label="Sites"]
        3 [label="Sociétés de\nmaintenance"]
    }
    subgraph constraints
    {
        node [style=dotted]
        4 [label="Surveiller"]
        5 [label="Effectuer des\ninterventions"]
    }

    edge [style=invis, weight=2]
    2->4
    3->5

    edge [style=dotted]
    4 -> 2
    4 -> 3
    5 -> 2
    5 -> 3

    edge [style="" arrowhead=none]
    1 -> 2 [label="a"]
    1 -> 3 [label="b"]
} 

This solution is the same as suggested by @alexandr_anturis (+1), but I have removed some irrelevant 'syntax noise', because I feel that such a complex and powerful specification as dot language benefits of any simplification available.

Use rankdir and hidden edges with appropriate weight.

Picture of the result:

enter image description here

like image 127
CapelliC Avatar answered Feb 23 '23 14:02

CapelliC