source: trunk/Jgraph/complex-examples/tree.awk@ 631

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

Jgraph: Debian changes by pzn@…

File size: 1.4 KB
Line 
1# This is an awk 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" | awk -f tree.awk ; echo "xaxis size 5.4" ) | jgraph -P
8#
9# and
10# ( echo "5 2" | awk -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
20# Calculate node locations
21
22 if (j == 0) {
23 numleaves = n ^ (m - 1)
24 for (i = 0; i < numleaves; i++) newleafloc[i] = i
25 } else {
26 numleaves = numleaves / n
27 for (i = 0; i < numleaves; i++) {
28 newleafloc[i] = (oldleafloc[i*n] + oldleafloc[i*n+n-1]) / 2.0
29 }
30 }
31
32# Print the nodes and labels
33
34 for (i = 0; i < numleaves; i++) {
35 printf("newcurve marktype box marksize 0.6 0.4 fill 1 pts %f %f\n",
36 newleafloc[i], j)
37 printf("newstring x %f y %f hjc vjc fontsize 6 : %d\n",
38 newleafloc[i], j, ++k)
39
40# Print the arcs to children nodes
41
42 if (j > 0) {
43 for (l = 0; l < n; l++) {
44 printf("newcurve marktype none linetype solid pts %f %f %f %f\n",
45 newleafloc[i], j-.2, oldleafloc[i*n+l], j-.8)
46 }
47 }
48 }
49 for (i = 0; i < numleaves; i++) {
50 oldleafloc[i] = newleafloc[i]
51 }
52 }
53}
Note: See TracBrowser for help on using the repository browser.