home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / BIPL.ZIP / PROCS.ZIP / GLABELS.ICN < prev    next >
Encoding:
Text File  |  1992-11-20  |  1.6 KB  |  69 lines

  1. ############################################################################
  2. #
  3. #    File:     glabels.icn
  4. #
  5. #    Subject:  Procedure to produce graph ticks
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     August 22, 1992
  10. #
  11. ###########################################################################
  12. #
  13. #  glabels(min, max, nticks) produces a list of aesthetically pleasing labels
  14. #  for graph ticks to cover a given range.  It is based on the algorithm
  15. #  given by Paul S. Heckert in "Graphic Gems", Andrew S Glassner, ed.,
  16. #  Academic Press, 1990.
  17. #
  18. ############################################################################
  19. #
  20. #  Links: real2int
  21. #
  22. ############################################################################
  23.  
  24. link real2int
  25.  
  26. procedure glabels(min, max, ntick)
  27.  
  28.    if min = max then fail        # no can do
  29.  
  30.    range := nicenum(max - min)
  31.    d := nicenum(range / (ntick - 1), 1)
  32.    graphmin := floor(min / d) * d
  33.    graphmax := ceil(max / d) * d
  34.    nfrac := max(-floor(log(d, 10)), 0)
  35.    llist := []
  36.    every x := graphmin to graphmax + 0.5 * d by d do
  37.      put(llist, x)
  38.  
  39.    return llist
  40.  
  41. end
  42.  
  43. procedure nicenum(x, round)
  44.  
  45.    exp := floor(log(x, 10))
  46.    f := x / (10 ^ exp)
  47.    if \round then {
  48.       if f < 1.5 then nf := 1
  49.       else if f < 3.0 then nf := 2
  50.       else if f < 7 then nf := 5
  51.       else nf := 10
  52.       }
  53.    else {
  54.       if f <= 1 then nf := 1
  55.       else if f <= 2 then nf := 2
  56.       else if f <= 5 then nf := 5
  57.       else nf := 10
  58.       }
  59.  
  60.    return nf * (10 ^ exp)
  61.  
  62. end
  63.  
  64. procedure max(i, j)
  65.  
  66.    if i > j then return i else return j
  67.  
  68. end
  69.