From 6afdc6b905c25c2a1eca165cfdf67d98189c3bc1 Mon Sep 17 00:00:00 2001 From: Christopher Stone Date: Thu, 8 Feb 2018 19:06:40 +0000 Subject: [PATCH] Attempt at drawing graphs with pyglet. Currently just draws axes --- telemetry/code/monitor/pyglet_test.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+), 0 deletions(-) create mode 100644 telemetry/code/monitor/pyglet_test.py diff --git a/telemetry/code/monitor/pyglet_test.py b/telemetry/code/monitor/pyglet_test.py new file mode 100644 index 0000000..1c6eb5e --- /dev/null +++ b/telemetry/code/monitor/pyglet_test.py @@ -0,0 +1,42 @@ +import pyglet +import math + +window = pyglet.window.Window() +window.set_caption("Test graph") + +title = pyglet.text.Label('Test Graph', + font_name='Arkhip', + font_size=12, + x=window.width//2, y=window.height//2, + anchor_x='center', anchor_y='top') + + +def round_sig(x, sig=2): + return round(x, sig-int(math.floor(math.log10(abs(x))))-1) + +def drawgrid(xlines, ylines, xlimits, ylimits): + 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), 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.width/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), 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): + pass + + +xdata = [1, 2, 3, 4, 5, 6, 7, 7.4, 9, 10] +ydata = [81, 86, 58, 20, 59, 3, -6, 4.8] + +@window.event +def on_draw(): + window.clear() + drawgrid(10, 12, [min(xdata), max(xdata)], [min(ydata), max(ydata)]) + +pyglet.app.run() \ No newline at end of file -- libgit2 0.21.2