From cad30d6c9a94ad51e9f4fd9300d39322bc30d053 Mon Sep 17 00:00:00 2001 From: Christopher Stone Date: Fri, 9 Feb 2018 22:54:34 +0000 Subject: [PATCH] Progress towards drawing graph axes --- telemetry/code/monitor/graph_plotter_rewrite.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/telemetry/code/monitor/graph_plotter_rewrite.py b/telemetry/code/monitor/graph_plotter_rewrite.py index 1d23332..d6fd81c 100755 --- a/telemetry/code/monitor/graph_plotter_rewrite.py +++ b/telemetry/code/monitor/graph_plotter_rewrite.py @@ -28,17 +28,21 @@ class Series: if len(self.data) > self.points: del self.points[-1] -class Plot: +class Plot(): def __init__(self, series, size=(640, 480)): """Setup a the details of a plot, and create a corresponding window""" self.series = series self.title = self.series.title self.size = size self.font = 'Arkhip' + self.margins = (0.02, 0.02) # Fractions of window size + self.lines = (12, 8) self.window = pyglet.window.Window(self.size[0], self.size[1], resizable=True) self.window.set_caption(self.title) self.window.on_resize = self.resize self.window.on_draw = self.draw + self.bounds = ((int(self.window.width * self.margins[0]), int(self.window.width * (1 - self.margins[0]))), + (int(self.window.height * self.margins[1]), int(self.window.height * (1 - self.margins[1])))) def resize(self, width, height): """Handle a pyglet resize event, then give control back to the event loop""" @@ -49,6 +53,7 @@ class Plot: """Draw all the components of the graph""" self.drawBackground() self.drawHeading() + self.drawXAxis() def drawBackground(self): """Draw the graph background, currently a plain colour""" @@ -57,9 +62,16 @@ class Plot: 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.size[0]/50, x=self.size[0]/2, y=self.size[1], + font_name=self.font, font_size=self.size[0]*self.margins[0], x=self.size[0]/2, y=self.size[1], 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[1][0], self.bounds[1][1])), + ('c3B', (0, 0, 0, 0, 0, 0))) + + testseries = Series() -- libgit2 0.21.2