From a1f7d7470fb7c758eca9f234c183cbadcd01c59a Mon Sep 17 00:00:00 2001 From: Christopher Stone Date: Sun, 11 Feb 2018 19:06:38 +0000 Subject: [PATCH] Improvements to layout code, still needs y-axis label rotating --- telemetry/code/monitor/graph_plotter_rewrite.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/telemetry/code/monitor/graph_plotter_rewrite.py b/telemetry/code/monitor/graph_plotter_rewrite.py index 81a6dc3..b95ca60 100755 --- a/telemetry/code/monitor/graph_plotter_rewrite.py +++ b/telemetry/code/monitor/graph_plotter_rewrite.py @@ -59,38 +59,44 @@ 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.series.title, color=BLACK, - font_name=self.font, font_size=self.height*self.margins[0]*0.6, x=self.width/2, y=self.height, + font_name=self.font, font_size=self.height*self.margins[0]*0.5, + x=self.width/2, y=self.height-(self.margins[1]), anchor_x='center', anchor_y='top') heading.draw() def drawAxis(self, axis): # axis=0 is x, 1 is y - limita = self.bounds[axis][1] - limitb = self.bounds[axis][0] - start = self.bounds[1-axis][0] - stop = self.bounds[1-axis][1] + limita = self.bounds[1-axis][1] + limitb = self.bounds[1-axis][0] + start = self.bounds[axis][0] + stop = self.bounds[axis][1] increment = float(stop-start)/self.lines[axis] for pos in numpy.arange(start, stop+1, increment): # Using fp arithmetic to avoid intermittent fencepost errors pos = int(pos) - if axis==0: - pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (limita, pos, limitb, pos)), + if axis==0: # x axis, vertical lines + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (pos, limita, pos, limitb)), ('c3B', (0, 0, 0, 0, 0, 0))) tag = pyglet.text.Label("123", color=BLACK, - font_name=self.font, font_size=self.height*self.margins[1-axis]*0.3, + font_name=self.font, font_size=self.height*self.margins[1-axis]*0.28, x=pos, y=self.height*self.margins[axis], anchor_x='left', anchor_y='top') - if axis==1: - pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (pos, limita, pos, limitb)), + axistitle = pyglet.text.Label(self.series.xname, color=BLACK, + font_name=self.font, font_size=self.height*self.margins[axis]*0.3, + x=self.width/2, y=0, + anchor_x='center', anchor_y='bottom') + if axis==1: # y axis, horizontal lines + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (limita, pos, limitb, pos)), ('c3B', (0, 0, 0, 0, 0, 0))) tag = pyglet.text.Label("123", color=BLACK, - font_name=self.font, font_size=self.width*self.margins[1-axis]*0.3, - x=self.width*self.margins[axis], y=pos, + font_name=self.font, font_size=self.width*self.margins[axis]*0.22, + x=self.width*self.margins[1-axis]*0.9, y=pos, anchor_x='right', anchor_y='center') - + axistitle = pyglet.text.Label(self.series.yname, color=BLACK, + font_name=self.font, font_size=self.height*self.margins[axis]*0.3, + x=0, y=self.height/2, + anchor_x='left', anchor_y='center') 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() -- libgit2 0.21.2