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