/
ch-2.ps
56 lines (49 loc) · 1 KB
/
ch-2.ps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
%!PS
% begin included library code
% see https://github.com/Firedrake/postscript-libraries/
/reduce { % array proc -> value
2 dict begin
/p exch def
/a exch def
a 0 get
1 1 a length 1 sub {
a exch get
p
} for
end
} bind def
/listmax {
{ max } reduce
} bind def
/listmin {
{ min } reduce
} bind def
% end included library code
/sparkline {
9 dict begin
/nn exch def
/bar 8 array def
0 1 7 {
/i exch def
/cc 3 string def
cc 0 16#e2 put
cc 1 16#96 put
cc 2 16#81 i add put
bar i cc put
} for
/mn nn listmin def
/mx nn listmax def
/inscale mx mn sub def
/outscale bar length def
/out nn length 3 mul string def
0 1 nn length 1 sub {
/i exch def
out i 3 mul
bar nn i get mn sub inscale div outscale mul cvi outscale 1 sub min get
putinterval
} for
out
end
} bind def
[ 0 10 ] sparkline print () =
[ 1 2 3 4 5 6 7 8 ] sparkline print () =