Tamar E. Granor
Tamar E. Granor

Reputation: 3937

Can DOT produce a more structured graph?

I'm not really sure how to describe what my client wants, so I'll let a picture do most of the talking. I'm using DOT to produce graphs for what is more or less the bill of materials problem. (Show an incoming lot and all the outgoing lots, at all levels, that were created from the material in the incoming lot.) I've got the code to create a graph that contains the data structured appropriately. For example, I generate this GV file:

digraph LotTrc {
  rankdir=LR;
  graph[label="Lot #AD626", labelloc=top, labeljust=left, fontsize=24];
   PO_AD626_0000003333[shape=triangle,color=greenyellow,style=filled,label=AD626];
   AJ_AD626_SJ00000099[shape=circle,color=red2,style=filled,label=AD626];
   PO_AD626_0000003333  -> AJ_AD626_SJ00000099;
   AJ_AD626_SJ00000103[shape=circle,color=red2,style=filled,label=AD626];
   PO_AD626_0000003333  -> AJ_AD626_SJ00000103;
   WO_AD627_RE00002230[shape=ellipse,color=lemonchiffon,style=filled,label=AD627];
   PO_AD626_0000003333  -> WO_AD627_RE00002230;
   SO_AD627_OZ00025429[shape=box,color=cyan3,style=filled,label=AD627];
   WO_AD627_RE00002230  -> SO_AD627_OZ00025429;
   SO_AD627_OZ00025434[shape=box,color=cyan3,style=filled,label=AD627];
   WO_AD627_RE00002230  -> SO_AD627_OZ00025434;
   SO_AD627_OZ00025439[shape=box,color=cyan3,style=filled,label=AD627];
   WO_AD627_RE00002230  -> SO_AD627_OZ00025439;
   SO_AD627_OZ00025444[shape=box,color=cyan3,style=filled,label=AD627];
   WO_AD627_RE00002230  -> SO_AD627_OZ00025444;
   WO_AD628_RE00002231[shape=ellipse,color=lemonchiffon,style=filled,label=AD628];
   PO_AD626_0000003333  -> WO_AD628_RE00002231;
   SO_AD628_OZ00025430[shape=box,color=cyan3,style=filled,label=AD628];
   WO_AD628_RE00002231  -> SO_AD628_OZ00025430;
   SO_AD628_OZ00025435[shape=box,color=cyan3,style=filled,label=AD628];
   WO_AD628_RE00002231  -> SO_AD628_OZ00025435;
   SO_AD628_OZ00025440[shape=box,color=cyan3,style=filled,label=AD628];
   WO_AD628_RE00002231  -> SO_AD628_OZ00025440;
   SO_AD628_OZ00025445[shape=box,color=cyan3,style=filled,label=AD628];
   WO_AD628_RE00002231  -> SO_AD628_OZ00025445;
   WO_AD629_RE00002232[shape=ellipse,color=lemonchiffon,style=filled,label=AD629];
   PO_AD626_0000003333  -> WO_AD629_RE00002232;
   SO_AD629_OZ00025431[shape=box,color=cyan3,style=filled,label=AD629];
   WO_AD629_RE00002232  -> SO_AD629_OZ00025431;
   SO_AD629_OZ00025436[shape=box,color=cyan3,style=filled,label=AD629];
   WO_AD629_RE00002232  -> SO_AD629_OZ00025436;
   SO_AD629_OZ00025441[shape=box,color=cyan3,style=filled,label=AD629];
   WO_AD629_RE00002232  -> SO_AD629_OZ00025441;
   SO_AD629_OZ00025446[shape=box,color=cyan3,style=filled,label=AD629];
   WO_AD629_RE00002232  -> SO_AD629_OZ00025446;
   WO_AD630_RE00002233[shape=ellipse,color=lemonchiffon,style=filled,label=AD630];
   PO_AD626_0000003333  -> WO_AD630_RE00002233;
   SO_AD630_OZ00025432[shape=box,color=cyan3,style=filled,label=AD630];
   WO_AD630_RE00002233  -> SO_AD630_OZ00025432;
   SO_AD630_OZ00025437[shape=box,color=cyan3,style=filled,label=AD630];
   WO_AD630_RE00002233  -> SO_AD630_OZ00025437;
   SO_AD630_OZ00025442[shape=box,color=cyan3,style=filled,label=AD630];
   WO_AD630_RE00002233  -> SO_AD630_OZ00025442;
   SO_AD630_OZ00025447[shape=box,color=cyan3,style=filled,label=AD630];
   WO_AD630_RE00002233  -> SO_AD630_OZ00025447;
   WO_AD631_RE00002234[shape=ellipse,color=lemonchiffon,style=filled,label=AD631];
   PO_AD626_0000003333  -> WO_AD631_RE00002234;
   SO_AD631_OZ00025433[shape=box,color=cyan3,style=filled,label=AD631];
   WO_AD631_RE00002234  -> SO_AD631_OZ00025433;
   SO_AD631_OZ00025438[shape=box,color=cyan3,style=filled,label=AD631];
   WO_AD631_RE00002234  -> SO_AD631_OZ00025438;
   SO_AD631_OZ00025443[shape=box,color=cyan3,style=filled,label=AD631];
   WO_AD631_RE00002234  -> SO_AD631_OZ00025443;
   SO_AD631_OZ00025448[shape=box,color=cyan3,style=filled,label=AD631];
   WO_AD631_RE00002234  -> SO_AD631_OZ00025448;

}

