tmac: use ds instead of de + chop
[neatroff_make.git] / tmac / tmac.gr
blobb7f5447ea5dbd92e013d592e721cdfc504c1333b
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 .\" .grclr line fill
34 .\"   Specify graph colours.
35 .\"
36 .nr grlnsz 24           \" Line point size
37 .nr grptsz 12           \" Text point size
38 .nr grbarwid 1          \" Bar width
39 .ds grclr.ln "#725      \" Line colour
40 .ds grclr.fl "#fff      \" Fill colour
41 .de grbeg
42 .       gr
43 .       nr grxmin 0
44 .       nr grxmax 0
45 .       nr grymin 0
46 .       nr grymax 0
47 .       gropt "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
48 .       nr grxwid 0\\n[grxmax]-\\n[grxmin]
49 .       nr grywid 0\\n[grymax]-\\n[grymin]
50 .       nr grwd \\n(.l-\\n(.i
51 .       nr grht \\n[grwd]*3/4
52 .       nr grxoff \\n(.i
53 .       nr gryoff \\n(.d+\\n[grht]
54 .       ne \\n[grht]u
55 .       ev grenv
56 .       nf
58 .\" map graph positions to roff position
59 .ds grx \\n[grxoff]+((\\$1-\\n[grxmin])*\\n[grwd]/\\n[grxwid])
60 .ds gry \\n[gryoff]-((\\$1-\\n[grymin])*\\n[grht]/\\n[grywid])
61 .ds grwd ((\\$1)*\\n[grwd]/\\n[grxwid])
62 .ds grht ((\\$1)*\\n[grht]/\\n[grywid])
63 .\" read graph options
64 .de gropt
65 .       if \\n(.$>=1 .if !"\\$1"" .nr gr\\$1
66 .       if \\n(.$>=2 .if !"\\$2"" .nr gr\\$2
67 .       if \\n(.$>=3 .if !"\\$3"" .nr gr\\$3
68 .       if \\n(.$>=4 .if !"\\$4"" .nr gr\\$4
69 .       if \\n(.$>=5 .if !"\\$5"" .nr gr\\$5
70 .       if \\n(.$>=6 .if !"\\$6"" .nr gr\\$6
71 .       if \\n(.$>=7 .if !"\\$7"" .nr gr\\$7
73 .de grbar
74 .       gropt "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
75 .       nr grxdiff \\*[grwd \\n[grbarwid]]
76 .       nr grx1 \\*[grx \\$1]-(\\n[grxdiff]/2)
77 .       nr gry1 \\*[gry \\n[grymin]]
78 .       nr gry2 \\*[gry \\$2]
79 .       nr grydiff (\\n[gry2]-\\n[gry1])
80 .       ps \\n[grlnsz]
81 \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[]
82 \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[]
83 .       ps
84 .       sp -2
86 .de grnum
87 .       nr grx1 \\*[grx \\$1]
88 .       nr gry1 \\*[gry \\n[grymin]]
89 \v'|\\n[gry1]u+1v'\h'|\\n[grx1]u-(\\w'\\$2'u/2u)'\\$2
90 .       sp -1
91 .       if \\n(.$>2&\\$3 \v'|\\n[gry1]u'\h'|\\n[grx1]u'\D'l 0 -\\n[grht]u'
92 .       if \\n(.$>2&\\$3 .sp -1
94 .de grval
95 .       nr grx1 \\*[grx \\n[grxmin]]
96 .       nr gry1 \\*[gry \\$1]
97 \v'|\\n[gry1]u'\h'|\\n[grx1]u-\\w'\\$2'u-1m'\\$2
98 .       sp -1
99 .       if \\n(.$>2&\\$3 \v'|\\n[gry1]u'\h'|\\n[grx1]u'\D'l \\n[grwd]u 0'
100 .       if \\n(.$>2&\\$3 .sp -1
102 .de grcurbeg
103 .       gropt "\\$1" "\\$2" "\\$3" "\\$4" "\\$5"
104 .       ds grcur.s "
105 .       nr grcur.x 0
106 .       nr grcur.y 0
107 .       nr grcur.beg 0
108 .       nr grcur.xbeg 0
109 .       nr grcur.ybeg 0
111 .de grcur
112 .       nr grx \\*[grx \\$1]
113 .       nr gry \\*[gry \\$2]
114 .       if !\\n[grcur.beg] .nr grcur.xbeg \\n[grx]
115 .       if !\\n[grcur.beg] .nr grcur.ybeg \\n[gry]
116 .       nr grxdiff \\n[grx]-\\n[grcur.x]
117 .       nr grydiff \\n[gry]-\\n[grcur.y]
118 .       if \\n[grcur.beg] .as grcur.s "\D'l \\n[grxdiff]u \\n[grydiff]u'
119 .       nr grcur.x \\n[grx]
120 .       nr grcur.y \\n[gry]
121 .       nr grcur.beg 1
123 .de grcurend
124 .       ps \\n[grlnsz]
125 \m[\\*[grclr.ln]]\v'|\\n[grcur.ybeg]u'\h'|\\n[grcur.xbeg]u'\\*[grcur.s]\m[]
126 .       ps
127 .       sp -1
129 .de grend
130 .       ps \\n[grlnsz]
131 \v'|\\n[gryoff]u'\h'|\\n[grxoff]u'\D'p \\n[grwd]u 0 0 -\\n[grht]u -\\n[grwd]u 0'
132 .       ps
133 .       sp |\\n[gryoff]u
134 .       ev
136 .de grclr
137 .       if \\n(.$>0 .if !'-'\\$1' .ds grclr.ln "\\$1
138 .       if \\n(.$>1 .if !'-'\\$2' .ds grclr.fl "\\$2
140 .de grloop
141 .       nr grnext \\$2+\\$4
142 .       \\$1 \\$2
143 .       if \\n[grnext]<\\$3 .grloop \\$1 \\n[grnext] \\$3 \\$4