cpython/Lib/stdwin/Histogram.py

42 lines
1.1 KiB
Python
Raw Normal View History

1990-10-25 18:51:42 +00:00
# Module 'Histogram'
from Buttons import *
1990-10-31 11:17:34 +00:00
from Resize import Resize
1990-10-25 18:51:42 +00:00
# A Histogram displays a histogram of numeric data.
# It reacts to resize events by resizing itself,
# leaving the same amount of space around the borders.
1990-10-31 11:17:34 +00:00
# (This is geometry management, and should really be implemented
# by a different group of classes, but for now this hack is OK.)
1990-10-25 18:51:42 +00:00
#
1990-10-31 11:17:34 +00:00
class HistogramAppearance() = Resize(), LabelAppearance():
1990-10-25 18:51:42 +00:00
#
def define(self, (win, bounds, ydata, scale)):
self.init_appearance(win, bounds)
1990-10-31 11:17:34 +00:00
self.init_resize()
1990-10-25 18:51:42 +00:00
self.ydata = ydata
self.scale = scale # (min, max)
return self
#
def setdata(self, (ydata, scale)):
self.ydata = ydata
self.scale = scale # (min, max)
self.win.change(self.bounds)
#
def drawit(self, d):
ydata = self.ydata
(left, top), (right, bottom) = self.bounds
min, max = self.scale
size = max-min
width, height = right-left, bottom-top
for i in range(len(ydata)):
h0 = left + i * width/len(ydata)
h1 = left + (i+1) * width/len(ydata)
v0 = top + height - (self.ydata[i]-min)*height/size
v1 = top + height
d.paint((h0, v0), (h1, v1))
#
1990-10-31 11:17:34 +00:00
class Histogram() = HistogramAppearance(), NoReactivity(): pass