From 77cc49a2182be2e1645d23e2809cfac1bd117dd2 Mon Sep 17 00:00:00 2001 From: mbucknell <mbucknell@usgs.gov> Date: Tue, 21 Apr 2020 12:48:11 -0500 Subject: [PATCH] All components/hydrograph tests are passing --- .../scripts/components/hydrograph/audible.js | 2 +- .../src/scripts/components/hydrograph/axes.js | 6 +- .../scripts/components/hydrograph/cursor.js | 2 +- .../components/hydrograph/cursor.spec.js | 5 +- .../components/hydrograph/date-controls.js | 23 +-- .../hydrograph/date-controls.spec.js | 24 +-- .../hydrograph/drawing-data.spec.js | 2 +- .../components/hydrograph/graph-brush.js | 8 +- .../components/hydrograph/graph-brush.spec.js | 16 +- .../components/hydrograph/graph-controls.js | 6 +- .../hydrograph/graph-controls.spec.js | 24 +-- .../scripts/components/hydrograph/index.js | 21 +-- .../components/hydrograph/index.spec.js | 138 +++++++++--------- .../scripts/components/hydrograph/legend.js | 9 +- .../components/hydrograph/legend.spec.js | 36 +++-- .../components/hydrograph/method-picker.js | 4 +- .../hydrograph/method-picker.spec.js | 8 +- .../components/hydrograph/parameters.js | 4 +- .../components/hydrograph/parameters.spec.js | 24 +-- .../scripts/components/hydrograph/scales.js | 10 +- .../components/hydrograph/scales.spec.js | 38 ++--- .../hydrograph/time-series-graph.js | 4 +- .../hydrograph/time-series-graph.spec.js | 29 ++-- .../components/hydrograph/time-series.js | 2 +- .../components/hydrograph/time-series.spec.js | 42 +++--- .../scripts/components/hydrograph/tooltip.js | 8 +- .../components/hydrograph/tooltip.spec.js | 82 ++++++----- assets/src/scripts/index.spec.js | 5 +- assets/src/scripts/store/index.js | 8 +- .../instantaneous-value-time-series-data.js | 21 +++ ...stantaneous-value-time-series-data.spec.js | 29 ++++ .../instantaneous-value-time-series-state.js | 2 +- assets/src/scripts/url-params.js | 10 +- assets/src/scripts/url-params.spec.js | 47 +++--- 34 files changed, 381 insertions(+), 318 deletions(-) diff --git a/assets/src/scripts/components/hydrograph/audible.js b/assets/src/scripts/components/hydrograph/audible.js index 5fdb446b4..21754aea9 100644 --- a/assets/src/scripts/components/hydrograph/audible.js +++ b/assets/src/scripts/components/hydrograph/audible.js @@ -73,7 +73,7 @@ export const updateSound = function ({enabled, points}) { } }; -const audibleInterfaceOnSelector = state => state.timeSeriesState.audiblePlayId !== null; +const audibleInterfaceOnSelector = state => state.ivTimeSeriesState.audiblePlayId !== null; const audibleScaleSelector = createSelector( getMainYScale, diff --git a/assets/src/scripts/components/hydrograph/axes.js b/assets/src/scripts/components/hydrograph/axes.js index 3c9f97c75..4ab058efe 100644 --- a/assets/src/scripts/components/hydrograph/axes.js +++ b/assets/src/scripts/components/hydrograph/axes.js @@ -3,7 +3,7 @@ import memoize from 'fast-memoize'; import {createSelector} from 'reselect'; import {generateTimeTicks} from '../../d3-rendering/tick-marks'; -import {getCurrentDateRange, getCurrentParmCd} from '../../selectors/time-series-selector'; +import {getCurrentDateRangeKind, getCurrentParmCd} from '../../selectors/time-series-selector'; import {convertCelsiusToFahrenheit, convertFahrenheitToCelsius} from '../../utils'; import {getYTickDetails} from './domain'; @@ -77,7 +77,7 @@ export const createAxes = function(xScale, yScale, secondaryYScale, yTickSize, p export const getBrushXAxis = createSelector( getBrushXScale('current'), tsTimeZoneSelector, - getCurrentDateRange, + getCurrentDateRangeKind, (xScale, ianaTimeZone, period) => createXAxis(xScale, period, ianaTimeZone) ); @@ -93,7 +93,7 @@ export const getAxes = memoize(kind => createSelector( yLabelSelector, tsTimeZoneSelector, getCurrentParmCd, - getCurrentDateRange, + getCurrentDateRangeKind, secondaryYLabelSelector, (xScale, yScale, secondaryYScale, layout, plotYLabel, ianaTimeZone, parmCd, currentDateRange, plotSecondaryYLabel) => { return { diff --git a/assets/src/scripts/components/hydrograph/cursor.js b/assets/src/scripts/components/hydrograph/cursor.js index 5e0ee2e70..16108b050 100644 --- a/assets/src/scripts/components/hydrograph/cursor.js +++ b/assets/src/scripts/components/hydrograph/cursor.js @@ -12,7 +12,7 @@ import {isVisibleSelector} from './time-series'; export const cursorOffsetSelector = createSelector( getMainXScale('current'), - state => state.ivTimeSeriesState.currentIVGraphCursorOffset, + state => state.ivTimeSeriesState.ivGraphCursorOffset, (xScale, cursorOffset) => { // If cursorOffset is false, don't show it if (cursorOffset === false) { diff --git a/assets/src/scripts/components/hydrograph/cursor.spec.js b/assets/src/scripts/components/hydrograph/cursor.spec.js index 63989aabe..d70f6ad43 100644 --- a/assets/src/scripts/components/hydrograph/cursor.spec.js +++ b/assets/src/scripts/components/hydrograph/cursor.spec.js @@ -319,7 +319,7 @@ const TEST_STATE_ONE_VAR = { }, currentIVVariableID: '00060id', currentIVMethodID: 69928, - currentIVDateRange: 'P7D', + currentIVDateRangeKind: 'P7D', ivGraphCursorOffset: null }, ui: { @@ -331,7 +331,6 @@ const TEST_STATE_ONE_VAR = { describe('Cursor module', () => { describe('tsCursorPointsSelector', () => { - it('Should return last time with non-masked value if the cursor offset is null', function() { expect(tsCursorPointsSelector('compare')(TEST_STATE_ONE_VAR)).toEqual({ '69928:compare:P7D': { @@ -391,7 +390,7 @@ describe('Cursor module', () => { ...TEST_STATE_THREE_VARS.ivTimeSeriesState, currentIVVariableID: '45807140', currentIVMethodID: 69930, - cursorIVOffset: 29 * 60 * 1000 + ivGraphCursorOffset: 29 * 60 * 1000 } }; diff --git a/assets/src/scripts/components/hydrograph/date-controls.js b/assets/src/scripts/components/hydrograph/date-controls.js index 054053e82..f075e6063 100644 --- a/assets/src/scripts/components/hydrograph/date-controls.js +++ b/assets/src/scripts/components/hydrograph/date-controls.js @@ -7,11 +7,11 @@ import {drawLoadingIndicator} from '../../d3-rendering/loading-indicator'; import { isLoadingTS, hasAnyTimeSeries, - getCurrentDateRange, + getCurrentDateRangeKind, getCustomTimeRange} from '../../selectors/time-series-selector'; import {getIanaTimeZone} from '../../selectors/time-zone-selector'; -import {Actions} from '../../store'; - +import {Actions as ivTimeSeriesDataActions} from '../../store/instantaneous-value-time-series-data'; +import {Actions as ivTimeSeriesStateActions} from '../../store/instantaneous-value-time-series-state'; export const drawDateRangeControls = function(elem, store, siteno) { const DATE_RANGE = [{ @@ -29,9 +29,10 @@ export const drawDateRangeControls = function(elem, store, siteno) { ariaExpanded: false }]; - const initialDateRange = getCurrentDateRange(store.getState()); let initialCustomTimeRange; - if (initialDateRange === 'custom') { + const dateRangeKind = getCurrentDateRangeKind(store.getState()); + const isDateRangeKindCustom = dateRangeKind === 'custom'; + if (isDateRangeKindCustom === 'custom') { const customTimeRangeInMillis = getCustomTimeRange(store.getState()); const locationIanaTimeZone = getIanaTimeZone(store.getState()); initialCustomTimeRange = { @@ -53,7 +54,7 @@ export const drawDateRangeControls = function(elem, store, siteno) { .attr('role', 'customdate') .attr('class', 'usa-form') .attr('aria-label', 'Custom date specification') - .attr('hidden', initialDateRange !== 'custom' ? true : null); + .attr('hidden', isDateRangeKindCustom ? null: true); customDateContainer.append('label') .attr('for', 'date-input') @@ -132,11 +133,11 @@ export const drawDateRangeControls = function(elem, store, siteno) { customDateValidationContainer.attr('hidden', null); } else { customDateValidationContainer.attr('hidden', true); - store.dispatch(Actions.retrieveUserRequestedDataForDateRange( + store.dispatch(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange( siteno, userSpecifiedStart, userSpecifiedEnd - )).then(() => store.dispatch(Actions.clearHydrographBrushOffset())); + )).then(() => store.dispatch(ivTimeSeriesStateActions.clearHydrographBrushOffset())); } }); @@ -170,11 +171,11 @@ export const drawDateRangeControls = function(elem, store, siteno) { } else { li.select('input#custom-date-range').attr('aria-expanded', false); customDateContainer.attr('hidden', true); - store.dispatch(Actions.retrieveExtendedTimeSeries( + store.dispatch(ivTimeSeriesDataActions.retrieveExtendedIVTimeSeries( siteno, li.select('input:checked').attr('value') )).then(() => { - store.dispatch(Actions.clearHydrographBrushOffset()); + store.dispatch(ivTimeSeriesStateActions.clearHydrographBrushOffset()); }); } }); @@ -182,5 +183,5 @@ export const drawDateRangeControls = function(elem, store, siteno) { .attr('class', 'usa-radio__label') .attr('for', (d) => `${d.period}-input`) .text((d) => d.name); - li.select(`#${initialDateRange}-input`).property('checked', true); + li.select(`#${dateRangeKind}-input`).property('checked', true); }; \ No newline at end of file diff --git a/assets/src/scripts/components/hydrograph/date-controls.spec.js b/assets/src/scripts/components/hydrograph/date-controls.spec.js index 980b14bae..8db3ea1ab 100644 --- a/assets/src/scripts/components/hydrograph/date-controls.spec.js +++ b/assets/src/scripts/components/hydrograph/date-controls.spec.js @@ -1,11 +1,12 @@ import {select} from 'd3-selection'; -import {Actions, configureStore} from '../../store'; +import {configureStore} from '../../store'; +import {Actions as ivTimeSeriesDataActions} from '../../store/instantaneous-value-time-series-data'; import {drawDateRangeControls} from './date-controls'; const TEST_STATE = { - series: { + ivTimeSeriesData: { timeSeries: { '00010:current': { points: [{ @@ -133,16 +134,15 @@ const TEST_STATE = { } } }, - timeSeriesState: { - currentVariableID: '45807197', - currentDateRange: 'P7D', - requestedTimeRange: null, - showSeries: { + ivTimeSeriesState: { + currentIVVariableID: '45807197', + currentIVDateRangeKind: 'P7D', + showIVTimeSeries: { current: true, compare: true, median: true }, - loadingTSKeys: [] + loadingIVTSKeys: [] }, ui: { width: 400 @@ -175,12 +175,12 @@ describe('date-controls', () => { }); it('Expects to retrieve the extended time series when the radio buttons are change', () => { - spyOn(Actions, 'retrieveExtendedTimeSeries').and.callThrough(); + spyOn(ivTimeSeriesDataActions, 'retrieveExtendedIVTimeSeries').and.callThrough(); let lastRadio = select('#P1Y-input'); lastRadio.property('checked', true); lastRadio.dispatch('change'); - expect(Actions.retrieveExtendedTimeSeries).toHaveBeenCalledWith('12345678', 'P1Y'); + expect(ivTimeSeriesDataActions.retrieveExtendedIVTimeSeries).toHaveBeenCalledWith('12345678', 'P1Y'); }); it('Expects to show the date range form when the Custom radio is selected', () => { @@ -216,7 +216,7 @@ describe('date-controls', () => { }); it('Expects data to be retrieved if both custom start and end dates are provided', () => { - spyOn(Actions, 'retrieveUserRequestedDataForDateRange').and.callThrough(); + spyOn(ivTimeSeriesDataActions, 'retrieveUserRequestedIVDataForDateRange').and.callThrough(); select('#custom-start-date').property('value', '2063-04-03'); select('#custom-end-date').property('value', '2063-04-05'); @@ -226,7 +226,7 @@ describe('date-controls', () => { let customDateAlertDiv = select('#custom-date-alert-container'); expect(customDateAlertDiv.attr('hidden')).toBe('true'); - expect(Actions.retrieveUserRequestedDataForDateRange).toHaveBeenCalledWith( + expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).toHaveBeenCalledWith( '12345678', '2063-04-03', '2063-04-05' ); }); diff --git a/assets/src/scripts/components/hydrograph/drawing-data.spec.js b/assets/src/scripts/components/hydrograph/drawing-data.spec.js index bb0216b55..c2e95ce6a 100644 --- a/assets/src/scripts/components/hydrograph/drawing-data.spec.js +++ b/assets/src/scripts/components/hydrograph/drawing-data.spec.js @@ -873,7 +873,7 @@ describe('drawingData module', () => { ...testData, ivTimeSeriesState: { ...testData.ivTimeSeriesState, - showIVTimesSeries: { + showIVTimeSeries: { 'current': true, 'compare': true, 'median': false diff --git a/assets/src/scripts/components/hydrograph/graph-brush.js b/assets/src/scripts/components/hydrograph/graph-brush.js index e59f0414b..3465e5fdc 100644 --- a/assets/src/scripts/components/hydrograph/graph-brush.js +++ b/assets/src/scripts/components/hydrograph/graph-brush.js @@ -1,10 +1,10 @@ -import {brushX, brushSelection} from 'd3-brush'; +import {brushX} from 'd3-brush'; import {event} from 'd3-selection'; import {createStructuredSelector} from 'reselect'; import {appendXAxis} from '../../d3-rendering/axes'; import {link} from '../../lib/d3-redux'; -import {Actions} from '../../store'; +import {Actions} from '../../store/instantaneous-value-time-series-state'; import {getBrushXAxis} from './axes'; import {currentVariableLineSegmentsSelector} from './drawing-data'; @@ -29,7 +29,7 @@ export const drawGraphBrush = function(container, store) { const brushOffsets = [adjustedBrush[0]- xScale.domain()[0], xScale.domain()[1] - adjustedBrush[1]]; - store.dispatch(Actions.setHydrographBrushOffset(brushOffsets)); + store.dispatch(Actions.setIVGraphBrushOffset(brushOffsets)); } }; @@ -93,7 +93,7 @@ export const drawGraphBrush = function(container, store) { }, createStructuredSelector({ layout: getBrushLayout, - hydrographBrushOffset: (state) => state.timeSeriesState.hydrographBrushOffset, + hydrographBrushOffset: (state) => state.ivTimeSeriesState.ivGraphBrushOffset, xScale: getBrushXScale('current') }))); }; \ No newline at end of file diff --git a/assets/src/scripts/components/hydrograph/graph-brush.spec.js b/assets/src/scripts/components/hydrograph/graph-brush.spec.js index eb9769131..45a0a2c3e 100644 --- a/assets/src/scripts/components/hydrograph/graph-brush.spec.js +++ b/assets/src/scripts/components/hydrograph/graph-brush.spec.js @@ -7,7 +7,7 @@ import {drawGraphBrush} from './graph-brush'; describe ('graph-brush module', () => { const TEST_STATE = { - series: { + ivTimeSeriesData: { timeSeries: { '00010:current': { points: [{ @@ -135,20 +135,18 @@ describe ('graph-brush module', () => { } } }, - timeSeriesState: { - currentVariableID: '45807197', - currentDateRange: 'P7D', - requestedTimeRange: null, - showSeries: { + ivTimeSeriesState: { + currentIVVariableID: '45807197', + currentIVDateRangeKind: 'P7D', + showIVTimeSeries: { current: true, compare: true, median: true }, - loadingTSKeys: [] + loadingIVTSKeys: [] }, ui: { - width: 400, - hydrographBrushOffset: undefined + width: 400 } }; describe('drawGraphBrush', () => { diff --git a/assets/src/scripts/components/hydrograph/graph-controls.js b/assets/src/scripts/components/hydrograph/graph-controls.js index 6d616eebc..d4fd21ed8 100644 --- a/assets/src/scripts/components/hydrograph/graph-controls.js +++ b/assets/src/scripts/components/hydrograph/graph-controls.js @@ -1,7 +1,7 @@ import {link} from '../../lib/d3-redux'; import {getCurrentVariableTimeSeries} from '../../selectors/time-series-selector'; -import {Actions} from '../../store'; +import {Actions} from '../../store/instantaneous-value-time-series-state'; import {audibleUI} from './audible'; import {getCurrentVariableMedianStatistics} from '../../selectors/median-statistics-selector'; @@ -33,7 +33,7 @@ export const drawGraphControls = function(elem, store) { .attr('ga-event-category', 'TimeSeriesGraph') .attr('ga-event-action', 'toggleCompare') .on('click', function() { - store.dispatch(Actions.toggleTimeSeries('compare', this.checked)); + store.dispatch(Actions.setIVTimeSeriesVisibility('compare', this.checked)); }) // Disables the checkbox if no compare time series for the current variable .call(link(store,function(elem, compareTimeSeries) { @@ -63,7 +63,7 @@ export const drawGraphControls = function(elem, store) { .attr('ga-event-category', 'TimeSeriesGraph') .attr('ga-event-action', 'toggleMedian') .on('click', function() { - store.dispatch(Actions.toggleTimeSeries('median', this.checked)); + store.dispatch(Actions.setIVTimeSeriesVisibility('median', this.checked)); }) // Disables the checkbox if no median data for the current variable .call(link(store,function(elem, medianData) { diff --git a/assets/src/scripts/components/hydrograph/graph-controls.spec.js b/assets/src/scripts/components/hydrograph/graph-controls.spec.js index 2bbf1da2c..3579a3788 100644 --- a/assets/src/scripts/components/hydrograph/graph-controls.spec.js +++ b/assets/src/scripts/components/hydrograph/graph-controls.spec.js @@ -1,13 +1,14 @@ import {select} from 'd3-selection'; -import {Actions, configureStore} from '../../store'; +import {configureStore} from '../../store'; +import {Actions} from '../../store/instantaneous-value-time-series-state'; import {drawGraphControls} from './graph-controls'; // Tests for the graph-controls module describe('graph-controls', () => { const TEST_STATE = { - series: { + ivTimeSeriesData: { timeSeries: { '00010:current': { points: [{ @@ -135,16 +136,15 @@ describe('graph-controls', () => { } } }, - timeSeriesState: { - currentVariableID: '45807197', - currentDateRange: 'P7D', - requestedTimeRange: null, - showSeries: { + ivTimeSeriesState: { + currentIVVariableID: '45807197', + currentIVDateRangeKind: 'P7D', + showIVTimeSeries: { current: true, compare: true, median: true }, - loadingTSKeys: [] + loadingIVTSKeys: [] }, ui: { width: 400 @@ -174,7 +174,7 @@ describe('graph-controls', () => { }); it('Should render the compare toggle unchecked', (done) => { - store.dispatch(Actions.toggleTimeSeries('compare', false)); + store.dispatch(Actions.setIVTimeSeriesVisibility('compare', false)); window.requestAnimationFrame(() => { const checkbox = select('#last-year-checkbox'); expect(checkbox.size()).toBe(1); @@ -188,7 +188,7 @@ describe('graph-controls', () => { }); it('should be disabled if there are no last year data', (done) => { - store.dispatch(Actions.setCurrentVariable('45807190')); + store.dispatch(Actions.setCurrentIVVariable('45807190')); window.requestAnimationFrame(() => { expect(select('#last-year-checkbox').property('disabled')).toBeTruthy(); done(); @@ -203,7 +203,7 @@ describe('graph-controls', () => { }); it('Should render the median toggle unchecked', (done) => { - store.dispatch(Actions.toggleTimeSeries('median', false)); + store.dispatch(Actions.setIVTimeSeriesVisibility('median', false)); window.requestAnimationFrame(() => { const checkbox = select('#median-checkbox'); expect(checkbox.size()).toBe(1); @@ -217,7 +217,7 @@ describe('graph-controls', () => { }); it('should be disabled if there are no median statistics data', (done) => { - store.dispatch(Actions.setCurrentVariable('45807190')); + store.dispatch(Actions.setCurrentIVVariable('45807190')); window.requestAnimationFrame(() => { expect(select('#median-checkbox').property('disabled')).toBeTruthy(); done(); diff --git a/assets/src/scripts/components/hydrograph/index.js b/assets/src/scripts/components/hydrograph/index.js index e7dad1521..e51a0d767 100644 --- a/assets/src/scripts/components/hydrograph/index.js +++ b/assets/src/scripts/components/hydrograph/index.js @@ -9,7 +9,8 @@ import {drawWarningAlert, drawInfoAlert} from '../../d3-rendering/alerts'; import {link} from '../../lib/d3-redux'; import {hasAnyTimeSeries, getCurrentParmCd, getVariables} from '../../selectors/time-series-selector'; -import {Actions} from '../../store'; +import {Actions as ivTimeSeriesDataActions} from '../../store/instantaneous-value-time-series-data'; +import {Actions as ivTimeSeriesStateActions} from '../../store/instantaneous-value-time-series-state'; import {Actions as statisticsDataActions} from '../../store/statistics-data'; import {Actions as timeZoneActions} from '../../store/time-zone'; import {renderTimeSeriesUrlParams} from '../../url-params'; @@ -74,26 +75,26 @@ export const attachToNode = function (store, if (showOnlyGraph) { // Only fetch what is needed if (parameterCode && period) { - fetchDataPromise = store.dispatch(Actions.retrieveCustomTimePeriodTimeSeries(siteno, parameterCode, period)); + fetchDataPromise = store.dispatch(ivTimeSeriesDataActions.retrieveCustomTimePeriodIVTimeSeries(siteno, parameterCode, period)); } else if (parameterCode && startDT && endDT) { // Don't fetch until time zone is available fetchDataPromise = fetchTimeZonePromise.then(() => { - return store.dispatch(Actions.retrieveDataForDateRange(siteno, startDT, endDT, parameterCode)); + return store.dispatch(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange(siteno, startDT, endDT, parameterCode)); }); } else { - fetchDataPromise = store.dispatch(Actions.retrieveTimeSeries(siteno, parameterCode ? [parameterCode] : null)); + fetchDataPromise = store.dispatch(ivTimeSeriesDataActions.retrieveIVTimeSeries(siteno, parameterCode ? [parameterCode] : null)); } } else { // Retrieve all parameter codes for 7 days and median statistics - fetchDataPromise = store.dispatch(Actions.retrieveTimeSeries(siteno)) + fetchDataPromise = store.dispatch(ivTimeSeriesDataActions.retrieveIVTimeSeries(siteno)) .then(() => { // Fetch any extended data needed to set initial state const currentParamCode = parameterCode ? parameterCode : getCurrentParmCd(store.getState()); if (period === 'P30D' || period === 'P1Y') { - store.dispatch(Actions.retrieveExtendedTimeSeries(siteno, period, currentParamCode)); + store.dispatch(ivTimeSeriesDataActions.retrieveExtendedIVTimeSeries(siteno, period, currentParamCode)); } else if (startDT && endDT) { fetchTimeZonePromise.then(() => { - store.dispatch(Actions.retrieveDataForDateRange(siteno, startDT, endDT, currentParamCode)); + store.dispatch(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange(siteno, startDT, endDT, currentParamCode)); }); } }); @@ -113,13 +114,13 @@ export const attachToNode = function (store, return variable.variableCode.value === parameterCode; }; const thisVariable = Object.values(getVariables(store.getState())).find(isThisParamCode); - store.dispatch(Actions.setCurrentVariable(thisVariable.oid)); + store.dispatch(ivTimeSeriesStateActions.setCurrentIVVariable(thisVariable.oid)); } if (compare) { - store.dispatch(Actions.toggleTimeSeries('compare', true)); + store.dispatch(ivTimeSeriesStateActions.setIVTimeSeriesVisibility('compare', true)); } if (timeSeriesId) { - store.dispatch(Actions.setCurrentMethodID(timeSeriesId)); + store.dispatch(ivTimeSeriesStateActions.setCurrentIVMethodID(timeSeriesId)); } // Initial data has been fetched and initial state set. We can render the hydrograph elements // Set up rendering functions for the graph-container diff --git a/assets/src/scripts/components/hydrograph/index.spec.js b/assets/src/scripts/components/hydrograph/index.spec.js index 38081f9af..1f4685631 100644 --- a/assets/src/scripts/components/hydrograph/index.spec.js +++ b/assets/src/scripts/components/hydrograph/index.spec.js @@ -1,12 +1,13 @@ import {select, selectAll} from 'd3-selection'; import {attachToNode} from './index'; -import {Actions, configureStore} from '../../store'; +import {configureStore} from '../../store'; +import {Actions as ivTimeSeriesDataActions} from '../../store/instantaneous-value-time-series-data'; import {Actions as statisticsDataActions} from '../../store/statistics-data'; import {Actions as timeZoneActions} from '../../store/time-zone'; const TEST_STATE = { - series: { + ivTimeSeriesData: { timeSeries: { '00010:current': { points: [{ @@ -134,16 +135,15 @@ const TEST_STATE = { } } }, - timeSeriesState: { - currentVariableID: '45807197', - currentDateRange: 'P7D', - requestedTimeRange: null, - showSeries: { + ivTimeSeriesState: { + currentIVVariableID: '45807197', + currentIVDateRangeKind: 'P7D', + showIVTimeSeries: { current: true, compare: true, median: true }, - loadingTSKeys: [] + loadingIVTSKeys: [] }, ui: { width: 400 @@ -182,7 +182,11 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => { let store; beforeEach(() => { - store = configureStore({}); + store = configureStore({ + ivTimeSeriesState: { + loadingIVTSKeys: [] + } + }); }); it('loading-indicator is shown until initial data has been retrieved', () => { @@ -205,7 +209,7 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => { describe('Always retrieve the 7 day data and median statistics', () => { beforeEach(() => { - spyOn(Actions, 'retrieveTimeSeries').and.callThrough(); + spyOn(ivTimeSeriesDataActions, 'retrieveIVTimeSeries').and.callThrough(); spyOn(statisticsDataActions, 'retrieveMedianStatistics').and.callThrough(); }); @@ -215,7 +219,7 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => { parameterCode: '00065' }); - expect(Actions.retrieveTimeSeries).toHaveBeenCalledWith('12345678'); + expect(ivTimeSeriesDataActions.retrieveIVTimeSeries).toHaveBeenCalledWith('12345678'); expect(statisticsDataActions.retrieveMedianStatistics).toHaveBeenCalledWith('12345678'); }); @@ -226,7 +230,7 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => { period: 'P30D' }); - expect(Actions.retrieveTimeSeries).toHaveBeenCalledWith('12345678'); + expect(ivTimeSeriesDataActions.retrieveIVTimeSeries).toHaveBeenCalledWith('12345678'); expect(statisticsDataActions.retrieveMedianStatistics).toHaveBeenCalledWith('12345678'); }); @@ -238,18 +242,18 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => { endDT: '2010-03-01' }); - expect(Actions.retrieveTimeSeries).toHaveBeenCalledWith('12345678'); + expect(ivTimeSeriesDataActions.retrieveIVTimeSeries).toHaveBeenCalledWith('12345678'); expect(statisticsDataActions.retrieveMedianStatistics).toHaveBeenCalledWith('12345678'); }); }); describe('Retrieve additional data if indicated', () => { beforeEach(() => { - spyOn(Actions, 'retrieveTimeSeries').and.returnValue(function() { + spyOn(ivTimeSeriesDataActions, 'retrieveIVTimeSeries').and.returnValue(function() { return Promise.resolve({}); }); - spyOn(Actions, 'retrieveExtendedTimeSeries').and.callThrough(); - spyOn(Actions, 'retrieveDataForDateRange').and.callThrough(); + spyOn(ivTimeSeriesDataActions, 'retrieveExtendedIVTimeSeries').and.callThrough(); + spyOn(ivTimeSeriesDataActions, 'retrieveUserRequestedIVDataForDateRange').and.callThrough(); }); it('Expect to not retrieve additional time series if not indicated', (done) => { @@ -259,8 +263,8 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => { }); window.requestAnimationFrame(() => { - expect(Actions.retrieveExtendedTimeSeries).not.toHaveBeenCalled(); - expect(Actions.retrieveDataForDateRange).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveExtendedIVTimeSeries).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).not.toHaveBeenCalled(); done(); }); }); @@ -272,8 +276,8 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => { }); window.requestAnimationFrame(() => { - expect(Actions.retrieveExtendedTimeSeries).toHaveBeenCalledWith('12345678', 'P30D', '00065'); - expect(Actions.retrieveDataForDateRange).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveExtendedIVTimeSeries).toHaveBeenCalledWith('12345678', 'P30D', '00065'); + expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).not.toHaveBeenCalled(); done(); }); }); @@ -287,13 +291,13 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => { }); window.requestAnimationFrame(() => { - expect(Actions.retrieveExtendedTimeSeries).not. toHaveBeenCalled(); - expect(Actions.retrieveDataForDateRange).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveExtendedIVTimeSeries).not. toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).not.toHaveBeenCalled(); done(); }); }); - it('should retrieve data for date range if time zone has been fetched', (done) => { + it('should retrieve data for date range if time zone has been fetched', (done) => { spyOn(timeZoneActions, 'retrieveIanaTimeZone').and.returnValue(function() { return Promise.resolve({}); }); @@ -305,8 +309,8 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => { }); window.requestAnimationFrame(() => { - expect(Actions.retrieveExtendedTimeSeries).not. toHaveBeenCalled(); - expect(Actions.retrieveDataForDateRange).toHaveBeenCalledWith('12345678', '2010-01-01', '2010-03-01', '00065'); + expect(ivTimeSeriesDataActions.retrieveExtendedIVTimeSeries).not. toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).toHaveBeenCalledWith('12345678', '2010-01-01', '2010-03-01', '00065'); done(); }); }); @@ -317,10 +321,14 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => { let store; beforeEach(() => { - store = configureStore({}); - spyOn(Actions, 'retrieveTimeSeries').and.callThrough(); - spyOn(Actions, 'retrieveCustomTimePeriodTimeSeries').and.callThrough(); - spyOn(Actions, 'retrieveDataForDateRange'); + store = configureStore({ + ivTimeSeriesState: { + loadingIVTSKeys: [] + } + }); + spyOn(ivTimeSeriesDataActions, 'retrieveIVTimeSeries').and.callThrough(); + spyOn(ivTimeSeriesDataActions, 'retrieveCustomTimePeriodIVTimeSeries').and.callThrough(); + spyOn(ivTimeSeriesDataActions, 'retrieveUserRequestedIVDataForDateRange'); }); it('should retrieve custom time period if period is specificed', (done) => { @@ -332,9 +340,9 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => { }); window.requestAnimationFrame(() => { - expect(Actions.retrieveTimeSeries).not.toHaveBeenCalled(); - expect(Actions.retrieveCustomTimePeriodTimeSeries).toHaveBeenCalledWith('12345678', '00065', 'P20D'); - expect(Actions.retrieveDataForDateRange).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveIVTimeSeries).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveCustomTimePeriodIVTimeSeries).toHaveBeenCalledWith('12345678', '00065', 'P20D'); + expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).not.toHaveBeenCalled(); done(); }); }); @@ -349,9 +357,9 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => { }); window.requestAnimationFrame(() => { - expect(Actions.retrieveTimeSeries).not.toHaveBeenCalled(); - expect(Actions.retrieveCustomTimePeriodTimeSeries).not.toHaveBeenCalled(); - expect(Actions.retrieveDataForDateRange).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveIVTimeSeries).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveCustomTimePeriodIVTimeSeries).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).not.toHaveBeenCalled(); done(); }); }); @@ -369,9 +377,9 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => { }); window.requestAnimationFrame(() => { - expect(Actions.retrieveTimeSeries).not.toHaveBeenCalled(); - expect(Actions.retrieveCustomTimePeriodTimeSeries).not.toHaveBeenCalled(); - expect(Actions.retrieveDataForDateRange).toHaveBeenCalledWith('12345678', '2010-01-01', '2010-03-01', '00065'); + expect(ivTimeSeriesDataActions.retrieveIVTimeSeries).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveCustomTimePeriodIVTimeSeries).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).toHaveBeenCalledWith('12345678', '2010-01-01', '2010-03-01', '00065'); done(); }); }); @@ -384,9 +392,9 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => { }); window.requestAnimationFrame(() => { - expect(Actions.retrieveTimeSeries).toHaveBeenCalledWith('12345678', ['00065']); - expect(Actions.retrieveCustomTimePeriodTimeSeries).not.toHaveBeenCalled(); - expect(Actions.retrieveDataForDateRange).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveIVTimeSeries).toHaveBeenCalledWith('12345678', ['00065']); + expect(ivTimeSeriesDataActions.retrieveCustomTimePeriodIVTimeSeries).not.toHaveBeenCalled(); + expect(ivTimeSeriesDataActions.retrieveUserRequestedIVDataForDateRange).not.toHaveBeenCalled(); done(); }); }); @@ -396,17 +404,17 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => { /* eslint no-use-before-define: 0 */ let store; beforeEach((done) => { - spyOn(Actions, 'retrieveTimeSeries').and.returnValue(function() { + spyOn(ivTimeSeriesDataActions, 'retrieveIVTimeSeries').and.returnValue(function() { return Promise.resolve({}); }); store = configureStore({ ...TEST_STATE, - series: { - ...TEST_STATE.series, + ivTimeSeriesData: { + ...TEST_STATE.ivTimeSeriesData, timeSeries: { - ...TEST_STATE.series.timeSeries, + ...TEST_STATE.ivTimeSeriesData.timeSeries, '00060:current': { - ...TEST_STATE.series.timeSeries['00060:current'], + ...TEST_STATE.ivTimeSeriesData.timeSeries['00060:current'], startTime: 1514926800000, endTime: 1514930400000, points: [{ @@ -421,17 +429,17 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => { } } }, - timeSeriesState: { - showSeries: { + ivTimeSeriesState: { + showIVTimeSeries: { current: true, compare: true, median: true }, - currentVariableID: '45807197', - currentDateRange: 'P7D', - currentMethodID: 'method1', - loadingTSKeys: [], - hydrographBrushOffset: null + currentIVVariableID: '45807197', + currentIVDateRangeKind: 'P7D', + currentIVMethodID: 'method1', + loadingIVTSKeys: [], + ivGraphBrushOffset: null }, ui: { windowWidth: 400, @@ -508,17 +516,17 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => { describe('hide elements when showOnlyGraph is set to true', () => { let store; beforeEach(() => { - spyOn(Actions, 'retrieveTimeSeries').and.returnValue(function() { + spyOn(ivTimeSeriesDataActions, 'retrieveIVTimeSeries').and.returnValue(function() { return Promise.resolve({}); }); store = configureStore({ ...TEST_STATE, - series: { - ...TEST_STATE.series, + ivTimeSeriesData: { + ...TEST_STATE.ivTimeSeriesData, timeSeries: { - ...TEST_STATE.series.timeSeries, + ...TEST_STATE.ivTimeSeriesData.timeSeries, '00060:current': { - ...TEST_STATE.series.timeSeries['00060:current'], + ...TEST_STATE.ivTimeSeriesData.timeSeries['00060:current'], startTime: 1514926800000, endTime: 1514930400000, points: [{ @@ -533,17 +541,17 @@ describe('Hydrograph charting and Loading indicators and data alerts', () => { } } }, - timeSeriesState: { - showSeries: { + ivTimeSeriesState: { + showIVTimeSeries: { current: true, compare: true, median: true }, - currentVariableID: '45807197', - currentDateRange: 'P7D', - currentMethodID: 'method1', - loadingTSKeys: [], - hydrographBrushOffset: null + currentIVVariableID: '45807197', + currentIVDateRangeKind: 'P7D', + currentIVMethodID: 'method1', + loadingIVTSKeys: [], + ivGraphBrushOffset: null }, ui: { windowWidth: 400, diff --git a/assets/src/scripts/components/hydrograph/legend.js b/assets/src/scripts/components/hydrograph/legend.js index 9e2081af1..77dd1dd52 100644 --- a/assets/src/scripts/components/hydrograph/legend.js +++ b/assets/src/scripts/components/hydrograph/legend.js @@ -5,11 +5,12 @@ import {createSelector, createStructuredSelector} from 'reselect'; import {drawSimpleLegend} from '../../d3-rendering/legend'; import {defineLineMarker, defineTextOnlyMarker, defineRectangleMarker} from '../../d3-rendering/markers'; +import {link} from '../../lib/d3-redux'; +import {getCurrentVariableMedianMetadata} from '../../selectors/median-statistics-selector'; -import {getMainLayout} from './layout'; import {currentVariableLineSegmentsSelector, HASH_ID, MASK_DESC} from './drawing-data'; -import {getCurrentVariableMedianMetadata} from '../../selectors/median-statistics-selector'; -import {link} from '../../lib/d3-redux'; +import {getMainLayout} from './layout'; + const TS_LABEL = { 'current': 'Current: ', @@ -127,7 +128,7 @@ const uniqueClassesSelector = memoize(tsKey => createSelector( * Select attributes from the state useful for legend creation */ const legendDisplaySelector = createSelector( - (state) => state.timeSeriesState.showSeries, + (state) => state.ivTimeSeriesState.showIVTimeSeries, getCurrentVariableMedianMetadata, uniqueClassesSelector('current'), uniqueClassesSelector('compare'), diff --git a/assets/src/scripts/components/hydrograph/legend.spec.js b/assets/src/scripts/components/hydrograph/legend.spec.js index dea6bd059..46e622f1d 100644 --- a/assets/src/scripts/components/hydrograph/legend.spec.js +++ b/assets/src/scripts/components/hydrograph/legend.spec.js @@ -1,12 +1,16 @@ import {select, selectAll} from 'd3-selection'; -import {legendMarkerRowsSelector, drawTimeSeriesLegend} from './legend'; + import {lineMarker, rectangleMarker, textOnlyMarker} from '../../d3-rendering/markers'; -import {Actions, configureStore} from '../../store'; +import {configureStore} from '../../store'; +import {Actions} from '../../store/instantaneous-value-time-series-state'; + +import {legendMarkerRowsSelector, drawTimeSeriesLegend} from './legend'; + describe('UV: Legend module', () => { const TEST_DATA = { - series: { + ivTimeSeriesData: { timeSeries: { '00060:current': { tsKey: 'current:P7D', @@ -82,10 +86,10 @@ describe('UV: Legend module', () => { } } }, - timeSeriesState: { - currentVariableID: '45807197', - currentDateRange: 'P7D', - showSeries: { + ivTimeSeriesState: { + currentIVVariableID: '45807197', + currentIVDateRangeKind: 'P7D', + showIVTimeSeries: { current: true, compare: true, median: true @@ -98,8 +102,8 @@ describe('UV: Legend module', () => { it('Should return no markers if no time series to show', () => { let newData = { ...TEST_DATA, - series: { - ...TEST_DATA.series, + ivTimeSeriesData: { + ...TEST_DATA.ivTimeSeriesData, timeSeries: {} }, statisticsData: {} @@ -125,9 +129,9 @@ describe('UV: Legend module', () => { it('Should return markers for a different selected variable', () => { const newData = { ...TEST_DATA, - timeSeriesState: { - ...TEST_DATA.timeSeriesState, - currentVariableID: '45807202' + ivTimeSeriesState: { + ...TEST_DATA.ivTimeSeriesState, + currentIVVariableID: '45807202' } }; const result = legendMarkerRowsSelector(newData); @@ -142,9 +146,9 @@ describe('UV: Legend module', () => { it('Should return markers only for time series shown', () => { const newData = { ...TEST_DATA, - timeSeriesState: { - ...TEST_DATA.timeSeriesState, - showSeries: { + ivTimeSeriesState: { + ...TEST_DATA.ivTimeSeriesState, + showIVTimeSeries: { 'current': true, 'compare': false, 'median': false @@ -198,7 +202,7 @@ describe('UV: Legend module', () => { }); it('Should have 4 legend marker after the median time series are removed', (done) => { - store.dispatch(Actions.toggleTimeSeries('median', false)); + store.dispatch(Actions.setIVTimeSeriesVisibility('median', false)); window.requestAnimationFrame(() => { expect(selectAll('.legend g').size()).toBe(4); done(); diff --git a/assets/src/scripts/components/hydrograph/method-picker.js b/assets/src/scripts/components/hydrograph/method-picker.js index 91bff95e9..43bfcb95b 100644 --- a/assets/src/scripts/components/hydrograph/method-picker.js +++ b/assets/src/scripts/components/hydrograph/method-picker.js @@ -8,7 +8,7 @@ import {createStructuredSelector} from 'reselect'; import{link} from '../../lib/d3-redux'; import config from '../../config'; import {getCurrentMethodID, getAllMethodsForCurrentVariable} from '../../selectors/time-series-selector'; -import {Actions} from '../../store'; +import {Actions} from '../../store/instantaneous-value-time-series-state'; import { } from './time-series'; @@ -27,7 +27,7 @@ export const drawMethodPicker = function(elem, store) { .attr('class', 'usa-select') .attr('id', 'method-picker') .on('change', function() { - store.dispatch(Actions.setCurrentMethodID(parseInt(select(this).property('value')))); + store.dispatch(Actions.setCurrentIVMethodID(parseInt(select(this).property('value')))); }) .call(link(store,function(elem, {methods, currentMethodId}) { const currentMethodIdString = parseInt(currentMethodId); diff --git a/assets/src/scripts/components/hydrograph/method-picker.spec.js b/assets/src/scripts/components/hydrograph/method-picker.spec.js index ba80d119c..ca34559a3 100644 --- a/assets/src/scripts/components/hydrograph/method-picker.spec.js +++ b/assets/src/scripts/components/hydrograph/method-picker.spec.js @@ -16,7 +16,7 @@ describe('method-picker', () => { }); const TEST_STATE = { - series: { + ivTimeSeriesData: { timeSeries: { '69930:00010:current': { points: DATA, @@ -53,8 +53,8 @@ describe('method-picker', () => { } } }, - timeSeriesState: { - currentVariableID: '00010id' + ivTimeSeriesState: { + currentIVVariableID: '00010id' } }; @@ -73,7 +73,7 @@ describe('method-picker', () => { window.requestAnimationFrame(() => { expect(div.select('div').property('hidden')).toEqual(false); expect(div.select('select').property('value')).toEqual('69930'); - expect(store.getState().timeSeriesState.currentMethodID).toEqual(69930); + expect(store.getState().ivTimeSeriesState.currentIVMethodID).toEqual(69930); done(); }); }); diff --git a/assets/src/scripts/components/hydrograph/parameters.js b/assets/src/scripts/components/hydrograph/parameters.js index 13ef13f38..ed1b15ac2 100644 --- a/assets/src/scripts/components/hydrograph/parameters.js +++ b/assets/src/scripts/components/hydrograph/parameters.js @@ -5,7 +5,7 @@ import {select} from 'd3-selection'; import {getVariables, getCurrentVariableID, getTimeSeries} from '../../selectors/time-series-selector'; import config from '../../config'; -import {Actions} from '../../store'; +import {Actions} from '../../store/instantaneous-value-time-series-data'; import {appendTooltip} from '../../tooltips'; import {sortedParameters} from '../../utils'; @@ -181,7 +181,7 @@ export const plotSeriesSelectTable = function (elem, .attr('aria-selected', parm => parm[1].selected) .on('click', function (parm) { if (!parm[1].selected) { - store.dispatch(Actions.updateCurrentVariable(siteno, parm[1].variableID)); + store.dispatch(Actions.updateIVCurrentVariableAndRetrieveTimeSeries(siteno, parm[1].variableID)); } }) .call(tr => { diff --git a/assets/src/scripts/components/hydrograph/parameters.spec.js b/assets/src/scripts/components/hydrograph/parameters.spec.js index 958dde5f9..3b30708ba 100644 --- a/assets/src/scripts/components/hydrograph/parameters.spec.js +++ b/assets/src/scripts/components/hydrograph/parameters.spec.js @@ -1,15 +1,17 @@ -import {select} from 'd3-selection'; import {scaleLinear} from 'd3-scale'; -import {addSparkLine, plotSeriesSelectTable, availableTimeSeriesSelector} from './parameters'; +import {select} from 'd3-selection'; + import {configureStore} from '../../store'; +import {addSparkLine, plotSeriesSelectTable, availableTimeSeriesSelector} from './parameters'; + describe('Parameters module', () => { describe('availableTimeSeriesSelector', () => { it('sets attributes correctly when all series have data points', () => { const available = availableTimeSeriesSelector({ - series: { + ivTimeSeriesData: { timeSeries: { 'current:00060': {description: '00060', tsKey: 'current:P7D', variable: 'code0', points: [{x: 1, y: 2}]}, 'current:00061': {description: '00061', tsKey: 'current:P7D', variable: 'code1', points: [{x: 2, y: 3}]}, @@ -49,8 +51,8 @@ describe('Parameters module', () => { } } }, - timeSeriesState: { - currentVariableID: 'code0' + ivTimeSeriesState: { + currentIVVariableID: 'code0' } }); // Series are ordered by parameter code and have expected values. @@ -63,7 +65,7 @@ describe('Parameters module', () => { it('sets attributes correctly when not all series have data points', () => { const available = availableTimeSeriesSelector({ - series: { + ivTimeSeriesData: { timeSeries: { 'current:00060': {description: '00060', tsKey: 'current:P7D', variable: 'code0', points: [{x: 1, y: 2}]}, 'current:00061': {description: '00061', tsKey: 'current:P7D', variable: 'code1', points: [{x: 2, y: 3}]}, @@ -103,8 +105,8 @@ describe('Parameters module', () => { } } }, - timeSeriesState: { - currentVariableID: 'code0' + ivTimeSeriesState: { + currentIVVariableID: 'code0' } }); // Series are ordered by parameter code and have expected values. @@ -117,7 +119,7 @@ describe('Parameters module', () => { it('time series without data points are considered available', () => { const available = availableTimeSeriesSelector({ - series: { + ivTimeSeriesData: { timeSeries: { 'current:00060': {description: '00060', tsKey: 'current:P7D', variable: 'code0', points: [{x: 1, y: 2}]}, 'current:00061': {description: '00061', tsKey: 'current:P7D', variable: 'code1', points: []}, @@ -157,8 +159,8 @@ describe('Parameters module', () => { } } }, - timeSeriesState: { - currentVariableID: 'code0' + ivTimeSeriesState: { + currentIVVariableID: 'code0' } }); // Series are ordered by parameter code and have expected values. diff --git a/assets/src/scripts/components/hydrograph/scales.js b/assets/src/scripts/components/hydrograph/scales.js index 762c435cf..ba7c5e569 100644 --- a/assets/src/scripts/components/hydrograph/scales.js +++ b/assets/src/scripts/components/hydrograph/scales.js @@ -69,18 +69,18 @@ export const createYScale = function (parmCd, extent, size) { export const getXScale = memoize((kind, tsKey) => createSelector( getLayout(kind), getRequestTimeRange(tsKey), - state => state.timeSeriesState.hydrographBrushOffset, - (layout, requestTimeRange, hydrographBrushOffset) => { + state => state.ivTimeSeriesState.ivGraphBrushOffset, + (layout, requestTimeRange, brushOffset) => { let timeRange; if (kind === 'BRUSH') { timeRange = requestTimeRange; } else { - if (hydrographBrushOffset) { + if (brushOffset) { timeRange = { - 'start': requestTimeRange.start + hydrographBrushOffset.start, - 'end': requestTimeRange.end - hydrographBrushOffset.end + 'start': requestTimeRange.start + brushOffset.start, + 'end': requestTimeRange.end - brushOffset.end }; } else { timeRange = requestTimeRange; diff --git a/assets/src/scripts/components/hydrograph/scales.spec.js b/assets/src/scripts/components/hydrograph/scales.spec.js index c0e85991b..e5585db17 100644 --- a/assets/src/scripts/components/hydrograph/scales.spec.js +++ b/assets/src/scripts/components/hydrograph/scales.spec.js @@ -103,10 +103,10 @@ describe('scales', () => { it('Creates a scale when there is no initial data', () => { const STATE = { - series: {}, + ivTimeSeriesData: {}, statisticsData: {}, - timeSeriesState: { - showSeries: { + ivTimeSeriesState: { + showIVTimeSeries: { current: true, compare: false, median: false @@ -124,7 +124,7 @@ describe('scales', () => { it('Creates a scale when there is initial data', () => { const STATE = { - series: { + ivTimeSeriesData: { variables: { '00060ID': { variableCode: { @@ -140,12 +140,12 @@ describe('scales', () => { } }, statisticsData: {}, - timeSeriesState: { - showSeries: { + ivTimeSeriesState: { + showIVTimeSeries: { current: true, compare: false }, - currentVariableID: '00060ID' + currentIVVariableID: '00060ID' }, ui: { width: 200, @@ -160,7 +160,7 @@ describe('scales', () => { describe('getSecondaryYScale', () => { it('Returns null if a non-temperature parameter is selected', () => { expect(getSecondaryYScale()({ - series: { + ivTimeSeriesData: { variables: { '00060ID': { variableCode: { @@ -176,12 +176,12 @@ describe('scales', () => { } }, statisticsData: {}, - timeSeriesState: { - showSeries: { + ivTimeSeriesState: { + showIVTimeSeries: { current: true, compare: false }, - currentVariableID: '00060ID' + currentIVVariableID: '00060ID' }, ui: { width: 200, @@ -192,7 +192,7 @@ describe('scales', () => { it('Returns a scale if a celsius temperature parameter is selected', () => { const secondaryYScale = getSecondaryYScale()({ - series: { + ivTimeSeriesData: { variables: { '00010ID': { variableCode: { @@ -208,12 +208,12 @@ describe('scales', () => { } }, statisticsData: {}, - timeSeriesState: { - showSeries: { + ivTimeSeriesState: { + showIVTimeSeries: { current: true, compare: false }, - currentVariableID: '00010ID' + currentIVVariableID: '00010ID' }, ui: { width: 200, @@ -225,7 +225,7 @@ describe('scales', () => { it('Returns a scale if a fahrenheit temperature parameter is selected', () => { const secondaryYScale = getSecondaryYScale()({ - series: { + ivTimeSeriesData: { variables: { '00011ID': { variableCode: { @@ -241,12 +241,12 @@ describe('scales', () => { } }, statisticsData: {}, - timeSeriesState: { - showSeries: { + ivTimeSeriesState: { + showIVTimeSeries: { current: true, compare: false }, - currentVariableID: '00011ID' + currentIVVariableID: '00011ID' }, ui: { width: 200, diff --git a/assets/src/scripts/components/hydrograph/time-series-graph.js b/assets/src/scripts/components/hydrograph/time-series-graph.js index 3206010f9..5d62b05f3 100644 --- a/assets/src/scripts/components/hydrograph/time-series-graph.js +++ b/assets/src/scripts/components/hydrograph/time-series-graph.js @@ -1,4 +1,5 @@ import {line as d3Line, curveStepAfter} from 'd3-shape'; +import {createStructuredSelector} from 'reselect'; import config from '../../config'; @@ -6,6 +7,7 @@ import {addSVGAccessibility} from '../../d3-rendering/accessibility'; import {appendAxes} from '../../d3-rendering/axes'; import {link} from '../../lib/d3-redux'; import {getAgencyCode, getMonitoringLocationName} from '../../selectors/time-series-selector'; +import {mediaQuery} from '../../utils'; import {getAxes} from './axes'; import { @@ -14,12 +16,10 @@ import { HASH_ID } from './drawing-data'; import {getMainLayout} from './layout'; -import {createStructuredSelector} from 'reselect'; import {getMainXScale, getMainYScale} from './scales'; import {descriptionSelector, isVisibleSelector, titleSelector} from './time-series'; import {drawDataLines} from './time-series-data'; import {drawTooltipFocus, drawTooltipText} from './tooltip'; -import {mediaQuery} from '../../utils'; const plotSvgDefs = function(elem) { diff --git a/assets/src/scripts/components/hydrograph/time-series-graph.spec.js b/assets/src/scripts/components/hydrograph/time-series-graph.spec.js index 8fd4cf8cb..73996cd5f 100644 --- a/assets/src/scripts/components/hydrograph/time-series-graph.spec.js +++ b/assets/src/scripts/components/hydrograph/time-series-graph.spec.js @@ -1,13 +1,14 @@ import {select, selectAll} from 'd3-selection'; -import {Actions, configureStore} from '../../store'; +import {configureStore} from '../../store'; +import {Actions} from '../../store/instantaneous-value-time-series-state'; import {drawTimeSeriesGraph} from './time-series-graph'; const TEST_STATE = { - series: { - ianaTimeZone: 'America/Chicago', + ianaTimeZone: 'America/Chicago', + ivTimeSeriesData: { timeSeries: { '2:00010:current': { points: [{ @@ -151,22 +152,20 @@ const TEST_STATE = { } } }, - timeSeriesState: { - currentVariableID: '45807197', - cursorOffset: 0, - currentMethodID: 1, - currentDateRange: 'P7D', - requestedTimeRange: null, - showSeries: { + ivTimeSeriesState: { + currentIVVariableID: '45807197', + ivGraphCursorOffset: 0, + currentIVMethodID: 1, + currentIVDateRangeKind: 'P7D', + showIVTimeSeries: { current: true, compare: true, median: true }, - loadingTSKeys: [] + loadingIVTSKeys: [] }, ui: { - width: 400, - hydrographXRange: undefined + width: 400 } }; @@ -250,7 +249,7 @@ describe('time series graph', () => { }); it('Should remove the lines when removing the compare time series', (done) => { - store.dispatch(Actions.toggleTimeSeries('compare', false)); + store.dispatch(Actions.setIVTimeSeriesVisibility('compare', false)); window.requestAnimationFrame(() => { expect(selectAll('#ts-compare-group .line-segment').size()).toBe(0); done(); @@ -269,7 +268,7 @@ describe('time series graph', () => { }); it('Should remove the lines when removing the median statistics data', (done) => { - store.dispatch(Actions.toggleTimeSeries('median', false)); + store.dispatch(Actions.setIVTimeSeriesVisibility('median', false)); window.requestAnimationFrame(() => { expect(selectAll('#median-points .median-data-series').size()).toBe(0); done(); diff --git a/assets/src/scripts/components/hydrograph/time-series.js b/assets/src/scripts/components/hydrograph/time-series.js index 52b1743db..632e20e03 100644 --- a/assets/src/scripts/components/hydrograph/time-series.js +++ b/assets/src/scripts/components/hydrograph/time-series.js @@ -56,7 +56,7 @@ export const hasTimeSeriesWithPoints = memoize((tsKey, period) => createSelector * @return {Boolean} Show state of the time series */ export const isVisibleSelector = memoize(tsKey => (state) => { - return state.timeSeriesState.showSeries[tsKey]; + return state.ivTimeSeriesState.showIVTimeSeries[tsKey]; }); diff --git a/assets/src/scripts/components/hydrograph/time-series.spec.js b/assets/src/scripts/components/hydrograph/time-series.spec.js index 033ecb4c2..ff3cb2b10 100644 --- a/assets/src/scripts/components/hydrograph/time-series.spec.js +++ b/assets/src/scripts/components/hydrograph/time-series.spec.js @@ -5,7 +5,7 @@ import { const TEST_DATA = { ianaTimeZone: 'America/Chicago', - series: { + ivTimeSeriesData: { timeSeries: { '00060': { tsKey: 'current:P7D', @@ -209,9 +209,9 @@ const TEST_DATA = { } } }, - timeSeriesState: { - currentVariableID: '45807197', - currentDateRange: 'P7D' + ivTimeSeriesState: { + currentIVVariableID: '45807197', + currentIVDateRangeKind: 'P7D' } }; @@ -230,8 +230,8 @@ describe('TimeSeries module', () => { describe('isVisibleSelector', () => { it('Returns whether the time series is visible', () => { const store = { - timeSeriesState: { - showSeries: { + ivTimeSeriesState: { + showIVTimeSeries: { 'current': true, 'compare': false, 'median': true @@ -253,9 +253,9 @@ describe('TimeSeries module', () => { it('Returns empty string if no variable selected', () => { expect(yLabelSelector({ ...TEST_DATA, - timeSeriesState: { - ...TEST_DATA.timeSeriesState, - currentVariableID: null + ivTimeSeriesState: { + ...TEST_DATA.ivTimeSeriesState, + currentIVVariableID: null } })).toBe(''); }); @@ -265,9 +265,9 @@ describe('TimeSeries module', () => { it('returns a secondary label when a celsius parameter is selected', () => { expect(secondaryYLabelSelector({ ...TEST_DATA, - timeSeriesState: { - ...TEST_DATA.timeSeriesState, - currentVariableID: '45807196' + ivTimeSeriesState: { + ...TEST_DATA.ivTimeSeriesState, + currentIVVariableID: '45807196' } })).toEqual('degrees Fahrenheit'); }); @@ -275,9 +275,9 @@ describe('TimeSeries module', () => { it('returns a secondary label when a fahrenheit parameter is selected', () => { expect(secondaryYLabelSelector({ ...TEST_DATA, - timeSeriesState: { - ...TEST_DATA.timeSeriesState, - currentVariableID: '45807195' + ivTimeSeriesState: { + ...TEST_DATA.ivTimeSeriesState, + currentIVVariableID: '45807195' } })).toEqual('degrees Celsius'); }); @@ -294,18 +294,18 @@ describe('TimeSeries module', () => { it('Returns the title string with the method description appended', () => { expect(titleSelector({ ...TEST_DATA, - timeSeriesState: { - ...TEST_DATA.timeSeriesState, - currentMethodID: 69330 + ivTimeSeriesState: { + ...TEST_DATA.ivTimeSeriesState, + currentIVMethodID: 69330 } })).toBe('Streamflow' + ', ' + '4.1 ft from riverbed (middle)'); }); it('Returns empty string if no variable selected', () => { expect(titleSelector({ ...TEST_DATA, - timeSeriesState: { - ...TEST_DATA.timeSeriesState, - currentVariableID: null + ivTimeSeriesState: { + ...TEST_DATA.ivTimeSeriesState, + currentIVVariableID: null } })).toBe(''); }); diff --git a/assets/src/scripts/components/hydrograph/tooltip.js b/assets/src/scripts/components/hydrograph/tooltip.js index 6df906120..b160487f4 100644 --- a/assets/src/scripts/components/hydrograph/tooltip.js +++ b/assets/src/scripts/components/hydrograph/tooltip.js @@ -2,8 +2,8 @@ import {set} from 'd3-collection'; import {select} from 'd3-selection'; import {transition} from 'd3-transition'; import memoize from 'fast-memoize'; -import {createSelector, createStructuredSelector} from 'reselect'; import {DateTime} from 'luxon'; +import {createSelector, createStructuredSelector} from 'reselect'; import config from '../../config'; import {drawCursorSlider} from '../../d3-rendering/cursor-slider'; @@ -227,7 +227,7 @@ export const drawTooltipFocus = function(elem, store) { layout: getMainLayout }), store, - Actions.setCursorOffset) + Actions.setIVGraphCursorOffset) ); }; @@ -244,8 +244,8 @@ export const drawTooltipCursorSlider = function(elem, store) { elem.attr('viewBox', `0 0 ${layout.width + layout.margin.left + layout.margin.right} 25`); }, getMainLayout)) .call(link(store, drawCursorSlider, createStructuredSelector({ - cursorOffset: (state) => state.timeSeriesState.cursorOffset, + cursorOffset: (state) => state.ivTimeSeriesState.ivGraphCursorOffset, xScale: getMainXScale('current'), layout: getMainLayout - }), store, Actions.setCursorOffset)); + }), store, Actions.setIVGraphCursorOffset)); }; \ No newline at end of file diff --git a/assets/src/scripts/components/hydrograph/tooltip.spec.js b/assets/src/scripts/components/hydrograph/tooltip.spec.js index a99ea60dd..671420395 100644 --- a/assets/src/scripts/components/hydrograph/tooltip.spec.js +++ b/assets/src/scripts/components/hydrograph/tooltip.spec.js @@ -1,5 +1,8 @@ import {select} from 'd3-selection'; -import {Actions, configureStore} from '../../store'; + +import {configureStore} from '../../store'; +import {Actions} from '../../store/instantaneous-value-time-series-state'; + import {drawTooltipText, drawTooltipFocus, tooltipPointsSelector, drawTooltipCursorSlider} from './tooltip'; @@ -28,7 +31,7 @@ describe('Hydrograph tooltip module', () => { data = data.concat(maskedData); const testState = { - series: { + ivTimeSeriesData: { timeSeries: { '69928:current:P7D': { points: data, @@ -151,21 +154,20 @@ describe('Hydrograph tooltip module', () => { } } }, - timeSeriesState: { - showSeries: { + ivTimeSeriesState: { + showIVTimeSeries: { current: true, compare: true }, - currentVariableID: '00060id', - currentMethodID: 69928, - currentDateRange: 'P7D', - customTimeRange: null, - cursorOffset: 61200000 + currentIVVariableID: '00060id', + currentIVMethodID: 69928, + currentIVDateRangeKind: 'P7D', + customIVTimeRange: null, + ivGraphCursorOffset: 61200000 }, ui: { windowWidth: 1300, - width: 990, - hydrographXRange: undefined + width: 990 } }; @@ -220,9 +222,9 @@ describe('Hydrograph tooltip module', () => { it('Creates the container for tooltips', () => { let store = configureStore({ - timeSeriesState: { - cursorOffset: null, - showSeries: { + ivTimeSeriesState: { + ivGraphCursorOffset: null, + showIVTimeSeries: { current: true } } @@ -236,8 +238,8 @@ describe('Hydrograph tooltip module', () => { it('Creates the text elements with the label for the focus times', () => { let store = configureStore(Object.assign({}, testState, { - timeSeriesState: Object.assign({}, testState.timeSeriesState, { - cursorOffset: 2 * 60 * 60 * 1000 + ivTimeSeriesState: Object.assign({}, testState.ivTimeSeriesState, { + ivGraphCursorOffset: 2 * 60 * 60 * 1000 }) })); @@ -251,10 +253,10 @@ describe('Hydrograph tooltip module', () => { it('Creates the text elements with the label for the focus times when there is a second axis', () => { let store = configureStore(Object.assign({}, testState, { - timeSeriesState: Object.assign({}, testState.timeSeriesState, { - cursorOffset: 2 * 60 * 60 * 1000, - currentVariableID: '00010id', - currentMethodID: 69929 + ivTimeSeriesState: Object.assign({}, testState.ivTimeSeriesState, { + ivGraphCursorOffset: 2 * 60 * 60 * 1000, + currentIVVariableID: '00010id', + currentIVMethodID: 69929 }) })); @@ -268,8 +270,8 @@ describe('Hydrograph tooltip module', () => { it('Text contents are updated when the store is provided with new focus times', (done) => { let store = configureStore(Object.assign({}, testState, { - timeSeriesState: Object.assign({}, testState.timeSeriesState, { - cursorOffset: 1 + ivTimeSeriesState: Object.assign({}, testState.ivTimeSeriesState, { + ivGraphCursorOffset: 1 }) })); @@ -277,7 +279,7 @@ describe('Hydrograph tooltip module', () => { let value = div.select('.current-tooltip-text').text().split(' - ')[0]; expect(value).toBe('12 ft3/s'); - store.dispatch(Actions.setCursorOffset(3 * 60 * 60 * 1000)); + store.dispatch(Actions.setIVGraphCursorOffset(3 * 60 * 60 * 1000)); window.requestAnimationFrame(() => { value = div.select('.current-tooltip-text').text().split(' - ')[0]; @@ -291,13 +293,13 @@ describe('Hydrograph tooltip module', () => { it('Shows the qualifier text if focus is near masked data points', (done) => { let store = configureStore(Object.assign({}, testState, { - timeSeriesState: Object.assign({}, testState.timeSeriesState, { - cursorOffset: 1 + ivTimeSeriesState: Object.assign({}, testState.ivTimeSeriesState, { + ivGraphCursorOffset: 1 }) })); div.call(drawTooltipText, store); - store.dispatch(Actions.setCursorOffset(299 * 60 * 1000)); // 2018-01-03T16:59:00.000Z + store.dispatch(Actions.setIVGraphCursorOffset(299 * 60 * 1000)); // 2018-01-03T16:59:00.000Z window.requestAnimationFrame(() => { expect(div.select('.current-tooltip-text').text()).toContain('Flood'); @@ -314,19 +316,19 @@ describe('Hydrograph tooltip module', () => { }; }); let store = configureStore(Object.assign({}, testState, { - series: Object.assign({}, testState.series, { - timeSeries: Object.assign({}, testState.series.timeSeries, { - '69928:current:P7D': Object.assign({}, testState.series.timeSeries['69928:current:P7D'], { + ivTimeSeriesData: Object.assign({}, testState.ivTimeSeriesData, { + timeSeries: Object.assign({}, testState.ivTimeSeriesData.timeSeries, { + '69928:current:P7D': Object.assign({}, testState.ivTimeSeriesData.timeSeries['69928:current:P7D'], { points: zeroData }) }) }), - timeSeriesState: Object.assign({}, testState.timeSeriesState, { - cursorOffset: 10 + ivTimeSeriesState: Object.assign({}, testState.ivTimeSeriesState, { + ivGraphCursorOffset: 10 }) })); div.call(drawTooltipText, store); - store.dispatch(Actions.setCursorOffset(119 * 60 * 1000)); + store.dispatch(Actions.setIVGraphCursorOffset(119 * 60 * 1000)); window.requestAnimationFrame(() => { let value = div.select('.current-tooltip-text').text().split(' - ')[0]; @@ -356,8 +358,8 @@ describe('Hydrograph tooltip module', () => { it('Creates focus lines and focus circles when cursor not set', () => { let store = configureStore(Object.assign({}, testState, { - series: Object.assign({}, testState.series, { - timeSeries: Object.assign({}, testState.series.timeSeries, { + ivTimeSeriesData: Object.assign({}, testState.ivTimeSeriesData, { + timeSeries: Object.assign({}, testState.ivTimeSeriesData.timeSeries, { '69928:current:P7D': { points: currentTsData, tsKey: 'current:P7D', @@ -372,8 +374,8 @@ describe('Hydrograph tooltip module', () => { } }) }), - timeSeriesState: Object.assign({}, testState.timeSeriesState, { - cursorOffset: null + ivTimeSeriesState: Object.assign({}, testState.ivTimeSeriesState, { + ivGraphCursorOffset: null }) })); @@ -386,8 +388,8 @@ describe('Hydrograph tooltip module', () => { it('Focus circles and line are displayed if cursor is set', () => { let store = configureStore(Object.assign({}, testState, { - series: Object.assign({}, testState.series, { - timeSeries: Object.assign({}, testState.series.timeSeries, { + ivTimeSeriesData: Object.assign({}, testState.ivTimeSeriesData, { + timeSeries: Object.assign({}, testState.ivTimeSeriesData.timeSeries, { '69928:current:P7D': { points: currentTsData, tsKey: 'current:P7D', @@ -402,8 +404,8 @@ describe('Hydrograph tooltip module', () => { } }) }), - timeSeriesState: Object.assign({}, testState.timeSeriesState, { - cursorOffset: 39 * 60 * 1000 + ivTimeSeriesState: Object.assign({}, testState.ivTimeSeriesState, { + ivGraphCursorOffset: 39 * 60 * 1000 }) })); diff --git a/assets/src/scripts/index.spec.js b/assets/src/scripts/index.spec.js index f22fb27e3..f7cbacee9 100644 --- a/assets/src/scripts/index.spec.js +++ b/assets/src/scripts/index.spec.js @@ -9,7 +9,7 @@ import './mock-service-data'; import './polyfills'; -/* + import './ajax.spec'; import './d3-rendering/accessibility.spec'; @@ -38,9 +38,7 @@ import './components/hydrograph/audible.spec'; import './components/hydrograph/cursor.spec'; import './components/hydrograph/date-controls.spec'; import './components/hydrograph/domain.spec'; -*/ import './components/hydrograph/drawing-data.spec'; -/* import './components/hydrograph/graph-brush.spec'; import './components/hydrograph/graph-controls.spec'; import './components/hydrograph/index.spec'; @@ -95,4 +93,3 @@ import './networks/network-component/network-legend.spec'; import './networks/selectors/network-data-selector.spec'; import './networks/store/network-store.spec'; import './networks/store/network-data-reducer.spec'; -*/ diff --git a/assets/src/scripts/store/index.js b/assets/src/scripts/store/index.js index b8cce771f..ebf18a73f 100644 --- a/assets/src/scripts/store/index.js +++ b/assets/src/scripts/store/index.js @@ -7,20 +7,20 @@ import { import {nldiDataReducer as nldiData} from './nldi-data'; import {dailyValueTimeSeriesDataReducer as dailyValueTimeSeriesData} from './daily-value-time-series'; import {dailyValueTimeSeriesStateReducer as dailyValueTimeSeriesState} from './daily-value-time-series'; -import {ivTimeSeriesDataReducer as series} from './instantaneous-value-time-series-data'; -import {ivTimeSeriesStateReducer as timeSeriesState} from './instantaneous-value-time-series-state'; +import {ivTimeSeriesDataReducer as ivTimeSeriesData} from './instantaneous-value-time-series-data'; +import {ivTimeSeriesStateReducer as ivTimeSeriesState} from './instantaneous-value-time-series-state'; import {statisticsDataReducer as statisticsData} from './statistics-data'; import {timeZoneReducer as ianaTimeZone} from './time-zone'; import {uiReducer as ui} from './ui-state'; const appReducer = combineReducers({ - series, + ivTimeSeriesData, ianaTimeZone, dailyValueTimeSeriesData, statisticsData, floodData, nldiData, - timeSeriesState, + ivTimeSeriesState, dailyValueTimeSeriesState, floodState, ui diff --git a/assets/src/scripts/store/instantaneous-value-time-series-data.js b/assets/src/scripts/store/instantaneous-value-time-series-data.js index 8c071b3b3..7cb09a5e3 100644 --- a/assets/src/scripts/store/instantaneous-value-time-series-data.js +++ b/assets/src/scripts/store/instantaneous-value-time-series-data.js @@ -3,6 +3,7 @@ import findKey from 'lodash/findKey'; import last from 'lodash/last'; import merge from 'lodash/merge'; import omitBy from 'lodash/omitBy'; +import {DateTime} from 'luxon'; import { getCurrentDateRangeKind, @@ -11,6 +12,7 @@ import { getTsRequestKey, hasTimeSeries } from '../selectors/time-series-selector'; +import {getIanaTimeZone} from '../selectors/time-zone-selector'; import {getPreviousYearTimeSeries, getTimeSeries} from '../web-services/models'; import {normalize} from '../schema'; import {calcStartTime, sortedParameters} from '../utils'; @@ -282,6 +284,24 @@ const retrieveExtendedIVTimeSeries = function(siteno, period, paramCd=null) { }; }; +/* + * Asynchronous Redux Action which retrieves data for a custom time range + * @param {String} siteno + * @param {String} startTimeStr + * @param {String} endTimeStr + * @param {String} paramCd + * @return {Function} which returns a promise when the data has been fetched + */ +const retrieveUserRequestedIVDataForDateRange = function(siteno, startTimeStr, endTimeStr, parmCd=null) { + return function(dispatch, getState) { + const state = getState(); + const locationIanaTimeZone = getIanaTimeZone(state); + const startTime = new DateTime.fromISO(startTimeStr,{zone: locationIanaTimeZone}).toMillis(); + const endTime = new DateTime.fromISO(endTimeStr, {zone: locationIanaTimeZone}).toMillis(); + return dispatch(Actions.retrieveCustomIVTimeSeries(siteno, startTime, endTime, parmCd)); + }; +}; + /* * Asynchronous Redux Action which sets the current variable id and fetches the custom * time series for that variable or the extended time series depending on the current date range kind. @@ -335,5 +355,6 @@ export const Actions = { retrieveCustomTimePeriodIVTimeSeries, retrieveCustomIVTimeSeries, retrieveExtendedIVTimeSeries, + retrieveUserRequestedIVDataForDateRange, updateIVCurrentVariableAndRetrieveTimeSeries }; diff --git a/assets/src/scripts/store/instantaneous-value-time-series-data.spec.js b/assets/src/scripts/store/instantaneous-value-time-series-data.spec.js index cba6bd83f..8d6a4f42b 100644 --- a/assets/src/scripts/store/instantaneous-value-time-series-data.spec.js +++ b/assets/src/scripts/store/instantaneous-value-time-series-data.spec.js @@ -615,5 +615,34 @@ describe('store/instantaneous-value-time-series-data module', () => { expect(ivTimeSeriesStateActions.ivTimeSeriesPlayStop).toHaveBeenCalled(); }); }); + + describe('retrieveUserRequestedIVDataForDateRange', () => { + let mockDispatch; + let mockGetState; + + beforeEach(() => { + mockDispatch = jasmine.createSpy('mockDispatch'); + mockGetState = jasmine.createSpy('mockGetState').and.returnValue({ + series: { + ianaTimeZone: 'America/Chicago' + } + }); + + spyOn(Actions, 'retrieveCustomTimeSeries'); + jasmine.Ajax.install(); + }); + + afterEach(() => { + jasmine.Ajax.uninstall(); + }); + + it('Converts time strings to javascript date/time objects correctly', () => { + Actions.retrieveUserRequestedIVDataForDateRange('12345678', '2010-01-01', '2010-03-01')(mockDispatch, mockGetState); + expect(Actions.retrieveCustomIVTimeSeries).toHaveBeenCalled(); + expect(Actions.retrieveCustomIVTimeSeries.calls.argsFor(0)[0]).toEqual('12345678'); + expect(Actions.retrieveCustomIVTimeSeries.calls.argsFor(0)[1]).toEqual(1262325600000); + expect(Actions.retrieveCustomIVTimeSeries.calls.argsFor(0)[2]).toEqual(1267423200000); + }); + }); }); }); \ No newline at end of file diff --git a/assets/src/scripts/store/instantaneous-value-time-series-state.js b/assets/src/scripts/store/instantaneous-value-time-series-state.js index 37f5f1dac..6b4126e63 100644 --- a/assets/src/scripts/store/instantaneous-value-time-series-state.js +++ b/assets/src/scripts/store/instantaneous-value-time-series-state.js @@ -196,7 +196,7 @@ export const ivTimeSeriesStateReducer = function(ivTimeSeriesState={}, action) { let newVisibility = {}; newVisibility[action.key] = action.show; return Object.assign({}, ivTimeSeriesState, { - showIVTimeSeries: Object.assign({}, ivTimeSeriesState.showSeries, newVisibility) + showIVTimeSeries: Object.assign({}, ivTimeSeriesState.showIVTimeSeries, newVisibility) }); } diff --git a/assets/src/scripts/url-params.js b/assets/src/scripts/url-params.js index 87a8fde55..5092a5435 100644 --- a/assets/src/scripts/url-params.js +++ b/assets/src/scripts/url-params.js @@ -2,7 +2,7 @@ import {DateTime} from 'luxon'; import {createStructuredSelector} from 'reselect'; import {listen} from './lib/d3-redux'; -import {getCurrentMethodID, getAllMethodsForCurrentVariable, getCurrentDateRange, getCustomTimeRange, getCurrentParmCd} +import {getCurrentMethodID, getAllMethodsForCurrentVariable, getCurrentDateRangeKind, getCustomTimeRange, getCurrentParmCd} from './selectors/time-series-selector'; import {getIanaTimeZone} from './selectors/time-zone-selector'; @@ -21,10 +21,10 @@ export const renderTimeSeriesUrlParams = function(store) { methodId: getCurrentMethodID, methods: getAllMethodsForCurrentVariable, compare: (state) => state.timeSeriesState.showSeries.compare, - currentDateRange: getCurrentDateRange, + currentDateRangeKind: getCurrentDateRangeKind, customTimeRange: getCustomTimeRange, timeZone: getIanaTimeZone - }), ({parameterCode, methodId, methods, compare, currentDateRange, customTimeRange, timeZone}) => { + }), ({parameterCode, methodId, methods, compare, currentDateRangeKind, customTimeRange, timeZone}) => { let params = new window.URLSearchParams(); if (parameterCode) { params.set('parameterCode', parameterCode); @@ -32,10 +32,10 @@ export const renderTimeSeriesUrlParams = function(store) { if (Object.keys(methods).length > 1) { params.set('timeSeriesId', methodId); } - switch(currentDateRange) { + switch(currentDateRangeKind) { case 'P30D': case 'P1Y': - params.set('period', currentDateRange); + params.set('period', currentDateRangeKind); break; case 'custom': params.set( diff --git a/assets/src/scripts/url-params.spec.js b/assets/src/scripts/url-params.spec.js index 0f49cd1ed..adad1d06a 100644 --- a/assets/src/scripts/url-params.spec.js +++ b/assets/src/scripts/url-params.spec.js @@ -1,4 +1,5 @@ -import {configureStore, Actions} from './store'; +import {configureStore} from './store'; +import {Actions} from './store/instantaneous-value-time-series-state'; import {getParamString, renderTimeSeriesUrlParams} from './url-params'; describe('url-params module', () => { @@ -19,7 +20,7 @@ describe('url-params module', () => { describe('renderTimeSeriesUrlParams', () => { const TEST_STATE = { - series: { + ivTimeSeriesData: { variables: { '123456': { oid: '123456', @@ -53,12 +54,12 @@ describe('url-params module', () => { } }, ianaTimeZone: 'America/New_York', - timeSeriesState: { - currentVariableID: '123456', - currentDateRange: 'P7D', - customTimeRange: null, - currentMethodID: '69928', - showSeries: { + ivTimeSeriesState: { + currentIVVariableID: '123456', + currentIVDateRangeKind: 'P7D', + customIVTimeRange: null, + currentIVMethodID: '69928', + showIVTimeSeries: { compare: false } } @@ -83,9 +84,9 @@ describe('url-params module', () => { it('adds compare if compare is in the store', () => { let store = configureStore({ ...TEST_STATE, - timeSeriesState: { - ...TEST_STATE.timeSeriesState, - showSeries: { + ivTimeSeriesState: { + ...TEST_STATE.ivTimeSeriesState, + showIVTimeSeries: { compare: true } } @@ -103,9 +104,9 @@ describe('url-params module', () => { it('adds period if current date range is P30D or P1Y', (done) => { let store = configureStore({ ...TEST_STATE, - timeSeriesState: { - ...TEST_STATE.timeSeriesState, - currentDateRange: 'P30D' + ivTimeSeriesState: { + ...TEST_STATE.ivTimeSeriesState, + currentIVDateRangeKind: 'P30D' } }); renderTimeSeriesUrlParams(store); @@ -117,7 +118,7 @@ describe('url-params module', () => { expect(window.location.hash).not.toContain('endDT'); expect(window.location.hash).not.toContain('timeSeriesId'); - store.dispatch(Actions.setCurrentDateRange('P1Y')); + store.dispatch(Actions.setCurrentIVDateRangeKind('P1Y')); window.requestAnimationFrame(() => { expect(window.location.hash).toContain('period=P1Y'); done(); @@ -126,12 +127,12 @@ describe('url-params module', () => { it('Contains startDT and endDT in url if customTimeRange is set in store', () => { let store = configureStore({ ...TEST_STATE, - timeSeriesState: { - ...TEST_STATE.timeSeriesState, - currentDateRange: 'custom', - customTimeRange: { - startDT: 1546318800000, - endDT: 1551416400000 + ivTimeSeriesState: { + ...TEST_STATE.ivTimeSeriesState, + currentIVDateRangeKind: 'custom', + customIVTimeRange: { + start: 1546318800000, + end: 1551416400000 } } }); @@ -148,8 +149,8 @@ describe('url-params module', () => { it('expects timeSeriesId to be set if currentMethodId is not null and multiple time series in selected variable', () => { let store = configureStore({ ...TEST_STATE, - series: { - ...TEST_STATE.series, + ivTimeSeriesData: { + ...TEST_STATE.ivTimeSeriesData, timeSeries: { '69928:current:P7D': { tsKey: 'current:P7D', -- GitLab