如何在 Graphviz 中划掉一个节点?

How can I cross out a node in Graphviz?

我想指出应该有一个节点,但目前流程中缺少该节点。 直觉上我想将其划掉,如下图所示(现在在 Paint 中手动完成):

Graphviz 中是否有我可以用于此目的的节点属性?

我找不到属性或节点形状来执行您想要的操作,但有两种方法可以执行此操作:

  1. 在 Graphviz 之外构建图像(使用文本和 X)并使用图像属性将图像用作节点(是的,如果你想经常这样做会很痛苦):

    b [image="myB.png"]

  2. 对于每个 X'd out 节点,添加从 .ne 到 .sw 和 .nw 到 .se 的 2 条新边(见下文)每个都有这个(新)属性:straightline=1。然后 运行 这个命令:

dot -Tdot Xout2.gv |gvpr -f straightline.gvpr -c | neato -n2 -Tpng >out.png

这里是straightline.gvpr:

E[straightline==1]{
  int i, n;
  string pt[int];
  double x1, y1, x2, y2, xI1, yI1, xI2, yI2;

  n=split($.pos, pt, " ");

  for (i=0;i<=1;i++){
    if (match(pt[i],"e,")>=0){
      print ("//  BEFORE: ", pt[i]);
      pt[n-1]=substr(pt[i],2);
      print ("//  AFTER: ", pt[i]);
      pt[i]=pt[i+1];
    }
  }
  for (i=0;i<=1;i++){
    if (match(pt[i],"s,")>=0){
      pt[0]=substr(pt[i],2);
    }
  }

  sscanf (pt[0], "%f,%f", &x1, &y1);
  sscanf (pt[n-1], "%f,%f", &x2, &y2);
  xI1=x1+(x2-x1)*.3;
  yI1=y1+(y2-y1)*.3;
  xI2=x1+(x2-x1)*.7;
  yI2=y1+(y2-y1)*.7;

  $.pos=sprintf("%s %.3f,%.3f %.3f,%.3f %s", pt[0], xI1, yI1, xI2, yI2, pt[n-1]);
}

来自这个输入:

digraph X{
  graph [outputorder=edgefirst]

  b [ label="X me"]
  a -> b -> c 
  a -> d
  d -> c

  e -> f 
  g -> i -> k

  edge [color="#ff000080" penwidth=2]  // note translucent color
  b:ne -> b:sw  [straightline=1]
  b:se -> b:nw  [straightline=1]

  edge [color="green" penwidth=2]
  e:n -> e:s  [straightline=1]
  f:w -> f:se [straightline=1]

  edge [color="orange" penwidth=2]
  g:n -> g:se [dir=back straightline=1]
  edge [color="blue" penwidth=2]
  g:n -> g:sw [dir=back straightline=1]
  i:e -> i:w [dir=none straightline=1]
  k -> k:s [dir=both straightline=1]
}

抱歉,有点费解,但它确实有效。

虽然 给出了我需要的确切输出,但它要求我了解如何在我的工作流程中引入 gvpr,这会花费一些时间。

与此同时,我想出了一个 dot 唯一的方法,它近似于为我的目的划掉一个节点。

在下图中,我想划掉节点 Some process:

digraph graphname {
    rankdir=LR
    node [fillcolor="lightblue3", style="filled"]
        a
        c
        d
        b [label="Some\nprocess"]
    a -> b -> c
    a -> d -> c
    {rank=same a;d}
}

为此,我更改:

digraph graphname {
    rankdir=LR
    node [fillcolor="lightblue3", style="filled"]
        a
        c
        d
    node [fillcolor="lightblue3;0.5:white", style="filled", fontcolor="gray50", color="gray50", gradientangle=100]
        b [label=<<s>Some<br/>process</s>>]
    a -> b -> c
    a -> d -> c
    {rank=same a;d}
}