Commit fb361c97 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add logic to save graph in pdf or png format.

parent f56eec5a
......@@ -294,13 +294,33 @@ class Graph(BaseReport):
ax.tick_params(which='minor', length=4)
def _savefig(self, format):
"""Save the figure as a string.
@type format: str
@param format: possible values are pdf, png and svg.
"""
fig = self.ax.get_figure()
fi = StringIO()
fig.savefig(fi, format=format)
data = fi.getvalue()
fi.close()
fig.clear()
matplotlib.pyplot.close(fig)
return data
def to_pdf(self):
"""
@rtype: string
@return: encode the graph with the PDF format.
"""
return self._savefig('pdf')
def to_png(self):
"""
......@@ -308,7 +328,8 @@ class Graph(BaseReport):
@return: encode the graph with the PNG format.
"""
return self._savefig('png')
def to_svg(self):
"""
......@@ -316,17 +337,7 @@ class Graph(BaseReport):
@return: encode the graph with the SVG format.
"""
fig = self.ax.get_figure()
fi = StringIO()
fig.savefig(fi, format='svg')
data = fi.getvalue()
fi.close()
fig.clear()
matplotlib.pyplot.close(fig)
return data
return self._savefig('svg')
class List(BaseReport):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment