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 29 easygui.msgbox("Failed to open serial port for unknown reason!", "Fatal error")
30 30 sys.exit()
31 31  
  32 +if platform.system()=='Windows': #easier than passing vars
  33 + os='Windows'
  34 +else:
  35 + os='Other'
  36 +
32 37 class Series:
33 38 def __init__(self, points=100, title="Series title", xname="x-axis name", yname="y-axis name"):
34 39 """Set up an object to store a 2D data series"""
... ... @@ -70,6 +75,7 @@ class Plot(pyglet.window.Window):
70 75 """Handle a resize event from the pyglet event loop"""
71 76 self.bounds = ((int(self.width * self.margins[0]), int(self.width * (1 - self.margins[0]))),
72 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 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 80 pyglet.window.Window.on_resize(self, width, height)
75 81  
... ... @@ -114,11 +120,11 @@ class Plot(pyglet.window.Window):
114 120 pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (pos, limita, pos, limitb)),
115 121 ('c3B', (0, 0, 0, 0, 0, 0)))
116 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 124 x=pos, y=self.height*self.margins[1],
119 125 anchor_x='left', anchor_y='top')
120 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 128 x=self.width/2, y=0,
123 129 anchor_x='center', anchor_y='bottom')
124 130 axistitle.draw()
... ... @@ -129,11 +135,11 @@ class Plot(pyglet.window.Window):
129 135 pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (limita, pos, limitb, pos)),
130 136 ('c3B', (0, 0, 0, 0, 0, 0)))
131 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 139 x=self.width*self.margins[0]*0.9, y=pos,
134 140 anchor_x='right', anchor_y='center')
135 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 143 x=0, y=self.height/2,
138 144 anchor_x='center', anchor_y='top')
139 145 pyglet.gl.glPushMatrix() # Set up a new context to avoid confusing the main one
... ...