From 99dd1cb77645a826db0ec0c24ca386ecf5cf8db6 Mon Sep 17 00:00:00 2001 From: Christopher Stone Date: Thu, 8 Feb 2018 22:08:29 +0000 Subject: [PATCH] Preparation for supporting multiple windows simultaneously --- telemetry/code/monitor/graph_plotter.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/telemetry/code/monitor/graph_plotter.py b/telemetry/code/monitor/graph_plotter.py index 7816753..d5a79bb 100755 --- a/telemetry/code/monitor/graph_plotter.py +++ b/telemetry/code/monitor/graph_plotter.py @@ -17,7 +17,7 @@ datafeed = serial.Serial( red = [1, 0, 0] green = [0, 1, 0] -blue = [0, 0, 1] +blue = [0.2, 0.5, 1] window = pyglet.window.Window(800, 480, resizable=True) window.set_caption("Raw data") @@ -25,31 +25,31 @@ window.set_caption("Raw data") starttime = time.time() -def drawgrid(xlines, ylines, xlimits, ylimits): +def drawgrid(target, xlines, ylines, xlimits, ylimits): pyglet.gl.glColor3f(0.5, 0.5, 0.5) - for xpos in range(0, window.width, window.width/xlines): - pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (xpos, 0, xpos, window.height))) - tagtext = str(round((xlimits[1]-xlimits[0])*(float(xpos)/window.width) + xlimits[0], 1)) + for xpos in range(0, target.width, target.width/xlines): + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (xpos, 0, xpos, target.height))) + tagtext = str(round((xlimits[1]-xlimits[0])*(float(xpos)/target.width) + xlimits[0], 1)) tag = pyglet.text.Label(tagtext, font_name='Arkhip', font_size=10, x=xpos-2, y=0, anchor_x='right', anchor_y='bottom') tag.draw() - for ypos in range(0, window.width, window.height/ylines): - pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (0, ypos, window.width, ypos))) - tagtext = str(round((ylimits[1]-ylimits[0])*(float(ypos)/window.height) + ylimits[0], 1)) + for ypos in range(0, target.width, target.height/ylines): + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (0, ypos, target.width, ypos))) + tagtext = str(round((ylimits[1]-ylimits[0])*(float(ypos)/target.height) + ylimits[0], 1)) tag = pyglet.text.Label(tagtext, font_name='Arkhip', font_size=10, x=0, y=ypos-2, anchor_x='left', anchor_y='top') tag.draw() -def plotline(xdata, ydata, colour): +def plotline(target, xdata, ydata, colour): pyglet.gl.glColor3f(colour[0], colour[1], colour[2]) points = [] for n in range(max(len(xdata), len(ydata))): try: - xpos = ((xdata[n]-min(xdata))*window.width)/(max(xdata)-min(xdata)) + xpos = ((xdata[n]-min(xdata))*target.width)/(max(xdata)-min(xdata)) except: xpos = 0 xpos = int(xpos) try: - ypos = ((ydata[n]-min(ydata))*window.height)/(max(ydata)-min(ydata)) + ypos = ((ydata[n]-min(ydata))*target.height)/(max(ydata)-min(ydata)) except: ypos = 0 ypos = int(ypos) @@ -90,13 +90,15 @@ def poll_serial(foo): pyglet.clock.schedule_interval(poll_serial, 0.01) +def drawgraph(target, xpoints, ypoints, colour): + plotline(target, xpoints, ypoints, colour) + drawgrid(target, 16, 10, [min(xpoints), max(xpoints)], [min(ypoints), max(ypoints)]) @window.event def on_draw(): window.clear() + drawgraph(window, xdata, ydata, blue) - drawgrid(16, 10, [min(xdata), max(xdata)], [min(ydata), max(ydata)]) - plotline(xdata, ydata, red) -- libgit2 0.21.2