Commit 6afdc6b905c25c2a1eca165cfdf67d98189c3bc1

Authored by Christopher Stone
1 parent 4c388833
Exists in master

Attempt at drawing graphs with pyglet. Currently just draws axes

Showing 1 changed file with 42 additions and 0 deletions   Show diff stats
telemetry/code/monitor/pyglet_test.py 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +import pyglet
  2 +import math
  3 +
  4 +window = pyglet.window.Window()
  5 +window.set_caption("Test graph")
  6 +
  7 +title = pyglet.text.Label('Test Graph',
  8 + font_name='Arkhip',
  9 + font_size=12,
  10 + x=window.width//2, y=window.height//2,
  11 + anchor_x='center', anchor_y='top')
  12 +
  13 +
  14 +def round_sig(x, sig=2):
  15 + return round(x, sig-int(math.floor(math.log10(abs(x))))-1)
  16 +
  17 +def drawgrid(xlines, ylines, xlimits, ylimits):
  18 + for xpos in range(0, window.width, window.width/xlines):
  19 + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (xpos, 0, xpos, window.height)))
  20 + tagtext = str(round((xlimits[1]-xlimits[0])*(float(xpos)/window.width), 1))
  21 + tag = pyglet.text.Label(tagtext, font_name='Arkhip', font_size=10, x=xpos-2, y=0, anchor_x='right', anchor_y='bottom')
  22 + tag.draw()
  23 + for ypos in range(0, window.width, window.width/ylines):
  24 + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (0, ypos, window.width, ypos)))
  25 + tagtext = str(round((ylimits[1]-ylimits[0])*(float(ypos)/window.height), 1))
  26 + tag = pyglet.text.Label(tagtext, font_name='Arkhip', font_size=10, x=0, y=ypos-2, anchor_x='left', anchor_y='top')
  27 + tag.draw()
  28 +
  29 +
  30 +def plotline(xdata, ydata):
  31 + pass
  32 +
  33 +
  34 +xdata = [1, 2, 3, 4, 5, 6, 7, 7.4, 9, 10]
  35 +ydata = [81, 86, 58, 20, 59, 3, -6, 4.8]
  36 +
  37 +@window.event
  38 +def on_draw():
  39 + window.clear()
  40 + drawgrid(10, 12, [min(xdata), max(xdata)], [min(ydata), max(ydata)])
  41 +
  42 +pyglet.app.run()
0 43 \ No newline at end of file
... ...