source: trunk/Jgraph/complex-examples/grtoj.sh

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

Jgraph: Debian changes by pzn@…

File size: 3.0 KB
Line 
1#!/bin/sh
2
3nawk '
4
5BEGIN {
6 xmarksize = ymarksize = .3
7 marktype = "circle"
8 vfont = "Times-Roman"
9 vfontsize = 8
10 efont = "Times-Roman"
11 efontsize = 8
12 fill = 1.
13 xs = ys = 1.
14 xmin = ymin = 999999.
15 xmax = ymax = -999999.
16 n = 0
17 m = 0
18 mode = 0
19 NOLABEL = "_NOLABEL"
20 pi = 3.141593
21 deg90 = pi / 2.
22 elabdist = .1
23 vlab = elab = 1
24 larrows = rarrows = 0
25}
26
27NF == 0 || substr($1, 1, 1) == "#" { next }
28
29$1 == "xmarksize" { xmarksize = $2 ; next }
30$1 == "ymarksize" { ymarksize = $2 ; next }
31$1 == "marksize" { xmarksize = ymarksize = $2 ; next }
32$1 == "marktype" { marktype = $2 ; next }
33$1 == "vfont" { vfont = $2 ; next }
34$1 == "vfontsize" { vfontsize = $2 ; next }
35$1 == "efont" { efont = $2 ; next }
36$1 == "efontsize" { efontsize = $2 ; next }
37$1 == "font" { vfont = efont = $2 ; next }
38$1 == "fontsize" { vfontsize = efontsize = $2 ; next }
39$1 == "fill" { fill = $2 ; next }
40$1 == "xs" { xs = $2 ; next }
41$1 == "ys" { ys = $2 ; next }
42$1 == "scale" { xs = ys = $2 ; next }
43$1 == "elabdist" { elabdist = $2 ; next }
44$1 == "vlab" { vlab = $2 ; next }
45$1 == "elab" { elab = $2 ; next }
46$1 == "lab" { vlab = elab = $2 ; next }
47$1 == "larrows" { larrows = $2 ; next }
48$1 == "rarrows" { rarrows = $2 ; next }
49$1 == "arrows" { larrows = rarrows = $2 ; next }
50
51$1 == "edges" {
52 mode = 1
53 printf "newgraph\n"
54 printf "xaxis min %f max %f size %f nodraw\n", xmin, xmax, (xmax - xmin) * xs
55 printf "yaxis min %f max %f size %f nodraw\n\n", ymin, ymax, (ymax - ymin) * ys
56 next
57}
58
59$1 == "raw" { mode = 2 ; next }
60
61{
62 if (!mode) {
63 x[n] = $1
64 y[n] = $2
65 vlabel[n] = (NF == 3 ? $3 : n)
66 if (x[n] < xmin) xmin = x[n]
67 else if (x[n] > xmax) xmax = x[n]
68 if (y[n] < ymin) ymin = y[n]
69 else if (y[n] > ymax) ymax = y[n]
70 n++
71 }
72 else if (mode == 1) {
73 src[m] = label_to_node($1)
74 dst[m] = label_to_node($2)
75 elabel[m] = (NF == 3 ? $3 : NOLABEL)
76 m++
77 }
78 else
79 print $0
80}
81
82END {
83 printf "\n"
84 for (i = 0; i < n; i++) {
85 printf "newline marktype %s marksize %f %f fill %f pts %f %f\n", marktype, xmarksize, ymarksize, fill, x[i], y[i]
86 if (vlab)
87 printf "newstring x %f y %f vjc hjc font %s fontsize %d : %s\n", x[i], y[i], vfont, vfontsize, vlabel[i]
88 }
89 printf "\n"
90 for (i = 0; i < m; i++) {
91 printf "newline marktype %s marksize %f %f fill %f pts %f %f %f %f ", marktype, xmarksize, ymarksize, fill, x[src[i]], y[src[i]], x[dst[i]], y[dst[i]]
92 if (larrows) printf "larrows "
93 if (rarrows) printf "rarrows "
94 printf "\n"
95 if (elab && elabel[i] != NOLABEL) {
96 midx = (x[src[i]] + x[dst[i]]) / 2.
97 midy = (y[src[i]] + y[dst[i]]) / 2.
98 ang = atan2(y[dst[i]] - y[src[i]], x[dst[i]] - x[src[i]])
99 nang = ang - deg90
100 px = midx + elabdist * cos(nang)
101 py = midy + elabdist * sin(nang)
102 rot = ang * 180. / pi
103 rot = (rot < 0. ? rot + 360. : rot)
104 rot = (rot >= 90. && rot <= 270. ? rot + 180. : rot);
105 printf "newstring x %f y %f vjc hjc rotate %f font %s fontsize %d : %s\n", px, py, rot, efont, efontsize, elabel[i]
106 }
107 }
108}
109
110function label_to_node(label) {
111 for (i = 0; i < n; i++)
112 if (vlabel[i] == label)
113 return(i)
114 return(-1)
115}
116
117'
Note: See TracBrowser for help on using the repository browser.