blob: a023938b4d1e7de1f05c3e62767cd1b3732711df [file] [log] [blame]
Guido van Rossume1f069e1990-10-25 18:51:42 +00001# Module 'Histogram'
2
3from Buttons import *
4
5
6# A Histogram displays a histogram of numeric data.
7# It reacts to resize events by resizing itself,
8# leaving the same amount of space around the borders.
9#
10class HistogramAppearance() = LabelAppearance():
11 #
12 def define(self, (win, bounds, ydata, scale)):
13 self.init_appearance(win, bounds)
14 self.ydata = ydata
15 self.scale = scale # (min, max)
16 self.left_top, (right, bottom) = bounds
17 width, height = win.getwinsize()
18 self.right_margin = width - right
19 self.bottom_margin = height - bottom
20 return self
21 #
22 def setdata(self, (ydata, scale)):
23 self.ydata = ydata
24 self.scale = scale # (min, max)
25 self.win.change(self.bounds)
26 #
27 def drawit(self, d):
28 ydata = self.ydata
29 (left, top), (right, bottom) = self.bounds
30 min, max = self.scale
31 size = max-min
32 width, height = right-left, bottom-top
33 for i in range(len(ydata)):
34 h0 = left + i * width/len(ydata)
35 h1 = left + (i+1) * width/len(ydata)
36 v0 = top + height - (self.ydata[i]-min)*height/size
37 v1 = top + height
38 d.paint((h0, v0), (h1, v1))
39 #
40 def resize(self):
41 width, height = self.win.getwinsize()
42 right = width - self.right_margin
43 bottom = height - self.bottom_margin
44 self.setbounds(self.left_top, (right, bottom))
45 #
46
47class HistogramReactivity() = NoReactivity(): pass
48
49class Histogram() = HistogramAppearance(), HistogramReactivity(): pass