aboutsummaryrefslogtreecommitdiffstats
path: root/grapheps.ps
diff options
context:
space:
mode:
Diffstat (limited to 'grapheps.ps')
-rwxr-xr-x[-rw-r--r--]grapheps.ps186
1 files changed, 147 insertions, 39 deletions
diff --git a/grapheps.ps b/grapheps.ps
index 4d41fd9..1f59e65 100644..100755
--- a/grapheps.ps
+++ b/grapheps.ps
@@ -1,7 +1,27 @@
+% "graph-eps" library for creating PostScript graphs
+% http://people.csail.mit.edu/jaffer/Docupage/grapheps
+% Copyright (C) 1991, 2001, 2005, 2006, 2009, 2010, 2011 Aubrey Jaffer
+%
+% Permission to copy this software, to modify it, to redistribute it,
+% to distribute modified versions, and to use it for any purpose is
+% granted, subject to the following restrictions and understandings.
+%
+% 1. Any copy made of this software must include this copyright notice
+% in full.
+%
+% 2. I have made no warranty or representation that the operation of
+% this software will be error-free, and I am under no obligation to
+% provide any services, by way of maintenance, update, or otherwise.
+%
+% 3. In conjunction with products arising from the use of this
+% material, there shall be no use of my name in any advertising,
+% promotional, or sales literature without prior written consent in
+% each case.
+
/plotdict 100 dict def
plotdict begin
-% Get dimensions the preamble left on the stack.
+% Get dimensions
4 array astore /whole-page exch def
% Definitions so that internal assignments are bound before setting.
@@ -50,9 +70,48 @@ plotdict begin
/STP3 0 def
/STP2 0 def
/SCL 0 def
+/Y0 0 def
+/NAME-ENCODING 0 def
+/ENCODING 0 def
+/NAME 0 def
/graphrect 0 def
/plotrect 0 def
+% ( TITLE ) ( SUBTITLE )
+/title-top
+{ dup stringwidth pop -2 div plotrect 0 get plotrect 2 get 2 div add add
+ plotrect 1 get plotrect 3 get add pointsize .4 mul add moveto show
+ dup stringwidth pop -2 div plotrect 0 get plotrect 2 get 2 div add add
+ plotrect 1 get plotrect 3 get add pointsize 1.4 mul add moveto show
+} bind def
+
+% ( TITLE ) ( SUBTITLE )
+/title-bottom
+{ dup stringwidth pop -2 div plotrect 0 get plotrect 2 get 2 div add add
+ plotrect 1 get pointsize -2 mul add moveto show
+ dup stringwidth pop -2 div plotrect 0 get plotrect 2 get 2 div add add
+ plotrect 1 get pointsize -1 mul add moveto show
+} bind def
+
+% Plots column K against column J of given two-dimensional ARRAY.
+% The arguments are:
+% [ ARRAY J K ] J and K are column-indexes into ARRAY
+% [ PREAMBLE RENDER POSTAMBLE ] Plotting procedures:
+% PREAMBLE - Executed once before plotting row
+% RENDER - Called with each pair of coordinates to plot
+% POSTAMBLE - Called once after plotting row (often does stroke)
+/plot-column
+{ /GPROCS exch def aload pop /YDX exch def /XDX exch def /DATA exch def
+ /GD glyphsize def
+ /GR GD .5 mul def
+ gsave
+ /ROW DATA 0 get def ROW XDX get ROW YDX get gtrans moveto
+ GPROCS 0 get exec % preamble
+ /PROC GPROCS 1 get def DATA {dup XDX get exch YDX get gtrans PROC} forall
+ GPROCS 2 get exec stroke % postamble
+ grestore
+} bind def
+
% Here are the procedure-arrays for passing as the third argument to
% plot-column. Plot-column moves to the first coordinate before
% calls to the first procedure. Thus both line and scatter graphs are
@@ -73,11 +132,17 @@ plotdict begin
{lineto}
{currentpoint pop topedge lineto closepath fill}] bind def
% Render lines from x-axis to points
-/impulse [{} {moveto XRNG 0 get 0 gtrans exch pop
- currentpoint pop exch lineto} {}] bind def
-/bargraph [{} {exch GR sub exch dup
- XRNG 0 get 0 gtrans exch pop % y=0
- exch sub GD exch rectstroke} {}] bind def
+/impulse [{} {2 copy moveto pop Y0 lineto} {}] bind def
+/bargraph
+ [{}
+ {2 copy pop GR sub Y0
+ 4 2 roll Y0 sub exch pop GD exch rectstroke}
+ {}] bind def
+/barfill
+ [{}
+ {2 copy pop GR sub Y0
+ 4 2 roll Y0 sub exch pop GD exch rectfill}
+ {}] bind def
% Solid round dot.
/disc [{GD setlinewidth 1 setlinecap}
@@ -121,41 +186,66 @@ plotdict begin
{}] bind def
/circle [{stroke} {GR 0 360 arc stroke} {}] bind def
-% ( TITLE ) ( SUBTITLE )
-/title-top
-{ dup stringwidth pop -2 div plotrect 0 get plotrect 2 get 2 div add add
- plotrect 1 get plotrect 3 get add pointsize .4 mul add moveto show
- dup stringwidth pop -2 div plotrect 0 get plotrect 2 get 2 div add add
- plotrect 1 get plotrect 3 get add pointsize 1.4 mul add moveto show
-} bind def
-
-% ( TITLE ) ( SUBTITLE )
-/title-bottom
-{ dup stringwidth pop -2 div plotrect 0 get plotrect 2 get 2 div add add
- plotrect 1 get pointsize -2 mul add moveto show
- dup stringwidth pop -2 div plotrect 0 get plotrect 2 get 2 div add add
- plotrect 1 get pointsize -1 mul add moveto show
-} bind def
-
-% Plots column K against column J of given two-dimensional ARRAY.
+% Puts text in column-L at column-K vs column-J
% The arguments are:
-% [ ARRAY J K ] J and K are column-indexes into ARRAY
+% [ ARRAY J K L ] J, K, and L are column-indexes into ARRAY
% [ PREAMBLE RENDER POSTAMBLE ] Plotting procedures:
% PREAMBLE - Executed once before plotting row
-% RENDER - Called with each pair of coordinates to plot
+% RENDER - Called with each pair of coordinates and text
% POSTAMBLE - Called once after plotting row (often does stroke)
-/plot-column
-{ /GPROCS exch def aload pop /YDX exch def /XDX exch def /DATA exch def
+/plot-text-column
+{ /GPROCS exch def aload pop
+ /TDX exch def /YDX exch def /XDX exch def /DATA exch def
/GD glyphsize def
/GR GD .5 mul def
gsave
/ROW DATA 0 get def ROW XDX get ROW YDX get gtrans moveto
GPROCS 0 get exec % preamble
- /PROC GPROCS 1 get def DATA {dup XDX get exch YDX get gtrans PROC} forall
+ /PROC GPROCS 1 get def
+ DATA
+ {/row exch def row XDX get row YDX get gtrans row TDX get PROC} forall
GPROCS 2 get exec stroke % postamble
grestore
} bind def
+% Here are the procedure-arrays for passing as the third argument to
+% plot-text-column. Plot-text-column moves to the first coordinate
+% before calls to the first procedure.
+
+% GD and GR are the graphic-glyph diameter and radius.
+% DIAG and DIAG2, used in /cross are diagonal and twice diagonal.
+% gtrans maps x, y coordinates on the stack to 72dpi page coordinates.
+
+/above [{}
+ {/TXT exch def
+ exch TXT stringwidth pop -2 div add exch pointsize 0.1 mul GR add add moveto
+ TXT show}
+ {}] bind def
+
+/center [{}
+ {/TXT exch def
+ exch TXT stringwidth pop -2 div add exch pointsize -0.35 mul add moveto
+ TXT show}
+ {}] bind def
+
+/below [{}
+ {/TXT exch def
+ exch TXT stringwidth pop -2 div add exch pointsize 0.7 mul GR add sub moveto
+ TXT show}
+ {}] bind def
+
+/left [{}
+ {/TXT exch def
+ exch TXT stringwidth pop GR add sub exch pointsize -0.35 mul add moveto
+ TXT show}
+ {}] bind def
+
+/right [{}
+ {/TXT exch def
+ exch GR add exch pointsize -0.35 mul add moveto
+ TXT show}
+ {}] bind def
+
/partition-page
{ /YPARTS exch def /XPARTS exch def /WPAGE exch def
/XWID WPAGE 2 get XPARTS div def /YHIT WPAGE 3 get YPARTS div def
@@ -168,6 +258,11 @@ plotdict begin
} repeat
} bind def
+/squelch-.0 % x
+{
+ dup dup cvi eq {cvi} if
+} bind def
+
/fudge3 % SCL STP3 STP2
{
/STP2 exch def /STP3 exch def /SCL exch def
@@ -191,17 +286,18 @@ plotdict begin
graphrect 1 get PLOT-bmargin add
graphrect 2 get PLOT-lmargin sub PLOT-rmargin sub
graphrect 3 get PLOT-bmargin sub PLOT-tmargin sub ] def
- /XOFF XRNG 0 get def /YOFF YRNG 0 get def
/XSCL plotrect 2 get XRNG aload pop exch sub div def
/YSCL plotrect 3 get YRNG aload pop exch sub div def
- /XOFF XOFF plotrect 0 get XSCL div sub def
- /YOFF YOFF plotrect 1 get YSCL div sub def
+ /XOFF XRNG 0 get plotrect 0 get XSCL div sub def
+ /YOFF YRNG 0 get plotrect 1 get YSCL div sub def
/YTSCL plotrect 3 get YRNG aload pop exch sub abs find-tick-scale def
- /YSTEP YTSCL 0 get 6 8 fudge3 5 mul yuntrans YSCL sign mul def
+ /YSTEP YTSCL 0 get 6 8 fudge3 5 mul yunttrans YSCL sign mul def
/XTSCL plotrect 2 get XRNG aload pop exch sub abs find-tick-scale def
- /XSTEP XTSCL 0 get 12 10 fudge3 5 mul xuntrans XSCL sign mul def
+ /XSTEP XTSCL 0 get 12 10 fudge3 5 mul xunttrans XSCL sign mul def
/YSTEPH YSTEP 2 div def
/XSTEPH XSTEP 2 div def
+% /Y0 0 YOFF sub YSCL mul def
+ /Y0 YRNG 0 get YOFF sub YSCL mul def
} bind def
% gtrans is the utility routine mapping data coordinates to view space.
@@ -209,10 +305,8 @@ plotdict begin
/gtrans {exch XOFF sub XSCL mul exch YOFF sub YSCL mul} bind def
%/guntrans {exch XSCL div XOFF add exch YSCL div YOFF add} bind def
-% /ytrans {YTSCL aload pop div mul} bind def
-% /xtrans {XTSCL aload pop div mul} bind def
-/yuntrans {YTSCL aload pop exch div mul} bind def
-/xuntrans {XTSCL aload pop exch div mul} bind def
+/yunttrans {YTSCL aload pop exch div mul} bind def
+/xunttrans {XTSCL aload pop exch div mul} bind def
/sign {dup 0 lt {pop -1} {0 gt {1} {0} ifelse} ifelse} bind def
@@ -290,7 +384,7 @@ bind def
YRNG 0 get YSTEP div ceiling YSTEP mul YSTEP YRNG 1 get
{ /YDX exch def 0 YDX gtrans /Y-COORD exch def pop
X-COORD Y-COORD moveto XWID 0 rlineto stroke
- /TXT YDX 20 string cvs def
+ /TXT YDX squelch-.0 20 string cvs def
X-COORD
XWID 0 gt {TXT stringwidth pop sub ( ) stringwidth pop sub
Y-COORD pointsize .3 mul sub moveto}
@@ -312,7 +406,7 @@ bind def
XRNG 0 get XSTEP div ceiling XSTEP mul XSTEP XRNG 1 get
{ dup 0 gtrans pop /X-COORD exch def
X-COORD Y-COORD moveto 0 YHIT rlineto stroke
- /TXT exch 10 string cvs def
+ /TXT exch squelch-.0 10 string cvs def
X-COORD TXT stringwidth pop 2.0 div sub
Y-COORD YHIT 0 gt {pointsize sub} {pointsize .3 mul add} ifelse
moveto TXT show
@@ -348,6 +442,19 @@ bind def
/gpush {gsave /gstack [ gstack pointsize glyphsize ] def} bind def
/gpop {/gstack gstack aload pop /glyphsize exch def /pointsize exch def def grestore} bind def
+/combine-font-encoding % NAME ENCODING NAME-ENCODING
+{
+ /NAME-ENCODING exch def
+ /ENCODING exch def
+ findfont
+ dup length dict begin
+ {1 index /FID ne {def} {pop pop} ifelse} forall
+ /Encoding ENCODING def
+ currentdict
+ end
+ NAME-ENCODING exch definefont pop
+} bind def
+
% Default parameters
% The legend-templates are strings used to reserve horizontal space
@@ -364,4 +471,5 @@ bind def
/Helvetica pointsize selectfont
gsave
+% End of "graph-eps"