home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyth_os2.zip / python-1.0.2 / Lib / stdwin / Histogram.py < prev    next >
Text File  |  1992-12-14  |  876b  |  37 lines

  1. # Module 'Histogram'
  2.  
  3. from Buttons import *
  4.  
  5. # A Histogram displays a histogram of numeric data.
  6. #
  7. class HistogramAppearance(LabelAppearance, Define):
  8.     #
  9.     def define(self, parent):
  10.         Define.define(self, (parent, ''))
  11.         self.ydata = []
  12.         self.scale = (0, 100)
  13.         return self
  14.     #
  15.     def setdata(self, ydata, scale):
  16.         self.ydata = ydata
  17.         self.scale = scale # (min, max)
  18.         self.parent.change(self.bounds)
  19.     #
  20.     def drawpict(self, d):
  21.         (left, top), (right, bottom) = self.bounds
  22.         min, max = self.scale
  23.         size = max-min
  24.         width, height = right-left, bottom-top
  25.         ydata = self.ydata
  26.         npoints = len(ydata)
  27.         v1 = top + height    # constant
  28.         h1 = left        # changed in loop
  29.         for i in range(npoints):
  30.             h0 = h1
  31.             v0 = top + height - (ydata[i]-min)*height/size
  32.             h1 = left + (i+1) * width/npoints
  33.             d.paint((h0, v0), (h1, v1))
  34.     #
  35.  
  36. class Histogram(NoReactivity, HistogramAppearance): pass
  37.