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 .nr grratio 133 \" Aspect ratio (width / height * 100)
40 .ds grclr.ln "#725 \" Line colour
41 .ds grclr.fl "#fff \" Fill colour
48 . gropt "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
49 . nr grxwid 0\\n[grxmax]-\\n[grxmin]
50 . nr grywid 0\\n[grymax]-\\n[grymin]
51 . nr grwd \\n(.l-\\n(.i
52 . nr grht \\n[grwd]*100/\\n[grratio]
54 . nr gryoff \\n(.d+\\n[grht]
59 .\" map graph positions to roff position
60 .ds grx \\n[grxoff]+((\\$1-\\n[grxmin])*\\n[grwd]/\\n[grxwid])
61 .ds gry \\n[gryoff]-((\\$1-\\n[grymin])*\\n[grht]/\\n[grywid])
62 .ds grwd ((\\$1)*\\n[grwd]/\\n[grxwid])
63 .ds grht ((\\$1)*\\n[grht]/\\n[grywid])
64 .\" read graph options
66 . if \\n(.$>=1 .if !"\\$1"" .nr gr\\$1
67 . if \\n(.$>=2 .if !"\\$2"" .nr gr\\$2
68 . if \\n(.$>=3 .if !"\\$3"" .nr gr\\$3
69 . if \\n(.$>=4 .if !"\\$4"" .nr gr\\$4
70 . if \\n(.$>=5 .if !"\\$5"" .nr gr\\$5
71 . if \\n(.$>=6 .if !"\\$6"" .nr gr\\$6
72 . if \\n(.$>=7 .if !"\\$7"" .nr gr\\$7
75 . gropt "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
76 . nr grxdiff \\*[grwd \\n[grbarwid]]
77 . nr grx1 \\*[grx \\$1]-(\\n[grxdiff]/2)
78 . nr gry1 \\*[gry \\n[grymin]]
79 . nr gry2 \\*[gry \\$2]
80 . nr grydiff (\\n[gry2]-\\n[gry1])
82 \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[]
83 \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[]
88 . nr grx1 \\*[grx \\$1]
89 . nr gry1 \\*[gry \\n[grymin]]
90 \v'|\\n[gry1]u+1v'\h'|\\n[grx1]u-(\\w'\\$2'u/2u)'\\$2
92 . if \\n(.$>2&\\$3 \v'|\\n[gry1]u'\h'|\\n[grx1]u'\D'l 0 -\\n[grht]u'
93 . if \\n(.$>2&\\$3 .sp -1
96 . nr grx1 \\*[grx \\n[grxmin]]
97 . nr gry1 \\*[gry \\$1]
98 \v'|\\n[gry1]u'\h'|\\n[grx1]u-\\w'\\$2'u-1m'\\$2
100 . if \\n(.$>2&\\$3 \v'|\\n[gry1]u'\h'|\\n[grx1]u'\D'l \\n[grwd]u 0'
101 . if \\n(.$>2&\\$3 .sp -1
104 . gropt "\\$1" "\\$2" "\\$3" "\\$4" "\\$5"
113 . nr grx \\*[grx \\$1]
114 . nr gry \\*[gry \\$2]
115 . if !\\n[grcur.beg] .nr grcur.xbeg \\n[grx]
116 . if !\\n[grcur.beg] .nr grcur.ybeg \\n[gry]
117 . nr grxdiff \\n[grx]-\\n[grcur.x]
118 . nr grydiff \\n[gry]-\\n[grcur.y]
119 . if \\n[grcur.beg] .as grcur.s "\D'l \\n[grxdiff]u \\n[grydiff]u'
120 . nr grcur.x \\n[grx]
121 . nr grcur.y \\n[gry]
126 \m[\\*[grclr.ln]]\v'|\\n[grcur.ybeg]u'\h'|\\n[grcur.xbeg]u'\\*[grcur.s]\m[]
132 \v'|\\n[gryoff]u'\h'|\\n[grxoff]u'\D'p \\n[grwd]u 0 0 -\\n[grht]u -\\n[grwd]u 0'
138 . if \\n(.$>0 .if !'-'\\$1' .ds grclr.ln "\\$1
139 . if \\n(.$>1 .if !'-'\\$2' .ds grclr.fl "\\$2
142 . nr grnext \\$2+\\$4
144 . if \\n[grnext]<\\$3 .grloop \\$1 \\n[grnext] \\$3 \\$4