and it produces this graph: enter image description here

But what my client really wants is something that looks more like this, where the edges are straight lines, using 90 degree angles as needed. (Note that this is generic, not based on the example above.)

enter image description here

Is there a way to use DOT to produce something like that?

Upvotes: 4

Views: 913

Answers (1)

Dany
Dany

Reputation: 4730

You can experiment with splines=ortho graph attibute. It makes the very straight connections with 90 degree angles.

But I won't recommend it. It's almost impossible to control them, port specification often doesn't work with them, and also, ortho splines may eat up some of the edge lables.

Possible solution would be using dummy nodes with point shape (this shape is convenient because it removes node lable by default) and width=0. Use these dummy nodes in places where the 90 degree turn is needed. You will have to group them with main nodes in subgraphs and add rank=same attribute to force these nodes to stay at the same level.

You would probably also need to add weight to some edges to prevent them from being bent (edges with higher weight tend to be straight).

Example

I've implemented part of your example graph using mentioned techniques, the code and image are below:

digraph {
    rankdir=LR
    ranksep=1
    nodesep=0.5

    LOT1 [shape=rect]
    LOT2 [shape=rect]
    LOT3 [shape=rect]
    LOT4 [shape=rect]
    LOT5 [shape=rect]

    {rank=same
        PO
        dot1 [shape=point width=0]
        dot2 [shape=point width=0]
        PO -> dot1 -> dot2 [arrowhead=none]
    }
    dot1 -> WO1 [weight=20]
    {
        rank=same
        WO1
        dot21  [shape=point width=0]
        dot22  [shape=point width=0]
        WO1 -> dot21 -> dot22 [arrowhead=none]
    }
    dot21 -> LOT1 [weight=20]
    dot22 -> LOT2 [weight=20]
    {
        rank=same
        dot31 [shape=point width=0]
        dot32 [shape=point width=0]
        dot33 [shape=point width=0]
        dot31 -> dot32 -> dot33 [arrowhead=none]
    }
        dot2 -> WO2 [weight=20]
    {
        WO2
        rank=same
        dot23 [shape=point width=0]
        dot24 [shape=point width=0]
        dot25 [shape=point width=0]
        WO2 -> dot23 -> dot24 -> dot25 [arrowhead=none]
    }
    dot23 -> LOT3 [weight=20]
    dot24 -> LOT4 [weight=20]
    dot25 -> LOT5 [weight=20]
    dot31 -> SO1
    dot33 -> SO2
    LOT1 -> dot32
}

Result:

enter image description here

Upvotes: 6

Related Questions