Use py_resource module
[python/dscho.git] / Lib / lib-stdwin / Histogram.py
blob74a75f374fb860cb73c831c08f46b42ec663508c
1 # Module 'Histogram'
3 from Buttons import *
5 # A Histogram displays a histogram of numeric data.
7 class HistogramAppearance(LabelAppearance, Define):
9 def define(self, parent):
10 Define.define(self, (parent, ''))
11 self.ydata = []
12 self.scale = (0, 100)
13 return self
15 def setdata(self, ydata, scale):
16 self.ydata = ydata
17 self.scale = scale # (min, max)
18 self.parent.change(self.bounds)
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))
36 class Histogram(NoReactivity, HistogramAppearance): pass