更改twopi布局中根节点中边的方向

问题描述 投票:0回答:1


我正在尝试弄清楚如何在这两个图表之间切换。

我正在使用twopi布局。
我尝试了各种方法,但找不到它的工作原理。
有人可以帮助我吗?

digraph G {

layout=twopi;

node [shape=circle]

0 -> 1
0 -> 2
1 -> 3
1 -> 4
2 -> 5
2 -> 6

}
graphviz dot
1个回答
0
投票

我认为没有办法直接 twopi 修改节点位置。您可以尝试添加不可见的节点和边,但充其量这只是一场斗争。
这是一个(稍作修改的)gvpr程序,它将获取原始输出并“旋转”(径向重新定位)指定节点(您的根)周围的所有节点。 [已对其进行修改以避免最新版本的 gvpr 中的错误]
gvpr (https://www.graphviz.org/pdf/gvpr.1.pdf) 是 Graphviz 包的一部分,所以你应该拥有它。 gvpr 程序:rotateNew.gvpr

/* Given node name and angle, rotate a layout using the given
 * node as origin.
 */

BEGIN {
  double x,y;
  double x0,y0;
  double x1,y1;
  double angle, cosa, sina;
  int cnt, sz;

  void rotate (double a, double b) {
    a -= x0;
    b -= y0;
    x1 = a*cosa - b*sina;
    y1 = a*sina + b*cosa;
  }
  char* rotateE (char* p) {
    char* newpos = "";
    cnt = sscanf (p, "e,%lf,%lf%n", &x, &y, &sz);
    if (cnt == 2) {
      rotate (x,y);
      newpos = newpos + sprintf ("e%lf,%lf ", x1, y1);
      p = substr(p, sz);
    }
    cnt = sscanf (p, "s,%lf,%lf%n", &x, &y, &sz);
    if (cnt == 2) {
      rotate (x,y);
      newpos = newpos + sprintf ("s%lf,%lf ", x1, y1);
      p = substr(p, sz);
    }

    while (sscanf (p, "%lf,%lf%n", &x, &y, &sz) == 2) {
      rotate (x,y);
      newpos = newpos + sprintf ("%lf,%lf ", x1, y1);
      p = substr(p, sz);
    }
    print("// returning: ", newpos);
    return newpos;
  }
}

BEG_G {
  node_t ctr = node ($, ARGV[0]);

  sscanf (ARGV[1], "%f", &angle);
  print("// using >", ctr.name, "<   >", angle, "<");
  cosa = cos(angle);
  sina = sin(angle);
  print("// old pos: ", ctr.name, "  ", ctr.pos);  
  sscanf (ctr.pos, "%f,%f", &x0, &y0);
  print("// new pos: ", ctr.name, "  ", ctr.pos);  
  $.bb ="";
}
N {
  sscanf ($.pos, "%f,%f", &x, &y);
  rotate (x,y);
  print("// old pos: ", $.name, "  ", $.pos);    
  $.pos = sprintf ("%f,%f", x1, y1);
  print("// new pos: ", $.name, "  ", $.pos);  
}
E {
  // bug $.pos = rotateE($.pos);
  $.pos="";
}

命令行 - 提供两个参数 w/ -a 节点名称和角度(以弧度为单位):

twopi myfile.gv |gvpr -cfrotateNew.gvpr -a "0 1.57" |neato -n -Tpng >myfile.png

有关这组程序的更多信息:https://graphviz.org/faq/#FaqDotWithNodeCoords

结果(注意水平边缘较短):

© www.soinside.com 2019 - 2024. All rights reserved.