Article View: comp.lang.postscript
Article #6979Re: How about a Bar Chart Program?
From: Geoffrey Cooper
Date: Sat, 12 Mar 1988 02:03
Date: Sat, 12 Mar 1988 02:03
139 lines
3517 bytes
3517 bytes
In article <4732@sigi.Colorado.EDU>, adamb@boulder.Colorado.EDU (Adam 'Buzz' Beguelin) writes:
> I was thinking about writting a postscript program to print bar charts
> of data. Before I do has anyone done this? It seems like it would
> be a handy tool.
Here is one, somewhat rudimentary:
/bar
{
0 1 index rlineto
barwidth 0 rlineto
0 exch neg rlineto
closepath
gsave fill grestore
gsave 0 setgray stroke grestore
newpath
}
def
/rshow
{
dup stringwidth exch neg exch rmoveto gsave show grestore
}
def
/cshow
{
dup stringwidth pop 2 index exch sub 2 div 0 rmoveto show pop
}
def
/bargraph
{
/nitems exch def
nitems array astore /data exch def
% compute number of points total.
/numpoints data 0 get length def
data { length dup numpoints lt { /numpoints exch def } { pop } ifelse } forall
% trim arrays to have that number of points.
0 1 data length 1 sub
{
/i exch def
data i data i get 0 numpoints getinterval put
}
for
% find minimum and maximum range
/minval 0 def
/maxval 0 def
data {
{ dup minval lt { dup /minval exch def } if
dup maxval gt { dup /maxval exch def } if
pop } forall
} forall
/pointsperval graph_height maxval minval sub abs div def
/zero_offset minval 0 lt { minval neg } { 0 } ifelse def
/spacing graph_width numpoints div def
/barwidth spacing data length 4 mul sub dup 0 lt { pop 1 } if def
/bar_offset 3 def
/grayinc 1 data length div def
% print major axes
1 setlinewidth
0 0 moveto 0 graph_height lineto
0 zero_offset moveto graph_width 0 rlineto stroke
0 setgray
/Helvetica findfont 8 scalefont setfont
% print hash lines
0 graph_hlabels maxval
{
/i exch def
0 i pointsperval mul moveto
gsave
[2 4] 2.1 setdash
graph_width 0 rlineto stroke
grestore
-10 0 rmoveto
(:) rshow
i cvi =string cvs rshow
}
for
minval 0 lt
{
graph_hlabels neg dup minval
{
/i exch def
0 i pointsperval mul moveto
gsave
[2 4] 2.1 setdash
graph_width 0 rlineto stroke
grestore
-10 0 rmoveto
(:) rshow
i cvi =string cvs rshow
}
for
}
if
0 setlinewidth
/curoffset 0 def
data
{
/curdata exch def
0 1 numpoints 1 sub
{
/i exch def
i spacing mul curoffset add zero_offset moveto
curdata i get pointsperval mul bar
}
for
/curoffset curoffset bar_offset add def
currentgray grayinc add setgray
}
forall
% print horizontal labels
0 1 numpoints 1 sub
{
/i exch def
i spacing mul zero_offset 11 sub moveto
spacing i =string cvs cshow
}
for
}
def
--
{decwrl,sun,saber}!imagen!geof
Technical Details
Message-ID:
<1663@imagen.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!uunet!portal!atari!imagen!geofReferences:
<4732@sigi.Colorado.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!portal!atari!imagen!geof From: geof@imagen.UUCP (Geoffrey Cooper) Newsgroups: comp.lang.postscript Subject: Re: How about a Bar Chart Program? Message-ID: <1663@imagen.UUCP> Date: 12 Mar 88 02:03:20 GMT References: <4732@sigi.Colorado.EDU> Organization: IMAGEN Corporation, Santa Clara, CA 95052-8101 Lines: 139