【问题标题】:Can DOT produce a more structured graph?DOT 可以生成更结构化的图吗?
【发布时间】:2019-08-19 11:46:04
【问题描述】:

我不确定如何描述我的客户想要什么,所以我会用一张图片来做大部分的谈话。我正在使用 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 来制作类似的东西?

【问题讨论】:

    标签: graphviz dot


    【解决方案1】:

    您可以尝试splines=ortho 图形属性。它以 90 度角进行非常直的连接。

    但我不会推荐它。几乎不可能控制它们,端口规范通常不适用于它们,而且正交样条可能会占用一些边缘标签。

    可能的解决方案将使用具有point 形状的虚拟节点(这种形状很方便,因为它默认删除节点标签)和width=0。在需要 90 度转弯的地方使用这些虚拟节点。您必须将它们与子图中的主节点分组并添加rank=same 属性以强制这些节点保持在同一级别。

    您可能还需要在某些边缘添加weight 以防止它们弯曲(重量较大的边缘往往是直的)。

    示例

    我已经使用提到的技术实现了您的示例图的一部分,代码和图像如下:

    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
    }
    

    结果:

    【讨论】:

    • 谢谢。现在我们解决了一些其他问题,看起来我的客户可能会满意而不这样做。但如果他想要,我会回到这个。
    猜你喜欢
    • 1970-01-01
    • 2016-12-01
    • 1970-01-01
    • 2010-12-17
    • 2020-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多