| 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 |
|
| 12 |
int setScale (char* s) |
| 13 |
{ |
| 14 |
if ((sscanf (s, ",%f",&scaley))) { |
| 15 |
scalex = 1; |
| 16 |
return 1; |
| 17 |
} |
| 18 |
else { |
| 19 |
r = sscanf (s, "%f,%f",&scalex,&scaley); |
| 20 |
if (r) { |
| 21 |
if (r == 1) scaley = 1; |
| 22 |
return 1; |
| 23 |
} |
| 24 |
} |
| 25 |
return 0; |
| 26 |
} |
| 27 |
|
| 28 |
} |
| 29 |
|
| 30 |
BEG_G { |
| 31 |
node_t ctr = node($,aget($,"root")); |
| 32 |
double cx, cy, x, y, delx; |
| 33 |
|
| 34 |
/* get scale argument */ |
| 35 |
done = 0; |
| 36 |
if (ARGC == 1) |
| 37 |
done = setScale (ARGV[0]); |
| 38 |
if (!done && isAttr($,"G","scale")) |
| 39 |
done = setScale ($.scale); |
| 40 |
if (!done) |
| 41 |
scalex = scaley = 1.0; |
| 42 |
|
| 43 |
if ((scalex == 1.0) && (scaley == 1.0)) |
| 44 |
exit (0); |
| 45 |
|
| 46 |
$.bb = ""; |
| 47 |
sscanf (ctr.pos, "%f,%f", &cx, &cy); |
| 48 |
} |
| 49 |
N [$ != ctr] { |
| 50 |
sscanf ($.pos, "%f,%f", &x, &y); |
| 51 |
delx = scalex*(x - cx) + cx; |
| 52 |
dely = scaley*(y - cy) + cy; |
| 53 |
$.pos = sprintf ("%f,%f", delx, dely); |
| 54 |
} |