summaryrefslogtreecommitdiff
path: root/dviware/psprint/unix/piechart.ps
diff options
context:
space:
mode:
Diffstat (limited to 'dviware/psprint/unix/piechart.ps')
-rw-r--r--dviware/psprint/unix/piechart.ps68
1 files changed, 68 insertions, 0 deletions
diff --git a/dviware/psprint/unix/piechart.ps b/dviware/psprint/unix/piechart.ps
new file mode 100644
index 0000000000..1d9d6137ea
--- /dev/null
+++ b/dviware/psprint/unix/piechart.ps
@@ -0,0 +1,68 @@
+% This file is inserted into the PSPRINT User Guide using \special.
+% It draws a simple pie chart (based on p.187 of the PostScript Cookbook).
+
+/DrawSlice
+{ % this routine expects 3 parameters on stack:
+ /endangle exch def
+ /startangle exch def
+ /thelabel exch def
+ newpath 0 0 moveto
+ 0 0 radius startangle endangle arc
+ closepath
+ 1.415 setmiterlimit % bevel the lines joining in the centre
+ 0.01 Inch setlinewidth
+ stroke
+ gsave
+ % calculate starting position for label
+ startangle endangle add 2 div rotate
+ radius labelps add 0 translate
+ 0 0 transform
+ grestore
+ itransform
+ /y exch def /x exch def
+ x y moveto
+ x 0 lt { thelabel stringwidth pop neg 0 rmoveto } if % move label left
+ y 0 lt { 0 labelps neg rmoveto } if % move label down
+ thelabel show
+} def
+
+/DrawPieChart
+{ % this routine expects 5 parameters on stack:
+ /radius exch def
+ /ycenter exch def
+ /xcenter exch def
+ /PieArray exch def
+ /labelps exch def
+ xcenter ycenter translate
+ /Helvetica findfont labelps scalefont setfont
+ /curangle 0 def
+ PieArray
+ { /slicearray exch def
+ slicearray aload pop
+ /percent exch def
+ /label exch def
+ /perangle percent 100 div 360 mul def
+ label curangle curangle perangle add DrawSlice
+ /curangle curangle perangle add def
+ } forall % repeat above procedure for each element in PieArray
+} def
+
+/Inch { 72 mul } def % converts inches to points
+
+% ----- MAIN PROGRAM -----
+
+8 % label point size
+[ % PieArray is an array of arrays
+ [ (Blueberry) 12 ]
+ [ (Apple) 30 ]
+ [ (Cherry) 12 ] % include any number of label, percentage pairs
+ [ (Raspberry) 16 ] % but make sure the numbers add up to 100
+ [ (Apricot) 24 ]
+ [ (Other) 6 ]
+]
+3.15 Inch 1.0 Inch % x,y center of pie chart
+ % (3.15in * 2 = 6.3in = text width in User Guide)
+.7 Inch % radius
+DrawPieChart % draw pie chart using above arguments
+
+showpage