Commit 3ce449c7b4dbad3b728f96bf2bd502a916a53f77
1 parent
4863d03c
Exists in
master
Added axis title and placeholder labels for x-axis
Showing
1 changed file
with
37 additions
and
8 deletions
Show diff stats
telemetry/code/monitor/graph_plotter_rewrite.py
| ... | ... | @@ -4,6 +4,7 @@ import pyglet |
| 4 | 4 | #import math |
| 5 | 5 | #import time |
| 6 | 6 | import serial |
| 7 | +import numpy | |
| 7 | 8 | |
| 8 | 9 | from colours import * |
| 9 | 10 | |
| ... | ... | @@ -33,12 +34,11 @@ class Plot(pyglet.window.Window): |
| 33 | 34 | """Setup a the details of a plot, and create a corresponding window""" |
| 34 | 35 | pyglet.window.Window.__init__(self, resizable=True) |
| 35 | 36 | self.series = series |
| 36 | - self.title = self.series.title | |
| 37 | 37 | self.font = 'Arkhip' |
| 38 | - self.margins = (0.05, 0.05) # Fractions of window size | |
| 38 | + self.margins = (0.08, 0.08) # Fractions of window size | |
| 39 | 39 | self.lines = (12, 8) |
| 40 | 40 | #self.resizable = True |
| 41 | - self.set_caption(self.title) | |
| 41 | + self.set_caption(self.series.title) | |
| 42 | 42 | |
| 43 | 43 | def on_resize(self, width, height): |
| 44 | 44 | self.bounds = ((int(self.width * self.margins[0]), int(self.width * (1 - self.margins[0]))), |
| ... | ... | @@ -50,6 +50,7 @@ class Plot(pyglet.window.Window): |
| 50 | 50 | self.drawBackground() |
| 51 | 51 | self.drawHeading() |
| 52 | 52 | self.drawXAxis() |
| 53 | + self.drawYAxis() | |
| 53 | 54 | |
| 54 | 55 | def drawBackground(self): |
| 55 | 56 | """Draw the graph background, currently a plain colour""" |
| ... | ... | @@ -57,15 +58,43 @@ class Plot(pyglet.window.Window): |
| 57 | 58 | |
| 58 | 59 | def drawHeading(self): |
| 59 | 60 | """Draw a title for the graph (duplicated in the window titlebar, if present""" |
| 60 | - heading = pyglet.text.Label(self.title, color=BLACK, | |
| 61 | - font_name=self.font, font_size=self.height*self.margins[0]*0.8, x=self.width/2, y=self.height, | |
| 61 | + heading = pyglet.text.Label(self.series.title, color=BLACK, | |
| 62 | + font_name=self.font, font_size=self.height*self.margins[0]*0.6, x=self.width/2, y=self.height, | |
| 62 | 63 | anchor_x='center', anchor_y='top') |
| 63 | 64 | heading.draw() |
| 64 | 65 | |
| 65 | 66 | def drawXAxis(self): |
| 66 | - pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (self.bounds[0][0], self.bounds[1][0], | |
| 67 | - self.bounds[0][0], self.bounds[1][1])), | |
| 68 | - ('c3B', (0, 0, 0, 0, 0, 0))) | |
| 67 | + top = self.bounds[1][1] | |
| 68 | + bot = self.bounds[1][0] | |
| 69 | + start = self.bounds[0][0] | |
| 70 | + stop = self.bounds[0][1] | |
| 71 | + increment = float(stop-start)/self.lines[0] | |
| 72 | + for x in numpy.arange(start, stop+1, increment): | |
| 73 | + # Using fp arithmetic to avoid intermittent fencepost errors | |
| 74 | + x = int(x) | |
| 75 | + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (x, top, x, bot)), | |
| 76 | + ('c3B', (0, 0, 0, 0, 0, 0))) | |
| 77 | + tag = pyglet.text.Label("123", color=BLACK, | |
| 78 | + font_name=self.font, font_size=self.height*self.margins[0]*0.3, | |
| 79 | + x=x, y=self.height*self.margins[0], | |
| 80 | + anchor_x='center', anchor_y='top') | |
| 81 | + tag.draw() | |
| 82 | + axistitle = pyglet.text.Label(self.series.xname, color=BLACK, | |
| 83 | + font_name=self.font, font_size=self.height*self.margins[0]*0.3, x=self.width/2, y=0, | |
| 84 | + anchor_x='center', anchor_y='bottom') | |
| 85 | + axistitle.draw() | |
| 86 | + | |
| 87 | + def drawYAxis(self): | |
| 88 | + lef = self.bounds[0][0] | |
| 89 | + rig = self.bounds[0][1] | |
| 90 | + start = self.bounds[1][0] | |
| 91 | + stop = self.bounds[1][1] | |
| 92 | + increment = float(stop-start)/self.lines[1] | |
| 93 | + for y in numpy.arange(start, stop+1, increment): | |
| 94 | + # Using fp arithmetic to avoid intermittent fencepost errors | |
| 95 | + y = int(y) | |
| 96 | + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (lef, y, rig, y)), | |
| 97 | + ('c3B', (0, 0, 0, 0, 0, 0))) | |
| 69 | 98 | |
| 70 | 99 | |
| 71 | 100 | ... | ... |