bb 997 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* computes the bounding box of a graph based on its nodes
  2. taking into account clusters and node sizes.
  3. */
  4. BEGIN {
  5. double x, y, w2, h2;
  6. double llx, lly, urx, ury;
  7. double llx0, lly0, urx0, ury0;
  8. graph_t clustBB (graph_t G) {
  9. graph_t sg;
  10. for (sg = fstsubg(G); sg; sg = nxtsubg(sg)) {
  11. sg = clustBB(sg);
  12. }
  13. if (G.name == "cluster*") {
  14. sscanf (G.bb, "%lf,%lf,%lf,%lf", &llx0, &lly0, &urx0, &ury0);
  15. if (llx0 < llx) llx = llx0;
  16. if (lly0 < lly) lly = lly0;
  17. if (urx0 > urx) urx = urx0;
  18. if (ury0 > ury) ury = ury0;
  19. }
  20. return G;
  21. }
  22. }
  23. BEG_G {
  24. llx = 1000000; lly = 1000000; urx = -1000000; ury = -1000000;
  25. }
  26. N {
  27. sscanf ($.pos, "%lf,%lf", &x, &y);
  28. w2 = (36.0*(double)$.width);
  29. h2 = (36.0*(double)$.height);
  30. if ((x - w2) < llx) llx = x - w2;
  31. if ((x + w2) > urx) urx = x + w2;
  32. if ((y - h2) < lly) lly = y - h2;
  33. if ((y + h2) > ury) ury = y + h2;
  34. }
  35. END_G {
  36. clustBB ($);
  37. $.bb = sprintf ("%lf,%lf,%lf,%lf", llx, lly, urx, ury);
  38. }