Commit 6510d668c1d0418845b242a82b4cf603c2028a6c

Authored by Christopher Stone
2 parents a304b3d8 b4a36d26
Exists in master

Merge branch 'master' of http://128.243.70.77/UoN_EEE/Robot_Wars

robots/little_john/telemetry/code/monitor/graph_plotter_rewrite.py
@@ -29,6 +29,11 @@ elif datafeed == None: @@ -29,6 +29,11 @@ elif datafeed == None:
29 easygui.msgbox("Failed to open serial port for unknown reason!", "Fatal error") 29 easygui.msgbox("Failed to open serial port for unknown reason!", "Fatal error")
30 sys.exit() 30 sys.exit()
31 31
  32 +if platform.system()=='Windows': #easier than passing vars
  33 + os='Windows'
  34 +else:
  35 + os='Other'
  36 +
32 class Series: 37 class Series:
33 def __init__(self, points=100, title="Series title", xname="x-axis name", yname="y-axis name"): 38 def __init__(self, points=100, title="Series title", xname="x-axis name", yname="y-axis name"):
34 """Set up an object to store a 2D data series""" 39 """Set up an object to store a 2D data series"""
@@ -70,6 +75,7 @@ class Plot(pyglet.window.Window): @@ -70,6 +75,7 @@ class Plot(pyglet.window.Window):
70 """Handle a resize event from the pyglet event loop""" 75 """Handle a resize event from the pyglet event loop"""
71 self.bounds = ((int(self.width * self.margins[0]), int(self.width * (1 - self.margins[0]))), 76 self.bounds = ((int(self.width * self.margins[0]), int(self.width * (1 - self.margins[0]))),
72 (int(self.height * self.margins[1]), int(self.height * (1 - self.margins[1])))) 77 (int(self.height * self.margins[1]), int(self.height * (1 - self.margins[1]))))
  78 + self.tag_size = min(self.height*self.margins[1]*0.3,self.width*self.margins[0]*0.3)
73 # This sometimes seems to throw an error ('AttributeError: 'Plot' object has no attribute 'margins') when started for a second time from the same instance. Interesting. Causes the plot windows to freeze 79 # This sometimes seems to throw an error ('AttributeError: 'Plot' object has no attribute 'margins') when started for a second time from the same instance. Interesting. Causes the plot windows to freeze
74 pyglet.window.Window.on_resize(self, width, height) 80 pyglet.window.Window.on_resize(self, width, height)
75 81
@@ -114,11 +120,11 @@ class Plot(pyglet.window.Window): @@ -114,11 +120,11 @@ class Plot(pyglet.window.Window):
114 pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (pos, limita, pos, limitb)), 120 pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (pos, limita, pos, limitb)),
115 ('c3B', (0, 0, 0, 0, 0, 0))) 121 ('c3B', (0, 0, 0, 0, 0, 0)))
116 tag = pyglet.text.Label(tagtext, color=BLACK, 122 tag = pyglet.text.Label(tagtext, color=BLACK,
117 - font_name=self.font, font_size=self.height*self.margins[1]*0.3, 123 + font_name=self.font, font_size=self.tag_size,
118 x=pos, y=self.height*self.margins[1], 124 x=pos, y=self.height*self.margins[1],
119 anchor_x='left', anchor_y='top') 125 anchor_x='left', anchor_y='top')
120 axistitle = pyglet.text.Label(self.series.xname, color=BLACK, 126 axistitle = pyglet.text.Label(self.series.xname, color=BLACK,
121 - font_name=self.font, font_size=self.height*self.margins[1]*0.3, 127 + font_name=self.font, font_size=self.tag_size,
122 x=self.width/2, y=0, 128 x=self.width/2, y=0,
123 anchor_x='center', anchor_y='bottom') 129 anchor_x='center', anchor_y='bottom')
124 axistitle.draw() 130 axistitle.draw()
@@ -129,11 +135,11 @@ class Plot(pyglet.window.Window): @@ -129,11 +135,11 @@ class Plot(pyglet.window.Window):
129 pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (limita, pos, limitb, pos)), 135 pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (limita, pos, limitb, pos)),
130 ('c3B', (0, 0, 0, 0, 0, 0))) 136 ('c3B', (0, 0, 0, 0, 0, 0)))
131 tag = pyglet.text.Label(tagtext, color=BLACK, 137 tag = pyglet.text.Label(tagtext, color=BLACK,
132 - font_name=self.font, font_size=self.width*self.margins[0]*0.2, 138 + font_name=self.font, font_size=self.tag_size,
133 x=self.width*self.margins[0]*0.9, y=pos, 139 x=self.width*self.margins[0]*0.9, y=pos,
134 anchor_x='right', anchor_y='center') 140 anchor_x='right', anchor_y='center')
135 axistitle = pyglet.text.Label(self.series.yname, color=BLACK, 141 axistitle = pyglet.text.Label(self.series.yname, color=BLACK,
136 - font_name=self.font, font_size=self.height*self.margins[0]*0.3, 142 + font_name=self.font, font_size=self.tag_size,
137 x=0, y=self.height/2, 143 x=0, y=self.height/2,
138 anchor_x='center', anchor_y='top') 144 anchor_x='center', anchor_y='top')
139 pyglet.gl.glPushMatrix() # Set up a new context to avoid confusing the main one 145 pyglet.gl.glPushMatrix() # Set up a new context to avoid confusing the main one