diff --git a/telemetry/code/monitor/graph_plotter_rewrite.py b/telemetry/code/monitor/graph_plotter_rewrite.py index 662178a..a556ee8 100755 --- a/telemetry/code/monitor/graph_plotter_rewrite.py +++ b/telemetry/code/monitor/graph_plotter_rewrite.py @@ -4,6 +4,7 @@ import pyglet #import math #import time import serial +import numpy from colours import * @@ -33,12 +34,11 @@ class Plot(pyglet.window.Window): """Setup a the details of a plot, and create a corresponding window""" pyglet.window.Window.__init__(self, resizable=True) self.series = series - self.title = self.series.title self.font = 'Arkhip' - self.margins = (0.05, 0.05) # Fractions of window size + self.margins = (0.08, 0.08) # Fractions of window size self.lines = (12, 8) #self.resizable = True - self.set_caption(self.title) + self.set_caption(self.series.title) def on_resize(self, width, height): self.bounds = ((int(self.width * self.margins[0]), int(self.width * (1 - self.margins[0]))), @@ -50,6 +50,7 @@ class Plot(pyglet.window.Window): self.drawBackground() self.drawHeading() self.drawXAxis() + self.drawYAxis() def drawBackground(self): """Draw the graph background, currently a plain colour""" @@ -57,15 +58,43 @@ class Plot(pyglet.window.Window): def drawHeading(self): """Draw a title for the graph (duplicated in the window titlebar, if present""" - heading = pyglet.text.Label(self.title, color=BLACK, - font_name=self.font, font_size=self.height*self.margins[0]*0.8, x=self.width/2, y=self.height, + heading = pyglet.text.Label(self.series.title, color=BLACK, + font_name=self.font, font_size=self.height*self.margins[0]*0.6, x=self.width/2, y=self.height, anchor_x='center', anchor_y='top') heading.draw() def drawXAxis(self): - pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (self.bounds[0][0], self.bounds[1][0], - self.bounds[0][0], self.bounds[1][1])), - ('c3B', (0, 0, 0, 0, 0, 0))) + top = self.bounds[1][1] + bot = self.bounds[1][0] + start = self.bounds[0][0] + stop = self.bounds[0][1] + increment = float(stop-start)/self.lines[0] + for x in numpy.arange(start, stop+1, increment): + # Using fp arithmetic to avoid intermittent fencepost errors + x = int(x) + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (x, top, x, bot)), + ('c3B', (0, 0, 0, 0, 0, 0))) + tag = pyglet.text.Label("123", color=BLACK, + font_name=self.font, font_size=self.height*self.margins[0]*0.3, + x=x, y=self.height*self.margins[0], + anchor_x='center', anchor_y='top') + tag.draw() + axistitle = pyglet.text.Label(self.series.xname, color=BLACK, + font_name=self.font, font_size=self.height*self.margins[0]*0.3, x=self.width/2, y=0, + anchor_x='center', anchor_y='bottom') + axistitle.draw() + + def drawYAxis(self): + lef = self.bounds[0][0] + rig = self.bounds[0][1] + start = self.bounds[1][0] + stop = self.bounds[1][1] + increment = float(stop-start)/self.lines[1] + for y in numpy.arange(start, stop+1, increment): + # Using fp arithmetic to avoid intermittent fencepost errors + y = int(y) + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (lef, y, rig, y)), + ('c3B', (0, 0, 0, 0, 0, 0))) -- libgit2 0.21.2