scalexy 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* finds root node of graph.
  2. * scales the x and y position of all other nodes using, first,
  3. * ARGV[0], or $G.scale.
  4. *
  5. * The expected syntax is "x,y" where at least one of x or y must
  6. * be given. If only one is given, the other is taken as 1.
  7. */
  8. BEGIN {
  9. double scalex, scaley;
  10. int r, done;
  11. int setScale (char* s)
  12. {
  13. if ((sscanf (s, ",%f",&scaley))) {
  14. scalex = 1;
  15. return 1;
  16. }
  17. else {
  18. r = sscanf (s, "%f,%f",&scalex,&scaley);
  19. if (r) {
  20. if (r == 1) scaley = 1;
  21. return 1;
  22. }
  23. }
  24. return 0;
  25. }
  26. }
  27. BEG_G {
  28. node_t ctr = node($,aget($,"root"));
  29. double cx, cy, x, y, delx;
  30. /* get scale argument */
  31. done = 0;
  32. if (ARGC == 1)
  33. done = setScale (ARGV[0]);
  34. if (!done && isAttr($,"G","scale"))
  35. done = setScale ($.scale);
  36. if (!done)
  37. scalex = scaley = 1.0;
  38. if ((scalex == 1.0) && (scaley == 1.0))
  39. exit (0);
  40. $.bb = "";
  41. sscanf (ctr.pos, "%f,%f", &cx, &cy);
  42. }
  43. N [$ != ctr] {
  44. sscanf ($.pos, "%f,%f", &x, &y);
  45. delx = scalex*(x - cx) + cx;
  46. dely = scaley*(y - cy) + cy;
  47. $.pos = sprintf ("%f,%f", delx, dely);
  48. }