Commit cad30d6c9a94ad51e9f4fd9300d39322bc30d053
1 parent
9159742e
Exists in
master
Progress towards drawing graph axes
Showing
1 changed file
with
14 additions
and
2 deletions
Show diff stats
telemetry/code/monitor/graph_plotter_rewrite.py
| ... | ... | @@ -28,17 +28,21 @@ class Series: |
| 28 | 28 | if len(self.data) > self.points: |
| 29 | 29 | del self.points[-1] |
| 30 | 30 | |
| 31 | -class Plot: | |
| 31 | +class Plot(): | |
| 32 | 32 | def __init__(self, series, size=(640, 480)): |
| 33 | 33 | """Setup a the details of a plot, and create a corresponding window""" |
| 34 | 34 | self.series = series |
| 35 | 35 | self.title = self.series.title |
| 36 | 36 | self.size = size |
| 37 | 37 | self.font = 'Arkhip' |
| 38 | + self.margins = (0.02, 0.02) # Fractions of window size | |
| 39 | + self.lines = (12, 8) | |
| 38 | 40 | self.window = pyglet.window.Window(self.size[0], self.size[1], resizable=True) |
| 39 | 41 | self.window.set_caption(self.title) |
| 40 | 42 | self.window.on_resize = self.resize |
| 41 | 43 | self.window.on_draw = self.draw |
| 44 | + self.bounds = ((int(self.window.width * self.margins[0]), int(self.window.width * (1 - self.margins[0]))), | |
| 45 | + (int(self.window.height * self.margins[1]), int(self.window.height * (1 - self.margins[1])))) | |
| 42 | 46 | |
| 43 | 47 | def resize(self, width, height): |
| 44 | 48 | """Handle a pyglet resize event, then give control back to the event loop""" |
| ... | ... | @@ -49,6 +53,7 @@ class Plot: |
| 49 | 53 | """Draw all the components of the graph""" |
| 50 | 54 | self.drawBackground() |
| 51 | 55 | self.drawHeading() |
| 56 | + self.drawXAxis() | |
| 52 | 57 | |
| 53 | 58 | def drawBackground(self): |
| 54 | 59 | """Draw the graph background, currently a plain colour""" |
| ... | ... | @@ -57,9 +62,16 @@ class Plot: |
| 57 | 62 | def drawHeading(self): |
| 58 | 63 | """Draw a title for the graph (duplicated in the window titlebar, if present""" |
| 59 | 64 | heading = pyglet.text.Label(self.title, color=BLACK, |
| 60 | - font_name=self.font, font_size=self.size[0]/50, x=self.size[0]/2, y=self.size[1], | |
| 65 | + font_name=self.font, font_size=self.size[0]*self.margins[0], x=self.size[0]/2, y=self.size[1], | |
| 61 | 66 | anchor_x='center', anchor_y='top') |
| 62 | 67 | heading.draw() |
| 68 | + | |
| 69 | + def drawXAxis(self): | |
| 70 | + pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (self.bounds[0][0], self.bounds[1][0], | |
| 71 | + self.bounds[1][0], self.bounds[1][1])), | |
| 72 | + ('c3B', (0, 0, 0, 0, 0, 0))) | |
| 73 | + | |
| 74 | + | |
| 63 | 75 | |
| 64 | 76 | testseries = Series() |
| 65 | 77 | ... | ... |