addrings 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Takes a graph laid out by twopi and adds rings.
  2. * Assumes ARGV[] = "root" "=" <rootname>, as output by twopi -v.
  3. * Usage:
  4. * twopi -v foo.dot > out 2> log
  5. * gvpr -f addrings.g -a"`grep root log`" out | neato -n2 ...
  6. */
  7. BEG_G {
  8. graph_t og;
  9. edge_t e;
  10. node_t ctr = node($, ARGV[0]);
  11. double rs = 1.0; /* min. slack between the squares of two consecutive radii */
  12. int cx, cy;
  13. int x, y;
  14. node_t n;
  15. int i, n_r;
  16. int d;
  17. int rads[int];
  18. char* ctr_s = ctr.pos;
  19. sscanf (ctr_s, "%d,%d", &cx, &cy);
  20. if (hasAttr($, "ranksep")) {
  21. sscanf ($.ranksep, "%f", &rs);
  22. if (rs == 0.0) rs = 1.0;
  23. }
  24. rs *= 72;
  25. rs = 1.5*rs*rs;
  26. }
  27. N [$ != ctr] {
  28. sscanf ($.pos, "%d,%d", &x, &y);
  29. d = (x-cx)*(x-cx) + (y-cy)*(y-cy);
  30. for (rads[i]) {
  31. if ((rads[i]-rs <= d) && (d <= rads[i]+rs)) return;
  32. }
  33. n_r++;
  34. rads[n_r] = d;
  35. }
  36. END_G {
  37. og = copy (NULL, $);
  38. og.outputorder = "nodesfirst";
  39. setDflt (og, "N", "label", "\\N");
  40. for (rads[i]) {
  41. n = node(og, "ring_"+((string)i));
  42. n.shape = "circle";
  43. n.pos = ctr_s;
  44. n.style = "";
  45. n.label = "";
  46. d = rads[i];
  47. n.width = sprintf("%f", sqrt(d)/36.0);
  48. }
  49. for (n=fstnode($);n;n = nxtnode(n))
  50. clone (og, n);
  51. for (n=fstnode($);n;n = nxtnode(n))
  52. for (e=fstedge(n);e;e = nxtedge(e,n))
  53. clone (og, e);
  54. write(og);
  55. }