Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Commit 28792d07 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Restore graph functionalities.

parent f87a693f
......@@ -5,6 +5,8 @@ import base64
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import os
from gluon import current
from gluon.storage import Storage
......@@ -15,6 +17,7 @@ from graph_tools import (FROM_TO,
savefig,
stackchart)
from model_selector import YEAR_SUBMIT
from uuid import uuid4
mplstyle()
......@@ -90,15 +93,17 @@ def publications_versus_time():
# instantiate the graph
ax = (stackchart(db, selector) if axis else linechart(db, selector))
fig = ax.get_figure()
# delegate the rendering to the view
extension = request.extension
fmt = "svg" if extension == "html" else extension
fmt = ("svg" if extension == "html" else extension)
# base64 string encoding
data = savefig(ax.get_figure(), fmt)
data = savefig(fig, fmt)
if fmt in ("pdf", "png"):
data = base64.b64encode(data)
data = data.decode("ascii")
response.view = "graphs/index.%s" % extension
return dict(data=data)
......@@ -3,6 +3,7 @@
"""
import matplotlib as mpl
import pandas as pd
import tempfile
from gluon import current
......@@ -387,10 +388,19 @@ def savefig(fig, fmt):
str:
"""
fi = StringIO()
fig.savefig(fi, format=fmt)
data = fi.getvalue()
fi.close()
if fmt == "svg":
fi = StringIO()
fig.savefig(fi, format=fmt)
data = fi.getvalue()
fi.close()
else:
fi = tempfile.TemporaryFile()
fig.savefig(fi, format=fmt)
fi.seek(0)
data = fi.read()
fi.close()
fig.clear()
mpl.pyplot.close(fig)
......
......@@ -5,10 +5,10 @@
# - data (string)
#
#--------------------------------------------------------------------------
import urllib
import urllib.parse
# encode special charactier bo be used in the image URI
data = urllib.quote(data)
data = urllib.parse.quote(data)
}}
<img src="data:image/svg+xml;utf8,{{=data}}" height=400></img>
......
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