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
57
58
59
60
61
62
63
64
65
66
67
68
|
############################################################################
#
# File: glabels.icn
#
# Subject: Procedure to produce graph ticks
#
# Author: Ralph E. Griswold
#
# Date: May 2, 2001
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# glabels(min, max, nticks) produces a list of aesthetically pleasing labels
# for graph ticks to cover a given range. It is based on the algorithm
# given by Paul S. Heckert in "Graphic Gems", Andrew S Glassner, ed.,
# Academic Press, 1990.
#
############################################################################
#
# Links: numbers
#
############################################################################
link numbers
procedure glabels(min, max, ntick)
local d, graphmin, graphmax, nfrac, llist, x, nf, range
if min = max then fail # no can do
range := nicenum(max - min)
d := nicenum(range / (ntick - 1), 1)
graphmin := floor(min / d) * d
graphmax := ceil(max / d) * d
nfrac := max(-floor(log(d, 10)), 0)
llist := []
every x := graphmin to graphmax + 0.5 * d by d do
put(llist, x)
return llist
end
procedure nicenum(x, round)
local exp, f, nf
exp := floor(log(x, 10))
f := x / (10 ^ exp)
if \round then {
if f < 1.5 then nf := 1
else if f < 3.0 then nf := 2
else if f < 7 then nf := 5
else nf := 10
}
else {
if f <= 1 then nf := 1
else if f <= 2 then nf := 2
else if f <= 5 then nf := 5
else nf := 10
}
return nf * (10 ^ exp)
end
|