Commit a1f7d7470fb7c758eca9f234c183cbadcd01c59a

Authored by Christopher Stone
1 parent 4cab8d4c
Exists in master

Improvements to layout code, still needs y-axis label rotating

Showing 1 changed file with 22 additions and 16 deletions   Show diff stats
telemetry/code/monitor/graph_plotter_rewrite.py
@@ -59,38 +59,44 @@ class Plot(pyglet.window.Window): @@ -59,38 +59,44 @@ class Plot(pyglet.window.Window):
59 def drawHeading(self): 59 def drawHeading(self):
60 """Draw a title for the graph (duplicated in the window titlebar, if present""" 60 """Draw a title for the graph (duplicated in the window titlebar, if present"""
61 heading = pyglet.text.Label(self.series.title, color=BLACK, 61 heading = pyglet.text.Label(self.series.title, color=BLACK,
62 - font_name=self.font, font_size=self.height*self.margins[0]*0.6, x=self.width/2, y=self.height, 62 + font_name=self.font, font_size=self.height*self.margins[0]*0.5,
  63 + x=self.width/2, y=self.height-(self.margins[1]),
63 anchor_x='center', anchor_y='top') 64 anchor_x='center', anchor_y='top')
64 heading.draw() 65 heading.draw()
65 66
66 def drawAxis(self, axis): # axis=0 is x, 1 is y 67 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] 68 + limita = self.bounds[1-axis][1]
  69 + limitb = self.bounds[1-axis][0]
  70 + start = self.bounds[axis][0]
  71 + stop = self.bounds[axis][1]
71 increment = float(stop-start)/self.lines[axis] 72 increment = float(stop-start)/self.lines[axis]
72 for pos in numpy.arange(start, stop+1, increment): 73 for pos in numpy.arange(start, stop+1, increment):
73 # Using fp arithmetic to avoid intermittent fencepost errors 74 # Using fp arithmetic to avoid intermittent fencepost errors
74 pos = int(pos) 75 pos = int(pos)
75 - if axis==0:  
76 - pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (limita, pos, limitb, pos)), 76 + if axis==0: # x axis, vertical lines
  77 + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (pos, limita, pos, limitb)),
77 ('c3B', (0, 0, 0, 0, 0, 0))) 78 ('c3B', (0, 0, 0, 0, 0, 0)))
78 tag = pyglet.text.Label("123", color=BLACK, 79 tag = pyglet.text.Label("123", color=BLACK,
79 - font_name=self.font, font_size=self.height*self.margins[1-axis]*0.3, 80 + font_name=self.font, font_size=self.height*self.margins[1-axis]*0.28,
80 x=pos, y=self.height*self.margins[axis], 81 x=pos, y=self.height*self.margins[axis],
81 anchor_x='left', anchor_y='top') 82 anchor_x='left', anchor_y='top')
82 - if axis==1:  
83 - pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (pos, limita, pos, limitb)), 83 + axistitle = pyglet.text.Label(self.series.xname, color=BLACK,
  84 + font_name=self.font, font_size=self.height*self.margins[axis]*0.3,
  85 + x=self.width/2, y=0,
  86 + anchor_x='center', anchor_y='bottom')
  87 + if axis==1: # y axis, horizontal lines
  88 + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (limita, pos, limitb, pos)),
84 ('c3B', (0, 0, 0, 0, 0, 0))) 89 ('c3B', (0, 0, 0, 0, 0, 0)))
85 tag = pyglet.text.Label("123", color=BLACK, 90 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, 91 + font_name=self.font, font_size=self.width*self.margins[axis]*0.22,
  92 + x=self.width*self.margins[1-axis]*0.9, y=pos,
88 anchor_x='right', anchor_y='center') 93 anchor_x='right', anchor_y='center')
89 - 94 + axistitle = pyglet.text.Label(self.series.yname, color=BLACK,
  95 + font_name=self.font, font_size=self.height*self.margins[axis]*0.3,
  96 + x=0, y=self.height/2,
  97 + anchor_x='left', anchor_y='center')
90 tag.draw() 98 tag.draw()
91 - axistitle = pyglet.text.Label(self.series.xname, color=BLACK,  
92 - font_name=self.font, font_size=self.height*self.margins[0]*0.3, x=self.width/2, y=0,  
93 - anchor_x='center', anchor_y='bottom') 99 +
94 axistitle.draw() 100 axistitle.draw()
95 101
96 102