Commit 99dd1cb77645a826db0ec0c24ca386ecf5cf8db6
1 parent
4cf57310
Exists in
master
Preparation for supporting multiple windows simultaneously
Showing
1 changed file
with
15 additions
and
13 deletions
Show diff stats
telemetry/code/monitor/graph_plotter.py
| ... | ... | @@ -17,7 +17,7 @@ datafeed = serial.Serial( |
| 17 | 17 | |
| 18 | 18 | red = [1, 0, 0] |
| 19 | 19 | green = [0, 1, 0] |
| 20 | -blue = [0, 0, 1] | |
| 20 | +blue = [0.2, 0.5, 1] | |
| 21 | 21 | |
| 22 | 22 | window = pyglet.window.Window(800, 480, resizable=True) |
| 23 | 23 | window.set_caption("Raw data") |
| ... | ... | @@ -25,31 +25,31 @@ window.set_caption("Raw data") |
| 25 | 25 | starttime = time.time() |
| 26 | 26 | |
| 27 | 27 | |
| 28 | -def drawgrid(xlines, ylines, xlimits, ylimits): | |
| 28 | +def drawgrid(target, xlines, ylines, xlimits, ylimits): | |
| 29 | 29 | pyglet.gl.glColor3f(0.5, 0.5, 0.5) |
| 30 | - for xpos in range(0, window.width, window.width/xlines): | |
| 31 | - pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (xpos, 0, xpos, window.height))) | |
| 32 | - tagtext = str(round((xlimits[1]-xlimits[0])*(float(xpos)/window.width) + xlimits[0], 1)) | |
| 30 | + for xpos in range(0, target.width, target.width/xlines): | |
| 31 | + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (xpos, 0, xpos, target.height))) | |
| 32 | + tagtext = str(round((xlimits[1]-xlimits[0])*(float(xpos)/target.width) + xlimits[0], 1)) | |
| 33 | 33 | tag = pyglet.text.Label(tagtext, font_name='Arkhip', font_size=10, x=xpos-2, y=0, anchor_x='right', anchor_y='bottom') |
| 34 | 34 | tag.draw() |
| 35 | - for ypos in range(0, window.width, window.height/ylines): | |
| 36 | - pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (0, ypos, window.width, ypos))) | |
| 37 | - tagtext = str(round((ylimits[1]-ylimits[0])*(float(ypos)/window.height) + ylimits[0], 1)) | |
| 35 | + for ypos in range(0, target.width, target.height/ylines): | |
| 36 | + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (0, ypos, target.width, ypos))) | |
| 37 | + tagtext = str(round((ylimits[1]-ylimits[0])*(float(ypos)/target.height) + ylimits[0], 1)) | |
| 38 | 38 | tag = pyglet.text.Label(tagtext, font_name='Arkhip', font_size=10, x=0, y=ypos-2, anchor_x='left', anchor_y='top') |
| 39 | 39 | tag.draw() |
| 40 | 40 | |
| 41 | 41 | |
| 42 | -def plotline(xdata, ydata, colour): | |
| 42 | +def plotline(target, xdata, ydata, colour): | |
| 43 | 43 | pyglet.gl.glColor3f(colour[0], colour[1], colour[2]) |
| 44 | 44 | points = [] |
| 45 | 45 | for n in range(max(len(xdata), len(ydata))): |
| 46 | 46 | try: |
| 47 | - xpos = ((xdata[n]-min(xdata))*window.width)/(max(xdata)-min(xdata)) | |
| 47 | + xpos = ((xdata[n]-min(xdata))*target.width)/(max(xdata)-min(xdata)) | |
| 48 | 48 | except: |
| 49 | 49 | xpos = 0 |
| 50 | 50 | xpos = int(xpos) |
| 51 | 51 | try: |
| 52 | - ypos = ((ydata[n]-min(ydata))*window.height)/(max(ydata)-min(ydata)) | |
| 52 | + ypos = ((ydata[n]-min(ydata))*target.height)/(max(ydata)-min(ydata)) | |
| 53 | 53 | except: |
| 54 | 54 | ypos = 0 |
| 55 | 55 | ypos = int(ypos) |
| ... | ... | @@ -90,13 +90,15 @@ def poll_serial(foo): |
| 90 | 90 | |
| 91 | 91 | pyglet.clock.schedule_interval(poll_serial, 0.01) |
| 92 | 92 | |
| 93 | +def drawgraph(target, xpoints, ypoints, colour): | |
| 94 | + plotline(target, xpoints, ypoints, colour) | |
| 95 | + drawgrid(target, 16, 10, [min(xpoints), max(xpoints)], [min(ypoints), max(ypoints)]) | |
| 93 | 96 | |
| 94 | 97 | @window.event |
| 95 | 98 | def on_draw(): |
| 96 | 99 | window.clear() |
| 100 | + drawgraph(window, xdata, ydata, blue) | |
| 97 | 101 | |
| 98 | - drawgrid(16, 10, [min(xdata), max(xdata)], [min(ydata), max(ydata)]) | |
| 99 | - plotline(xdata, ydata, red) | |
| 100 | 102 | |
| 101 | 103 | |
| 102 | 104 | ... | ... |