Commit cad30d6c9a94ad51e9f4fd9300d39322bc30d053

Authored by Christopher Stone
1 parent 9159742e
Exists in master

Progress towards drawing graph axes

Showing 1 changed file with 14 additions and 2 deletions   Show diff stats
telemetry/code/monitor/graph_plotter_rewrite.py
@@ -28,17 +28,21 @@ class Series: @@ -28,17 +28,21 @@ class Series:
28 if len(self.data) > self.points: 28 if len(self.data) > self.points:
29 del self.points[-1] 29 del self.points[-1]
30 30
31 -class Plot: 31 +class Plot():
32 def __init__(self, series, size=(640, 480)): 32 def __init__(self, series, size=(640, 480)):
33 """Setup a the details of a plot, and create a corresponding window""" 33 """Setup a the details of a plot, and create a corresponding window"""
34 self.series = series 34 self.series = series
35 self.title = self.series.title 35 self.title = self.series.title
36 self.size = size 36 self.size = size
37 self.font = 'Arkhip' 37 self.font = 'Arkhip'
  38 + self.margins = (0.02, 0.02) # Fractions of window size
  39 + self.lines = (12, 8)
38 self.window = pyglet.window.Window(self.size[0], self.size[1], resizable=True) 40 self.window = pyglet.window.Window(self.size[0], self.size[1], resizable=True)
39 self.window.set_caption(self.title) 41 self.window.set_caption(self.title)
40 self.window.on_resize = self.resize 42 self.window.on_resize = self.resize
41 self.window.on_draw = self.draw 43 self.window.on_draw = self.draw
  44 + self.bounds = ((int(self.window.width * self.margins[0]), int(self.window.width * (1 - self.margins[0]))),
  45 + (int(self.window.height * self.margins[1]), int(self.window.height * (1 - self.margins[1]))))
42 46
43 def resize(self, width, height): 47 def resize(self, width, height):
44 """Handle a pyglet resize event, then give control back to the event loop""" 48 """Handle a pyglet resize event, then give control back to the event loop"""
@@ -49,6 +53,7 @@ class Plot: @@ -49,6 +53,7 @@ class Plot:
49 """Draw all the components of the graph""" 53 """Draw all the components of the graph"""
50 self.drawBackground() 54 self.drawBackground()
51 self.drawHeading() 55 self.drawHeading()
  56 + self.drawXAxis()
52 57
53 def drawBackground(self): 58 def drawBackground(self):
54 """Draw the graph background, currently a plain colour""" 59 """Draw the graph background, currently a plain colour"""
@@ -57,9 +62,16 @@ class Plot: @@ -57,9 +62,16 @@ class Plot:
57 def drawHeading(self): 62 def drawHeading(self):
58 """Draw a title for the graph (duplicated in the window titlebar, if present""" 63 """Draw a title for the graph (duplicated in the window titlebar, if present"""
59 heading = pyglet.text.Label(self.title, color=BLACK, 64 heading = pyglet.text.Label(self.title, color=BLACK,
60 - font_name=self.font, font_size=self.size[0]/50, x=self.size[0]/2, y=self.size[1], 65 + font_name=self.font, font_size=self.size[0]*self.margins[0], x=self.size[0]/2, y=self.size[1],
61 anchor_x='center', anchor_y='top') 66 anchor_x='center', anchor_y='top')
62 heading.draw() 67 heading.draw()
  68 +
  69 + def drawXAxis(self):
  70 + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (self.bounds[0][0], self.bounds[1][0],
  71 + self.bounds[1][0], self.bounds[1][1])),
  72 + ('c3B', (0, 0, 0, 0, 0, 0)))
  73 +
  74 +
63 75
64 testseries = Series() 76 testseries = Series()
65 77