Skip to content
Snippets Groups Projects
Verified Commit cbceb533 authored by Owen Graham's avatar Owen Graham
Browse files

Send years with HTML

parent c3f694d9
No related branches found
No related tags found
No related merge requests found
/**
* Known plottable years for each station.
*/
const fetchedYears = {};
/**
* Fetch year options and put them in one selector.
*/
function getYears(n) {
clearYears(n);
const station = selectVal(suffixID('station', n));
fetchYears(station, years => {
appendYears(years, n);
});
const years = recordYears[station];
appendYears(years, n);
}
/**
......@@ -21,10 +15,9 @@ function boxplotGetYears() {
clearYears(1);
clearYears(2);
const station = selectVal('station');
fetchYears(station, years => {
appendYears(years, 1);
appendYears(years, 2);
});
const years = recordYears[station];
appendYears(years, 1);
appendYears(years, 2);
}
/**
......@@ -51,22 +44,6 @@ function clearYears(n) {
yearSelect.options.length = 1;
}
/**
* Call `callback(years)` after fetching years for the given station.
*/
function fetchYears(station, callback) {
if (fetchedYears.hasOwnProperty(station)) {
callback(fetchedYears[station]);
} else {
fetch(`${$SCRIPT_ROOT}/record/years${paramString({station})}`)
.then(response => response.json())
.then(years => {
fetchedYears[station] = years;
callback(years);
});
}
}
function indexVisualize() {
const params = {
station: selectVal('station'),
......
......@@ -8,6 +8,7 @@
<link rel="stylesheet" href="https://amrdc.ssec.wisc.edu/wp-test/wp-content/themes/amrdc-theme/dist/fonts/uw160/fonts.css?ver=1.0.0">
<script>
const $SCRIPT_ROOT = {{ request.script_root | tojson }};
const recordYears = {{ g.record_years | tojson }};
</script>
<script defer src="{{ url_for('static', filename='script.js') }}"></script>
</head>
......
......@@ -106,14 +106,6 @@ def boxplot():
return render_template('boxplot.html')
@app.route('/record/years')
def record_years():
"""Return a list of years for the selected station."""
station = get_station(get_param('station'))
years = [i['year'] for i in station['records']]
return jsonify(years)
@app.route('/record/link')
def record_link():
"""Return the source link for the selected dataset."""
......@@ -303,7 +295,14 @@ def savefig_response(fig):
def populate_g():
"""Populate `g` with data for rendering page templates."""
g.stations = read_stations()
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():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment