Commit 6432a3a50300598dcd33bc27fe75ebb763bded79
1 parent
01bfd701
Exists in
master
Added class to keep data in
Showing
1 changed file
with
19 additions
and
4 deletions
Show diff stats
telemetry/code/monitor/graph_plotter_rewrite.py
| ... | ... | @@ -7,14 +7,27 @@ import pyglet |
| 7 | 7 | |
| 8 | 8 | from colours import * |
| 9 | 9 | |
| 10 | +class Series: | |
| 11 | + def __init__(self, points=100, title="Series title", xname="x-axis name", yname="y-axis name"): | |
| 12 | + self.title = title | |
| 13 | + self.xname = xname | |
| 14 | + self.yname = yname | |
| 15 | + self.data = [] | |
| 16 | + self.points = points | |
| 17 | + def addpoint(self, point): | |
| 18 | + self.data.append(point) | |
| 19 | + if len(self.data) > self.points: | |
| 20 | + del self.points[-1] | |
| 21 | + | |
| 10 | 22 | class Plot: |
| 11 | - def __init__(self, title="Unknown", size=(640, 480)): | |
| 23 | + def __init__(self, series, size=(640, 480)): | |
| 12 | 24 | """Setup a the details of a plot, and create a corresponding window""" |
| 13 | - self.title = title | |
| 25 | + self.series = series | |
| 26 | + self.title = self.series.title | |
| 14 | 27 | self.size = size |
| 15 | 28 | self.font = 'Arkhip' |
| 16 | 29 | self.window = pyglet.window.Window(self.size[0], self.size[1], resizable=True) |
| 17 | - self.window.set_caption(title) | |
| 30 | + self.window.set_caption(self.title) | |
| 18 | 31 | self.window.on_resize = self.resize |
| 19 | 32 | self.window.on_draw = self.draw |
| 20 | 33 | |
| ... | ... | @@ -39,8 +52,10 @@ class Plot: |
| 39 | 52 | anchor_x='center', anchor_y='top') |
| 40 | 53 | heading.draw() |
| 41 | 54 | |
| 55 | +testseries = Series() | |
| 56 | + | |
| 42 | 57 | plots = [] |
| 43 | -plots.append(Plot("This is a test plot")) | |
| 58 | +plots.append(Plot(testseries)) | |
| 44 | 59 | |
| 45 | 60 | def pollSerial(foo): |
| 46 | 61 | """Dummy, will check serial port for incoming data""" | ... | ... |