clt60
clt60

Reputation: 63974

simple "T shaped" graph in graphviz

Need draw a graph with dot/graphviz like this image: simple T shaped graph

The texts can be above arrows, like graphviz does it. But how to achieve the T-layout? Need make a cluster for the top row?

Upvotes: 1

Views: 758

Answers (2)

marapet
marapet

Reputation: 56586

This is one possibility using rank=same for a subgraph:

digraph g {
    node[shape=point, width=0.2];
    {
        rank=same;
        p1 -> n [label="text1"];
        n -> p2 [label="text2"];
    }
    n -> p3 [label="text3", dir=back];
    n[label="node", shape=rect, style=rounded];
}

You could also use a left-right layout instead of top-down.

An other possibility is to disable the effect of some edges using constraint=false:

digraph g {
    node[shape=point, width=0.2];
    p1 -> n [label="text1", constraint=false];
    n -> p2 [label="text2", constraint=false];
    n -> p3 [label="text3", dir=back];
    n[label="node", shape=rect, style=rounded];
}

The result is the same.

Upvotes: 3

Joey
Joey

Reputation: 354864

dot usually layouts trees in layers. To force an edge to not be a layer separation you can add the constraint=false option. So something like:

digraph {
  A [shape=point]
  B [shape=point]
  C [shape=point]
  N [label="node"]

  A -> N [label="text1", constraint=false]
  N -> B [label="text2", constraint=false]
  N -> C [label="text3", dir=back]
}

should work.

Note that the edge from the lower node to "node" has to be backwards, since dot layouts trees from top to bottom. Therefore the logical edge direction has to be from top to bottom, even though the display direction might be the other way round (which is the case here).

Upvotes: 2

Related Questions