tmac.tbl: invoke tblmac macros after adjusting in and ll
[neatroff_make.git] / tmac / tmac.gr
blob56bde3b075d85b28f0b2bb87c053c7d129473038
1 .\" A macro package for drawing simple charts and curves
2 .\"
3 .\" The main macros are as follows:
4 .\"
5 .\" .grbeg "xmin x1" "xmax x2" "ymin y1" "ymax y2" [opts]
6 .\"   Begin a graph; the arguments specify the minimum and maximum
7 .\"   x and y values.  The value of other variables may be specified
8 .\"   similarly.  For instance, adding "barwid 2" sets the width of
9 .\"   bars.
10 .\"
11 .\" .grend
12 .\"   End the current graph.
13 .\"
14 .\" .grbar pos height [opts]
15 .\"   Draw a bar at x=pos with the given height.  The width of
16 .\"   the bar can be specified as "barwid N".
17 .\"
18 .\" .grcurbeg [opts]
19 .\"   Begin a curve.
20 .\"
21 .\" .grcur x y
22 .\"   Specify the next point in the current curve.
23 .\"
24 .\" .grcurend
25 .\"   End and draw the current curve.
26 .\"
27 .\" .grnum x label
28 .\"   Specify x-axis label at x.
29 .\"
30 .\" .grval y label
31 .\"   Specify y-axis label at y.
32 .\"
33 .\" .grtxt x y "text"
34 .\"   Write "text" in the given position.
35 .\"
36 .\" .grclr line fill
37 .\"   Specify graph colours.
38 .\"
39 .\" .grlab.x "label" [pos]
40 .\"   Specify x-axis label.
41 .\"
42 .\" .grlab.y "label" [pos]
43 .\"   Specify y-axis label.
44 .\"
45 .nr grlnsz 24           \" Line point size
46 .nr grptsz 12           \" Text point size
47 .nr grbarwid 1          \" Bar width
48 .nr grratio 133         \" Aspect ratio (width / height * 100)
49 .ds grclr.ln "#725      \" Line colour
50 .ds grclr.fl "#fff      \" Fill colour
51 .de grbeg
52 .       br
53 .       nr grxmin 0
54 .       nr grxmax 0
55 .       nr grymin 0
56 .       nr grymax 0
57 .       gropt "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
58 .       nr grxwid 0\\n[grxmax]-\\n[grxmin]
59 .       nr grywid 0\\n[grymax]-\\n[grymin]
60 .       nr grwd \\n(.l-\\n(.i
61 .       nr grht \\n[grwd]*100/\\n[grratio]
62 .       nr grxoff \\n(.i
63 .       nr gryoff \\n(.d+\\n[grht]
64 .       ne \\n[grht]u
65 .       ev grenv
66 .       nf
68 .\" map graph positions to roff position
69 .ds grx \\n[grxoff]+((\\$1-\\n[grxmin])*\\n[grwd]/\\n[grxwid])
70 .ds gry \\n[gryoff]-((\\$1-\\n[grymin])*\\n[grht]/\\n[grywid])
71 .ds grwd ((\\$1)*\\n[grwd]/\\n[grxwid])
72 .ds grht ((\\$1)*\\n[grht]/\\n[grywid])
73 .\" read graph options
74 .de gropt
75 .       if \\n(.$>=1 .if !"\\$1"" .nr gr\\$1
76 .       if \\n(.$>=2 .if !"\\$2"" .nr gr\\$2
77 .       if \\n(.$>=3 .if !"\\$3"" .nr gr\\$3
78 .       if \\n(.$>=4 .if !"\\$4"" .nr gr\\$4
79 .       if \\n(.$>=5 .if !"\\$5"" .nr gr\\$5
80 .       if \\n(.$>=6 .if !"\\$6"" .nr gr\\$6
81 .       if \\n(.$>=7 .if !"\\$7"" .nr gr\\$7
83 .de grbar
84 .       gropt "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
85 .       nr grxdiff \\*[grwd \\n[grbarwid]]
86 .       nr grx1 \\*[grx \\$1]-(\\n[grxdiff]/2)
87 .       nr gry1 \\*[gry \\n[grymin]]
88 .       nr gry2 \\*[gry \\$2]
89 .       nr grydiff (\\n[gry2]-\\n[gry1])
90 .       ps \\n[grlnsz]
91 \m[\\*[grclr.fl]]\v'|\\n[gry1]u'\h'|\\n[grx1]u'\D'P \\n[grxdiff]u 0u 0u \\n[grydiff]u -\\n[grxdiff]u 0u'\m[]
92 \m[\\*[grclr.ln]]\v'|\\n[gry1]u'\h'|\\n[grx1]u'\D'p \\n[grxdiff]u 0u 0u \\n[grydiff]u -\\n[grxdiff]u 0u'\m[]
93 .       ps
94 .       sp -2
96 .de grnum
97 .       nr grx1 \\*[grx \\$1]
98 .       nr gry1 \\*[gry \\n[grymin]]
99 .       ps \\n[grptsz]
100 \v'|\\n[gry1]u+1v'\h'|\\n[grx1]u-(\\w'\\$2'u/2u)'\\$2
101 .       ps
102 .       sp -1
103 .       if \\n(.$>2&\\$3 \v'|\\n[gry1]u'\h'|\\n[grx1]u'\D'l 0 -\\n[grht]u'
104 .       if \\n(.$>2&\\$3 .sp -1
106 .de grval
107 .       nr grx1 \\*[grx \\n[grxmin]]
108 .       nr gry1 \\*[gry \\$1]
109 .       ps \\n[grptsz]
110 \v'|\\n[gry1]u'\h'|\\n[grx1]u-\\w'\\$2'u-1m'\\$2
111 .       ps
112 .       sp -1
113 .       if \\n(.$>2&\\$3 \v'|\\n[gry1]u'\h'|\\n[grx1]u'\D'l \\n[grwd]u 0'
114 .       if \\n(.$>2&\\$3 .sp -1
116 .de grlab.x
117 .       ps \\n[grptsz]
118 \v'|\\n[gryoff]u+2v\\$2'\h'|\\n[grxoff]u+(\\n[grwd]u/2u)-(\\w'\\$1'u/2u)'\\$1
119 .       ps
120 .       sp -1
122 .de grlab.y
123 .       ps \\n[grptsz]
124 \v'|\\n[gryoff]u-(\\n[grht]u/2u)'\h'|\\n[grxoff]u-2v\\$2'\
125 \X'rotate 90'\h'-(\\w'\\$1'u/2u)'\\$1\X'rotate 0'
126 .       ps
127 .       sp -1
129 .de grtxt
130 .       nr grx1 \\*[grx \\$1]
131 .       nr gry1 \\*[gry \\$2]
132 .       ps \\n[grptsz]
133 \v'|\\n[gry1]u'\h'|\\n[grx1]u'\h'-(\\w'\\$3'u/2u)'\\$3
134 .       ps
135 .       sp -1
137 .de grcurbeg
138 .       gropt "\\$1" "\\$2" "\\$3" "\\$4" "\\$5"
139 .       ds grcur.s "
140 .       nr grcur.x 0
141 .       nr grcur.y 0
142 .       nr grcur.beg 0
143 .       nr grcur.xbeg 0
144 .       nr grcur.ybeg 0
146 .de grcur
147 .       nr grx \\*[grx \\$1]
148 .       nr gry \\*[gry \\$2]
149 .       if !\\n[grcur.beg] .nr grcur.xbeg \\n[grx]
150 .       if !\\n[grcur.beg] .nr grcur.ybeg \\n[gry]
151 .       nr grxdiff \\n[grx]-\\n[grcur.x]
152 .       nr grydiff \\n[gry]-\\n[grcur.y]
153 .       if \\n[grcur.beg] .as grcur.s "\D'l \\n[grxdiff]u \\n[grydiff]u'
154 .       nr grcur.x \\n[grx]
155 .       nr grcur.y \\n[gry]
156 .       nr grcur.beg 1
158 .de grcurend
159 .       ps \\n[grlnsz]
160 \m[\\*[grclr.ln]]\v'|\\n[grcur.ybeg]u'\h'|\\n[grcur.xbeg]u'\\*[grcur.s]\m[]
161 .       ps
162 .       sp -1
164 .de grend
165 .       ps \\n[grlnsz]
166 \v'|\\n[gryoff]u'\h'|\\n[grxoff]u'\D'p \\n[grwd]u 0 0 -\\n[grht]u -\\n[grwd]u 0'
167 .       ps
168 .       sp |\\n[gryoff]u
169 .       ev
171 .de grclr
172 .       if \\n(.$>0 .if !'-'\\$1' .ds grclr.ln "\\$1
173 .       if \\n(.$>1 .if !'-'\\$2' .ds grclr.fl "\\$2
175 .de grloop
176 .       nr grnext \\$2+\\$4
177 .       \\$1 \\$2
178 .       if \\n[grnext]<\\$3 .grloop \\$1 \\n[grnext] \\$3 \\$4