Commit 4cab8d4cc85f41dae36eee7c6a0b579ca5ec29c8

Authored by Christopher Stone
1 parent 3ce449c7
Exists in master

work towards drawing axes better, not working yet

Showing 1 changed file with 25 additions and 26 deletions   Show diff stats
telemetry/code/monitor/graph_plotter_rewrite.py
@@ -49,8 +49,8 @@ class Plot(pyglet.window.Window): @@ -49,8 +49,8 @@ class Plot(pyglet.window.Window):
49 """Draw all the components of the graph""" 49 """Draw all the components of the graph"""
50 self.drawBackground() 50 self.drawBackground()
51 self.drawHeading() 51 self.drawHeading()
52 - self.drawXAxis()  
53 - self.drawYAxis() 52 + self.drawAxis(0)
  53 + self.drawAxis(1)
54 54
55 def drawBackground(self): 55 def drawBackground(self):
56 """Draw the graph background, currently a plain colour""" 56 """Draw the graph background, currently a plain colour"""
@@ -63,38 +63,37 @@ class Plot(pyglet.window.Window): @@ -63,38 +63,37 @@ class Plot(pyglet.window.Window):
63 anchor_x='center', anchor_y='top') 63 anchor_x='center', anchor_y='top')
64 heading.draw() 64 heading.draw()
65 65
66 - def drawXAxis(self):  
67 - top = self.bounds[1][1]  
68 - bot = self.bounds[1][0]  
69 - start = self.bounds[0][0]  
70 - stop = self.bounds[0][1]  
71 - increment = float(stop-start)/self.lines[0]  
72 - for x in numpy.arange(start, stop+1, increment): 66 + def drawAxis(self, axis): # axis=0 is x, 1 is y
  67 + limita = self.bounds[axis][1]
  68 + limitb = self.bounds[axis][0]
  69 + start = self.bounds[1-axis][0]
  70 + stop = self.bounds[1-axis][1]
  71 + increment = float(stop-start)/self.lines[axis]
  72 + for pos in numpy.arange(start, stop+1, increment):
73 # Using fp arithmetic to avoid intermittent fencepost errors 73 # Using fp arithmetic to avoid intermittent fencepost errors
74 - x = int(x)  
75 - pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (x, top, x, bot)), 74 + pos = int(pos)
  75 + if axis==0:
  76 + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (limita, pos, limitb, pos)),
76 ('c3B', (0, 0, 0, 0, 0, 0))) 77 ('c3B', (0, 0, 0, 0, 0, 0)))
77 - tag = pyglet.text.Label("123", color=BLACK,  
78 - font_name=self.font, font_size=self.height*self.margins[0]*0.3,  
79 - x=x, y=self.height*self.margins[0],  
80 - anchor_x='center', anchor_y='top') 78 + tag = pyglet.text.Label("123", color=BLACK,
  79 + font_name=self.font, font_size=self.height*self.margins[1-axis]*0.3,
  80 + x=pos, y=self.height*self.margins[axis],
  81 + anchor_x='left', anchor_y='top')
  82 + if axis==1:
  83 + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (pos, limita, pos, limitb)),
  84 + ('c3B', (0, 0, 0, 0, 0, 0)))
  85 + tag = pyglet.text.Label("123", color=BLACK,
  86 + font_name=self.font, font_size=self.width*self.margins[1-axis]*0.3,
  87 + x=self.width*self.margins[axis], y=pos,
  88 + anchor_x='right', anchor_y='center')
  89 +
81 tag.draw() 90 tag.draw()
82 axistitle = pyglet.text.Label(self.series.xname, color=BLACK, 91 axistitle = pyglet.text.Label(self.series.xname, color=BLACK,
83 font_name=self.font, font_size=self.height*self.margins[0]*0.3, x=self.width/2, y=0, 92 font_name=self.font, font_size=self.height*self.margins[0]*0.3, x=self.width/2, y=0,
84 anchor_x='center', anchor_y='bottom') 93 anchor_x='center', anchor_y='bottom')
85 axistitle.draw() 94 axistitle.draw()
86 95
87 - def drawYAxis(self):  
88 - lef = self.bounds[0][0]  
89 - rig = self.bounds[0][1]  
90 - start = self.bounds[1][0]  
91 - stop = self.bounds[1][1]  
92 - increment = float(stop-start)/self.lines[1]  
93 - for y in numpy.arange(start, stop+1, increment):  
94 - # Using fp arithmetic to avoid intermittent fencepost errors  
95 - y = int(y)  
96 - pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (lef, y, rig, y)),  
97 - ('c3B', (0, 0, 0, 0, 0, 0))) 96 +
98 97
99 98
100 99