aboutsummaryrefslogtreecommitdiffstats
path: root/grapheps.scm
diff options
context:
space:
mode:
Diffstat (limited to 'grapheps.scm')
-rwxr-xr-x[-rw-r--r--]grapheps.scm94
1 files changed, 81 insertions, 13 deletions
diff --git a/grapheps.scm b/grapheps.scm
index 857829c..7f7a465 100644..100755
--- a/grapheps.scm
+++ b/grapheps.scm
@@ -1,5 +1,5 @@
;;;; "grapheps.scm", Create PostScript Graphs
-;;; Copyright (C) 2003 Aubrey Jaffer
+;;; Copyright (C) 2003, 2004, 2005, 2006, 2008, 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
@@ -30,7 +30,7 @@
;;@noindent
;;This is a graphing package creating encapsulated-PostScript files.
;;Its motivations and design choice are described in
-;;@url{http://swiss.csail.mit.edu/~jaffer/Docupage/grapheps}
+;;@url{http://people.csail.mit.edu/jaffer/Docupage/grapheps}
;;
;;@noindent
;;A dataset to be plotted is taken from a 2-dimensional array.
@@ -53,6 +53,22 @@
(else arg)))
args)))
+(define (data->ps . args)
+ (apply string-append
+ (map (lambda (arg)
+ (cond ((number? arg) (number->string arg))
+ ((symbol? arg) (string-append "/" (symbol->string arg)))
+ ((string? arg) (string-append "(" arg ")"))
+ ((or (vector? arg) (list? arg))
+ (string-append
+ "[ "
+ (apply string-append
+ (map (lambda (x) (data->ps x " "))
+ (if (vector? arg) (vector->list arg) arg)))
+ "]"))
+ (else arg)))
+ args)))
+
;;; Capture for %%Title
(define *plot-title* #f)
@@ -120,7 +136,8 @@
(cond ((zero? idx)
(write-line "]" oprt)
(display " [" oprt)))
- (display (scheme->ps " " elt) oprt)
+ (display " " oprt)
+ (display (data->ps elt) oprt)
(set! idx (modulo (+ 1 idx) row-length)))
array)
(write-line "]" oprt)
@@ -258,6 +275,35 @@
;;Hollow circle
;;@end table
+;;@body
+;;Plots text in @4 of @1 at x coordinate in @2 of @1 and y coordinate
+;;@3 of @1. The symbol @5 specifies the offset of the text from the
+;;specified coordinates.
+(define (plot-text-column array x-column y-column t-column proc3s)
+ (set! array (import-array array))
+ (scheme->ps "[ " array " " x-column " " y-column " " t-column " ] " proc3s
+ " plot-text-column"))
+
+;;@noindent
+;;The offsets available are:
+;;
+;;@table @code
+;;@item above
+;;Draws the text centered above at the point.
+;;@item center
+;;Draws the text centered at the point.
+;;@item below
+;;Draws the text centered below the point.
+;;@item left
+;;Draws the text to the left of the point.
+;;@item right
+;;Draws the text to the right of the point.
+;;@end table
+;;
+;;All the offsets other than @code{center} are calculated to keep the
+;;text clear of a glyph drawn at the same coordinates. If you need
+;;more or less clearance, use @code{set-glyphsize}.
+
;;@node Graphics Context, Rectangles, Drawing the Graph, PostScript Graphing
;;@subsubsection Graphics Context
@@ -294,14 +340,28 @@
(append (map num->str (color->sRGB clr)) '(setrgbcolor))))
(else "")))
-;;@body
+;;@args font height
+;;@args font encoding height
;;@1 should be a (case-sensitive) string naming a PostScript font.
-;;@2 should be a positive real number.
+;;@var{height} should be a positive real number.
+;;@var{encoding} should name a PostScript encoding such as
+;;@samp{ISOLatin1Encoding}.
;;
-;;@0 Changes the current PostScript font to @1 with height equal to
-;;@2. The default font is Helvetica (12pt).
-(define (set-font name fontheight)
- (scheme->ps "/fontsize " fontheight " def /" name " fontsize selectfont"))
+;;@0 Changes the current PostScript font to @1 with the @var{encoding}
+;;encoding, and height equal to @var{height}. The default font is
+;;@samp{Helvetica} (12pt). The default encoding is
+;;@samp{StandardEncoding}.
+(define (set-font name arg2 . args)
+ (define fontheight (if (null? args) arg2 (car args)))
+ (define encoding (and (not (null? args)) arg2))
+ (scheme->ps
+ (if (null? args)
+ ""
+ (string-append " /" name " " encoding " /" name "-" encoding
+ " combine-font-encoding"))
+ " /fontsize " fontheight " def /"
+ (if encoding (string-append name "-" encoding) name)
+ " fontsize selectfont"))
;;@noindent
;;The base set of PostScript fonts is:
@@ -314,6 +374,14 @@
;;@end multitable
;;@noindent
+;;The base set of PostScript encodings is:
+;;
+;;@multitable @columnfractions .33 .33 .33
+;;@item StandardEncoding @tab ISOLatin1Encoding @tab ExpertEncoding
+;;@item ExpertSubsetEncoding @tab SymbolEncoding
+;;@end multitable
+
+;;@noindent
;;Line parameters do no affect fonts; they do effect glyphs.
;;@body
@@ -527,12 +595,12 @@
;;over the range @2 to @3. If the optional integer argument @4 is
;;supplied, it specifies the number of points to evaluate @1 at.
;;
-;;@defunx x1 x2 npts func1 func2 ...
+;;@args x1 x2 npts func1 func2 ...
;;Creates and displays an encapsulated PostScript graph of the
;;one-argument functions @var{func1}, @var{func2}, ... over the range
;;@var{x1} to @var{x2} at @var{npts} points.
;;
-;;@defunx plot coords x-label y-label
+;;@args coords x-label y-label
;;@var{coords} is a list or vector of coordinates, lists of x and y
;;coordinates. @var{x-label} and @var{y-label} are strings with which
;;to label the x and y axes.
@@ -540,11 +608,11 @@
(call-with-tmpnam
(lambda (tmp)
(cond ((procedure? (car args))
- (apply graph:plot-function tmp args))
+ (apply graph:plot-function (cons tmp args)))
((or (array? (car args))
(and (pair? (car args))
(pair? (caar args))))
- (apply graph:plot tmp args))
+ (apply graph:plot (cons tmp args)))
(else (let ((dats (apply functions->array args)))
(graph:plot tmp dats "" ""))))
(system (string-append "gv '" tmp "'")))