blob: f4692725f067320055bf58df64d786346eee72c9 [file] [log] [blame]
Guido van Rossume1f069e1990-10-25 18:51:42 +00001# Module 'Histogram'
2
3from Buttons import *
Guido van Rossume15607f1990-10-31 11:17:34 +00004from Resize import Resize
Guido van Rossume1f069e1990-10-25 18:51:42 +00005
6
7# A Histogram displays a histogram of numeric data.
8# It reacts to resize events by resizing itself,
9# leaving the same amount of space around the borders.
Guido van Rossume15607f1990-10-31 11:17:34 +000010# (This is geometry management, and should really be implemented
11# by a different group of classes, but for now this hack is OK.)
Guido van Rossume1f069e1990-10-25 18:51:42 +000012#
Guido van Rossume15607f1990-10-31 11:17:34 +000013class HistogramAppearance() = Resize(), LabelAppearance():
Guido van Rossume1f069e1990-10-25 18:51:42 +000014 #
15 def define(self, (win, bounds, ydata, scale)):
16 self.init_appearance(win, bounds)
Guido van Rossume15607f1990-10-31 11:17:34 +000017 self.init_resize()
Guido van Rossume1f069e1990-10-25 18:51:42 +000018 self.ydata = ydata
19 self.scale = scale # (min, max)
Guido van Rossume1f069e1990-10-25 18:51:42 +000020 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 #
Guido van Rossume1f069e1990-10-25 18:51:42 +000040
Guido van Rossume15607f1990-10-31 11:17:34 +000041class Histogram() = HistogramAppearance(), NoReactivity(): pass