Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
visualizer-embed
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Owen Graham
visualizer-embed
Commits
40a8f351
Verified
Commit
40a8f351
authored
3 years ago
by
Owen Graham
Browse files
Options
Downloads
Patches
Plain Diff
Use the same routes for all pages and plots
parent
97843dba
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
templates/boxplot.html
+2
-2
2 additions, 2 deletions
templates/boxplot.html
templates/index.html
+2
-2
2 additions, 2 deletions
templates/index.html
templates/overlay.html
+2
-2
2 additions, 2 deletions
templates/overlay.html
visualizer.py
+41
-28
41 additions, 28 deletions
visualizer.py
with
47 additions
and
34 deletions
templates/boxplot.html
+
2
−
2
View file @
40a8f351
...
...
@@ -33,11 +33,11 @@
</div>
<div>
<input
type=
"checkbox"
id=
"check-overlay"
onclick=
"location.href = '{{ url_for('overlay') }}';"
>
<input
type=
"checkbox"
id=
"check-overlay"
onclick=
"location.href = '{{ url_for('
page', plot_name='
overlay') }}';"
>
<label
for=
"check-overlay"
>
Overlay second dataset
</label>
</div>
<div>
<input
type=
"checkbox"
id=
"check-boxplot"
checked
onclick=
"location.href = '{{ url_for('
home
') }}';"
>
<input
type=
"checkbox"
id=
"check-boxplot"
checked
onclick=
"location.href = '{{ url_for('
page', plot_name='index
') }}';"
>
<label
for=
"check-boxplot"
>
Boxplot multiple years
</label>
</div>
</div>
...
...
This diff is collapsed.
Click to expand it.
templates/index.html
+
2
−
2
View file @
40a8f351
...
...
@@ -28,11 +28,11 @@
</div>
<div>
<input
type=
"checkbox"
id=
"check-overlay"
onclick=
"location.href = '{{ url_for('overlay') }}';"
>
<input
type=
"checkbox"
id=
"check-overlay"
onclick=
"location.href = '{{ url_for('
page', plot_name='
overlay') }}';"
>
<label
for=
"check-overlay"
>
Overlay second dataset
</label>
</div>
<div>
<input
type=
"checkbox"
id=
"check-boxplot"
onclick=
"location.href = '{{ url_for('boxplot') }}';"
>
<input
type=
"checkbox"
id=
"check-boxplot"
onclick=
"location.href = '{{ url_for('
page', plot_name='
boxplot') }}';"
>
<label
for=
"check-boxplot"
>
Boxplot multiple years
</label>
</div>
</div>
...
...
This diff is collapsed.
Click to expand it.
templates/overlay.html
+
2
−
2
View file @
40a8f351
...
...
@@ -28,11 +28,11 @@
</div>
<div>
<input
type=
"checkbox"
id=
"check-overlay"
checked
onclick=
"location.href = '{{ url_for('
home
') }}';"
>
<input
type=
"checkbox"
id=
"check-overlay"
checked
onclick=
"location.href = '{{ url_for('
page', plot_name='index
') }}';"
>
<label
for=
"check-overlay"
>
Overlay second dataset
</label>
</div>
<div>
<input
type=
"checkbox"
id=
"check-boxplot"
onclick=
"location.href = '{{ url_for('boxplot') }}';"
>
<input
type=
"checkbox"
id=
"check-boxplot"
onclick=
"location.href = '{{ url_for('
page', plot_name='
boxplot') }}';"
>
<label
for=
"check-boxplot"
>
Boxplot multiple years
</label>
</div>
...
...
This diff is collapsed.
Click to expand it.
visualizer.py
+
41
−
28
View file @
40a8f351
...
...
@@ -35,22 +35,23 @@ plt.rcParams['axes.xmargin'] = 0
matplotlib
.
use
(
'
Agg
'
)
@app.route
(
'
/
'
)
def
home
():
populate_g
()
return
render_template
(
'
index.html
'
)
@app.route
(
'
/
'
,
defaults
=
{
'
plot_name
'
:
'
index
'
})
@app.route
(
'
/<plot_name>
'
)
def
page
(
plot_name
):
"""
Render a visualizer page.
"""
if
plot_name
not
in
plotters
:
abort
(
404
)
stations
=
read_stations
()
g
.
stations
=
stations
@app.route
(
'
/overlay
'
)
def
overlay
():
populate_g
()
return
render_template
(
'
overlay.html
'
)
def
id_years
(
station
):
years
=
[
record
[
'
year
'
]
for
record
in
station
[
'
records
'
]]
return
station
[
'
id
'
],
years
g
.
record_years
=
dict
(
map
(
id_years
,
stations
))
@app.route
(
'
/boxplot
'
)
def
boxplot
():
populate_g
()
return
render_template
(
'
boxplot.html
'
)
return
render_template
(
f
'
{
plot_name
}
.html
'
)
@app.route
(
'
/record/link
'
)
...
...
@@ -61,8 +62,32 @@ def record_link():
return
jsonify
(
get_link
(
station
,
year
))
@app.route
(
'
/plot
'
)
def
plot
():
@app.route
(
'
/plot
'
,
defaults
=
{
'
plot_name
'
:
'
index
'
})
@app.route
(
'
/plot/<plot_name>
'
)
def
plot
(
plot_name
):
"""
Create a data plot image.
"""
plotter
=
plotters
.
get
(
plot_name
)
if
plotter
is
None
:
abort
(
404
)
return
plotter
.
plot
()
Plotter
=
make_dataclass
(
'
Plotter
'
,
[
'
name
'
,
'
plot
'
])
plotters
=
{}
def
add_plotter
(
name
):
"""
Decorator to register a plot type.
"""
def
decorator
(
f
):
plotters
[
name
]
=
Plotter
(
name
,
f
)
return
f
return
decorator
@add_plotter
(
'
index
'
)
def
plot_index
():
"""
Plot one station/year/measurement.
"""
station_id
=
get_param
(
'
station
'
)
year
=
get_param
(
'
year
'
,
to
=
year_type
)
...
...
@@ -94,7 +119,7 @@ def plot():
return
savefig_response
(
fig
)
@a
pp.rou
te
(
'
/plot/
overlay
'
)
@a
dd_plot
te
r
(
'
overlay
'
)
def
plot_overlay
():
"""
Plot two station/years @ one measurement.
"""
num_datasets
=
2
...
...
@@ -152,7 +177,7 @@ def plot_overlay():
return
savefig_response
(
fig
)
@a
pp.rou
te
(
'
/plot/
boxplot
'
)
@a
dd_plot
te
r
(
'
boxplot
'
)
def
plot_boxplot
():
"""
Boxplot one station/measurement @ multiple years.
"""
station_id
=
get_param
(
'
station
'
)
...
...
@@ -240,18 +265,6 @@ def savefig_response(fig):
return
Response
(
buf
.
getvalue
(),
mimetype
=
'
image/png
'
)
def
populate_g
():
"""
Populate `g` with data for rendering page templates.
"""
stations
=
read_stations
()
g
.
stations
=
stations
def
id_years
(
station
):
years
=
[
record
[
'
year
'
]
for
record
in
station
[
'
records
'
]]
return
station
[
'
id
'
],
years
g
.
record_years
=
dict
(
map
(
id_years
,
stations
))
def
read_stations
():
"""
Read amrdcrecords.json.
"""
with
open
(
'
amrdcrecords.json
'
)
as
f
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment