Newer
Older
Bucknell, Mary S.
committed
import {Actions} from 'ml/store/daily-value-time-series';
Bucknell, Mary S.
committed
import {
getAvailableGWDVTimeSeries,
getAvailableGWDVTimeSeriesIdsForParameterCode
Bucknell, Mary S.
committed
} from 'ml/selectors/daily-value-time-series-selector';
/*
* Draw the parameter code toggle for the daily values time series graph.
* @param {Object} elem - D3 selection
* @param {Object} store - Redux Store
*/
Bucknell, Mary S.
committed
const drawDVTimeSeriesSelection = function(container, store, monitoringLocationId, initialParameterCode) {
Bucknell, Mary S.
committed
const availableTimeSeries = getAvailableGWDVTimeSeries(store.getState());
const availableParameterCodes = new Set(availableTimeSeries.map(ts => ts.parameterCode));
Bucknell, Mary S.
committed
if (availableParameterCodes.size > 1) {
container.append('div').append('legend')
Bucknell, Mary S.
committed
.attr('class', 'usa-legend')
.text('Parameter codes:');
Bucknell, Mary S.
committed
Array.from(availableParameterCodes).forEach((parameterCode) => {
Bucknell, Mary S.
committed
const inputId = `code-${parameterCode}-radio`;
const inputContainer = container.append('div')
.attr('class', 'usa-radio');
inputContainer.append('input')
.attr('class', 'usa-radio__input')
.attr('id', inputId)
Bucknell, Mary S.
committed
.attr('name', 'parameter-code-selector')
Bucknell, Mary S.
committed
.attr('value', parameterCode)
.attr('checked', initialParameterCode === parameterCode ? true : null)
Bucknell, Mary S.
committed
.on('click', function() {
Bucknell, Mary S.
committed
const timeSeries = getAvailableGWDVTimeSeriesIdsForParameterCode(parameterCode)(store.getState());
store.dispatch(Actions.retrieveDVTimeSeries(monitoringLocationId, timeSeries.min));
store.dispatch(Actions.retrieveDVTimeSeries(monitoringLocationId, timeSeries.mean));
store.dispatch(Actions.retrieveDVTimeSeries(monitoringLocationId, timeSeries.max));
store.dispatch(Actions.setCurrentDVTimeSeriesIds(timeSeries.min, timeSeries.mean, timeSeries.max));
Bucknell, Mary S.
committed
inputContainer.append('label')
.attr('class', 'usa-radio__label')
.attr('for', inputId)
.text(parameterCode);
* Create the parameter code toggle for the daily values time series graph.
* @param {Object} elem - D3 selection
* @param {Object} store - Redux Store
Bucknell, Mary S.
committed
* @param {String} monitoringLocationId - Generally of form agency_cd-siteno
Bucknell, Mary S.
committed
export const drawGraphControls = function(elem, store, monitoringLocationId, initialParameterCode) {
elem.append('div')
.attr('id', 'dv-parameter-code-toggle')
Bucknell, Mary S.
committed
.call(drawDVTimeSeriesSelection, store, monitoringLocationId, initialParameterCode);