blob: ac767c3e110f94659214de56443a69f84ec88666 [file] [log] [blame]
Guido van Rossum36ddc9e1990-10-31 11:24:22 +00001# Module 'StripChart'
2
Guido van Rossum36ddc9e1990-10-31 11:24:22 +00003import rect
Guido van Rossum0c89ec71990-11-05 19:44:31 +00004from Buttons import LabelAppearance, NoReactivity
Guido van Rossum36ddc9e1990-10-31 11:24:22 +00005
Guido van Rossum0c89ec71990-11-05 19:44:31 +00006# A StripChart doesn't really look like a label but it needs a base class.
7# LabelAppearance allows it to be disabled and hilited.
Guido van Rossum36ddc9e1990-10-31 11:24:22 +00008
Guido van Rossum0c89ec71990-11-05 19:44:31 +00009class StripChart() = LabelAppearance(), NoReactivity():
Guido van Rossum36ddc9e1990-10-31 11:24:22 +000010 #
Guido van Rossum0c89ec71990-11-05 19:44:31 +000011 def define(self, (parent, scale)):
12 self.parent = parent
13 parent.addchild(self)
14 self.init_appearance()
Guido van Rossum36ddc9e1990-10-31 11:24:22 +000015 self.init_reactivity()
Guido van Rossum36ddc9e1990-10-31 11:24:22 +000016 self.ydata = []
17 self.scale = scale
18 self.resetbounds()
19 return self
20 #
21 def setbounds(self, bounds):
22 LabelAppearance.setbounds(self, bounds)
23 self.resetbounds()
24 #
25 def resetbounds(self):
26 (left, top), (right, bottom) = self.bounds
27 self.width = right-left
28 self.height = bottom-top
29 excess = len(self.ydata) - self.width
30 if excess > 0:
31 del self.ydata[:excess]
32 elif excess < 0:
33 while len(self.ydata) < self.width:
34 self.ydata.insert(0, 0)
35 #
36 def append(self, y):
37 self.ydata.append(y)
38 excess = len(self.ydata) - self.width
39 if excess > 0:
40 del self.ydata[:excess]
Guido van Rossum0c89ec71990-11-05 19:44:31 +000041 if self.bounds <> rect.empty:
42 self.parent.scroll(self.bounds, (-excess, 0))
43 if self.bounds <> rect.empty:
Guido van Rossum36ddc9e1990-10-31 11:24:22 +000044 (left, top), (right, bottom) = self.bounds
45 i = len(self.ydata)
46 area = (left+i-1, top), (left+i, bottom)
Guido van Rossum0c89ec71990-11-05 19:44:31 +000047 self.draw(self.parent.begindrawing(), area)
Guido van Rossum36ddc9e1990-10-31 11:24:22 +000048 #
49 def draw(self, (d, area)):
Guido van Rossum36ddc9e1990-10-31 11:24:22 +000050 area = rect.intersect(area, self.bounds)
51 if area = rect.empty:
Guido van Rossum0c89ec71990-11-05 19:44:31 +000052 print 'mt'
Guido van Rossum36ddc9e1990-10-31 11:24:22 +000053 return
54 d.cliprect(area)
55 d.erase(self.bounds)
56 (a_left, a_top), (a_right, a_bottom) = area
57 (left, top), (right, bottom) = self.bounds
58 height = bottom - top
59 i1 = a_left - left
60 i2 = a_right - left
61 for i in range(max(0, i1), min(len(self.ydata), i2)):
62 split = bottom-self.ydata[i]*height/self.scale
63 d.paint((left+i, split), (left+i+1, bottom))
64 if not self.enabled:
65 self.flipenable(d)
66 if self.hilited:
67 self.fliphilite(d)
68 d.noclip()