Commit 654dbda955af418ae31e5e8ab97a8c09443e3e58

Authored by Hugo Stephens
1 parent 9f810b17
Exists in master

Resructured axes title and tag scaling

now axes titles and text scale at the same rate, to avoid the ugly situation of uneven overlaps.

May want to change scaling factors in the future so that titles are larger than lables, but that can be done easily.
robots/little_john/telemetry/code/monitor/graph_plotter_rewrite.py
@@ -129,6 +129,7 @@ class Plot(pyglet.window.Window): @@ -129,6 +129,7 @@ class Plot(pyglet.window.Window):
129 """Handle a resize event from the pyglet event loop""" 129 """Handle a resize event from the pyglet event loop"""
130 self.bounds = ((int(self.width * self.margins[0]), int(self.width * (1 - self.margins[0]))), 130 self.bounds = ((int(self.width * self.margins[0]), int(self.width * (1 - self.margins[0]))),
131 (int(self.height * self.margins[1]), int(self.height * (1 - self.margins[1])))) 131 (int(self.height * self.margins[1]), int(self.height * (1 - self.margins[1]))))
  132 + self.tag_size = min(self.height*self.margins[1]*0.3,self.width*self.margins[0]*0.3)
132 # 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 133 # 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
133 pyglet.window.Window.on_resize(self, width, height) 134 pyglet.window.Window.on_resize(self, width, height)
134 135
@@ -173,11 +174,11 @@ class Plot(pyglet.window.Window): @@ -173,11 +174,11 @@ class Plot(pyglet.window.Window):
173 pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (pos, limita, pos, limitb)), 174 pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (pos, limita, pos, limitb)),
174 ('c3B', (0, 0, 0, 0, 0, 0))) 175 ('c3B', (0, 0, 0, 0, 0, 0)))
175 tag = pyglet.text.Label(tagtext, color=BLACK, 176 tag = pyglet.text.Label(tagtext, color=BLACK,
176 - font_name=self.font, font_size=self.height*self.margins[1]*0.3, 177 + font_name=self.font, font_size=self.tag_size,
177 x=pos, y=self.height*self.margins[1], 178 x=pos, y=self.height*self.margins[1],
178 anchor_x='left', anchor_y='top') 179 anchor_x='left', anchor_y='top')
179 axistitle = pyglet.text.Label(self.series.xname, color=BLACK, 180 axistitle = pyglet.text.Label(self.series.xname, color=BLACK,
180 - font_name=self.font, font_size=self.height*self.margins[1]*0.3, 181 + font_name=self.font, font_size=self.tag_size,
181 x=self.width/2, y=0, 182 x=self.width/2, y=0,
182 anchor_x='center', anchor_y='bottom') 183 anchor_x='center', anchor_y='bottom')
183 axistitle.draw() 184 axistitle.draw()
@@ -188,11 +189,11 @@ class Plot(pyglet.window.Window): @@ -188,11 +189,11 @@ class Plot(pyglet.window.Window):
188 pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (limita, pos, limitb, pos)), 189 pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (limita, pos, limitb, pos)),
189 ('c3B', (0, 0, 0, 0, 0, 0))) 190 ('c3B', (0, 0, 0, 0, 0, 0)))
190 tag = pyglet.text.Label(tagtext, color=BLACK, 191 tag = pyglet.text.Label(tagtext, color=BLACK,
191 - font_name=self.font, font_size=self.width*self.margins[0]*0.2, 192 + font_name=self.font, font_size=self.tag_size,
192 x=self.width*self.margins[0]*0.9, y=pos, 193 x=self.width*self.margins[0]*0.9, y=pos,
193 anchor_x='right', anchor_y='center') 194 anchor_x='right', anchor_y='center')
194 axistitle = pyglet.text.Label(self.series.yname, color=BLACK, 195 axistitle = pyglet.text.Label(self.series.yname, color=BLACK,
195 - font_name=self.font, font_size=self.height*self.margins[0]*0.3, 196 + font_name=self.font, font_size=self.tag_size,
196 x=0, y=self.height/2, 197 x=0, y=self.height/2,
197 anchor_x='center', anchor_y='top') 198 anchor_x='center', anchor_y='top')
198 pyglet.gl.glPushMatrix() # Set up a new context to avoid confusing the main one 199 pyglet.gl.glPushMatrix() # Set up a new context to avoid confusing the main one