1 .\" A macro package for drawing simple charts and curves
3 .\" The main macros are as follows:
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
12 .\" End the current graph.
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".
22 .\" Specify the next point in the current curve.
25 .\" End and draw the current curve.
28 .\" Specify x-axis label at x.
31 .\" Specify y-axis label at y.
34 .\" Specify graph colours.
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
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
53 . nr gryoff \\n(.d+\\n[grht]
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
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
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])
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[]
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
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
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
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
103 . gropt "\\$1" "\\$2" "\\$3" "\\$4" "\\$5"
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]
125 \m[\\*[grclr.ln]]\v'|\\n[grcur.ybeg]u'\h'|\\n[grcur.xbeg]u'\\*[grcur.s]\m[]
131 \v'|\\n[gryoff]u'\h'|\\n[grxoff]u'\D'p \\n[grwd]u 0 0 -\\n[grht]u -\\n[grwd]u 0'
137 . if \\n(.$>0 .if !'-'\\$1' .ds grclr.ln "\\$1
138 . if \\n(.$>1 .if !'-'\\$2' .ds grclr.fl "\\$2
141 . nr grnext \\$2+\\$4
143 . if \\n[grnext]<\\$3 .grloop \\$1 \\n[grnext] \\$3 \\$4