| 1 | from .base import Renderer |
| 2 | |
| 3 | |
| 4 | class FakeRenderer(Renderer): |
| 5 | """ |
| 6 | Fake Renderer |
| 7 | |
| 8 | This is a fake renderer which simply outputs a text tree representing the |
| 9 | elements found in the plot(s). This is used in the unit tests for the |
| 10 | package. |
| 11 | |
| 12 | Below are the methods your renderer must implement. You are free to do |
| 13 | anything you wish within the renderer (i.e. build an XML or JSON |
| 14 | representation, call an external API, etc.) Here the renderer just |
| 15 | builds a simple string representation for testing purposes. |
| 16 | """ |
| 17 | def __init__(self): |
| 18 | self.output = "" |
| 19 | |
| 20 | def open_figure(self, fig, props): |
| 21 | self.output += "opening figure\n" |
| 22 | |
| 23 | def close_figure(self, fig): |
| 24 | self.output += "closing figure\n" |
| 25 | |
| 26 | def open_axes(self, ax, props): |
| 27 | self.output += " opening axes\n" |
| 28 | |
| 29 | def close_axes(self, ax): |
| 30 | self.output += " closing axes\n" |
| 31 | |
| 32 | def open_legend(self, legend, props): |
| 33 | self.output += " opening legend\n" |
| 34 | |
| 35 | def close_legend(self, legend): |
| 36 | self.output += " closing legend\n" |
| 37 | |
| 38 | def draw_text(self, text, position, coordinates, style, |
| 39 | text_type=None, mplobj=None): |
| 40 | self.output += " draw text '{0}' {1}\n".format(text, text_type) |
| 41 | |
| 42 | def draw_path(self, data, coordinates, pathcodes, style, |
| 43 | offset=None, offset_coordinates="data", mplobj=None): |
| 44 | self.output += " draw path with {0} vertices\n".format(data.shape[0]) |
| 45 | |
| 46 | def draw_image(self, imdata, extent, coordinates, style, mplobj=None): |
| 47 | self.output += " draw image of size {0}\n".format(len(imdata)) |
| 48 | |
| 49 | |
| 50 | class FullFakeRenderer(FakeRenderer): |
| 51 | """ |
| 52 | Renderer with the full complement of methods. |
| 53 | |
| 54 | When the following are left undefined, they will be implemented via |
| 55 | other methods in the class. They can be defined explicitly for |
| 56 | more efficient or specialized use within the renderer implementation. |
| 57 | """ |
| 58 | def draw_line(self, data, coordinates, style, label, mplobj=None): |
| 59 | self.output += " draw line with {0} points\n".format(data.shape[0]) |
| 60 | |
| 61 | def draw_markers(self, data, coordinates, style, label, mplobj=None): |
| 62 | self.output += " draw {0} markers\n".format(data.shape[0]) |
| 63 | |
| 64 | def draw_path_collection(self, paths, path_coordinates, path_transforms, |
| 65 | offsets, offset_coordinates, offset_order, |
| 66 | styles, mplobj=None): |
| 67 | self.output += (" draw path collection " |
| 68 | "with {0} offsets\n".format(offsets.shape[0])) |