Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
limbra
limbra
Commits
d08b6615
Commit
d08b6615
authored
Nov 13, 2019
by
LE GAC Renaud
Browse files
Update graphs controllers and views.
parent
f33fc97b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
20 deletions
+25
-20
controllers/graphs.py
controllers/graphs.py
+24
-19
views/graphs/index.html
views/graphs/index.html
+1
-1
No files found.
controllers/graphs.py
View file @
d08b6615
...
...
@@ -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
)
views/graphs/index.html
View file @
d08b6615
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment