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

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

Update graphs controllers and views.

parent f33fc97b
...@@ -2,12 +2,10 @@ ...@@ -2,12 +2,10 @@
""" """
import base64 import base64
import matplotlib import io
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import os
from matplotlib.figure import Figure
from gluon import current from gluon import current
from gluon.storage import Storage from gluon.storage import Storage
from graph_tools import (FROM_TO, from graph_tools import (FROM_TO,
...@@ -17,10 +15,6 @@ from graph_tools import (FROM_TO, ...@@ -17,10 +15,6 @@ from graph_tools import (FROM_TO,
savefig, savefig,
stackchart) stackchart)
from model_selector import YEAR_SUBMIT from model_selector import YEAR_SUBMIT
from uuid import uuid4
mplstyle()
def dashboard(): def dashboard():
...@@ -43,8 +37,10 @@ def dashboard(): ...@@ -43,8 +37,10 @@ def dashboard():
selector.Graph_selectorYear_start = "" selector.Graph_selectorYear_start = ""
selector.Graph_selectorYear_end = "" selector.Graph_selectorYear_end = ""
# figure layout # figure layout and style
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, sharey=True) mplstyle()
fig = Figure()
ax1, ax2 = fig.subplots(nrows=1, ncols=2, sharey=True)
# the number of publications per year except for the current year # the number of publications per year except for the current year
# the starting value is defined in the preferences of the application # the starting value is defined in the preferences of the application
...@@ -77,8 +73,12 @@ def dashboard(): ...@@ -77,8 +73,12 @@ def dashboard():
linechart(db, selector, target=ax2, title=title) linechart(db, selector, target=ax2, title=title)
# delegate the rendering to the view # delegate the rendering to the view
buf = io.BytesIO()
fig.savefig(buf, format="svg")
data = base64.b64encode(buf.getbuffer()).decode("ascii")
response.view = "graphs/index.html" response.view = "graphs/index.html"
return dict(data=savefig(fig, "svg")) return dict(data=data)
def publications_versus_time(): def publications_versus_time():
...@@ -91,19 +91,24 @@ def publications_versus_time(): ...@@ -91,19 +91,24 @@ def publications_versus_time():
graph = db.graphs[selector.Graph_selectorId_graphs] graph = db.graphs[selector.Graph_selectorId_graphs]
axis = graph.stack_axis axis = graph.stack_axis
# instantiate the graph # figure and style
ax = (stackchart(db, selector) if axis else linechart(db, selector)) mplstyle()
fig = ax.get_figure() fig = Figure()
ax = fig.subplots(nrows=1, ncols=1)
# create the plot
if axis:
stackchart(db, selector, target=ax)
else:
linechart(db, selector, target=ax)
# delegate the rendering to the view # delegate the rendering to the view
extension = request.extension extension = request.extension
fmt = ("svg" if extension == "html" else extension) fmt = ("svg" if extension == "html" else extension)
# base64 string encoding buf = io.BytesIO()
data = savefig(fig, fmt) fig.savefig(buf, format=fmt)
if fmt in ("pdf", "png"): data = base64.b64encode(buf.getbuffer()).decode("ascii")
data = base64.b64encode(data)
data = data.decode("ascii")
response.view = "graphs/index.%s" % extension response.view = "graphs/index.%s" % extension
return dict(data=data) return dict(data=data)
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
data = urllib.parse.quote(data) data = urllib.parse.quote(data)
}} }}
<img src="data:image/svg+xml;utf8,{{=data}}" height=400></img> <img src="data:image/svg+xml;base64,{{=data}}" height=400></img>
{{ {{
from datetime import datetime from datetime import datetime
......
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