DOT可以生成更结构化的图吗? [英] Can DOT produce a more structured graph?

查看:111
本文介绍了DOT可以生成更结构化的图吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太确定如何描述客户的需求,所以我将大部分时间放在图片上.我正在使用DOT生成有关物料清单问题的图形.(在各个级别上显示从入库物料中创建的入库批次和所有出库批次.)我已经获得了创建包含适当结构化数据的图形的代码.例如,我生成了这个GV文件:

  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;} 

并生成此图形:

但是我的客户真正想要的是看起来更像这样的东西,其中的边缘是直线,并根据需要使用90度角.(请注意,这是通用的,而不是基于上面的示例.)

有没有一种方法可以使用DOT生成类似的东西?

解决方案

您可以尝试

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:

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.)

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

解决方案

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:

这篇关于DOT可以生成更结构化的图吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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