source: trunk/Jgraph/tree.awk@ 626

Last change on this file since 626 was 418, checked in by Nicholas Riley, 17 years ago

Jgraph 8.3 from http://www.cs.utk.edu/~plank/plank/jgraph/jgraph.tar.gz

File size: 1.3 KB
Line 
1# This is an nawk script for plotting m-level n-ary trees in jgraph.
2# For each line of input, it will produce a new jgraph. The line must
3# contain two numbers: m and n, separated by white-space.
4#
5# Two nice outputs of this are:
6#
7# ( echo "4 3" | nawk -f tree.awk ; echo "xaxis size 5.4" ) | jgraph -P
8#
9# and
10# ( echo "5 2" | nawk -f tree.awk ; echo "xaxis size 5" ) | jgraph -P
11#
12
13{ m = $1
14 n = $2
15
16 printf("newgraph xaxis nodraw yaxis nodraw\n")
17 k = 0
18 for (j = 0; j < m; j++) {
19 if (j == 0) {
20 numleaves = n ^ (m - 1)
21 for (i = 0; i < numleaves; i++) newleafloc[i] = i
22 } else {
23 numleaves = numleaves / n
24 for (i = 0; i < numleaves; i++) {
25 newleafloc[i] = (oldleafloc[i*n] + oldleafloc[i*n+n-1]) / 2.0
26 }
27 }
28 for (i = 0; i < numleaves; i++) {
29 printf("newcurve marktype box marksize 0.6 0.4 fill 1 pts %f %f\n",
30 newleafloc[i], j)
31 printf("newstring x %f y %f hjc vjc fontsize 6 : %d\n",
32 newleafloc[i], j, ++k)
33 if (j > 0) {
34 for (l = 0; l < n; l++) {
35 printf("newcurve marktype none linetype solid pts %f %f %f %f\n",
36 newleafloc[i], j-.2, oldleafloc[i*n+l], j-.8)
37 }
38 }
39 }
40 for (i = 0; i < numleaves; i++) {
41 oldleafloc[i] = newleafloc[i]
42 }
43 }
44}
Note: See TracBrowser for help on using the repository browser.