diff --git a/assets/src/scripts/index.spec.js b/assets/src/scripts/index.spec.js index ad4b8fc6461ef279ca6ab2ee5e0c8dced2c0f443..49c4441452096db6b9cbfb00ee6ae69e4bc8ec53 100644 --- a/assets/src/scripts/index.spec.js +++ b/assets/src/scripts/index.spec.js @@ -43,21 +43,23 @@ import './monitoring-location/components/daily-value-hydrograph/tooltip.spec'; import './monitoring-location/components/embed.spec'; -import './monitoring-location/components/hydrograph/audible.spec'; import './monitoring-location/components/hydrograph/selectors/cursor.spec'; -import './monitoring-location/components/hydrograph/date-controls.spec'; import './monitoring-location/components/hydrograph/selectors/domain.spec'; -import './monitoring-location/components/hydrograph/drawing-data.spec'; +import './monitoring-location/components/hydrograph/selectors/drawing-data.spec'; +import './monitoring-location/components/hydrograph/selectors/layout.spec'; +import './monitoring-location/components/hydrograph/selectors/parameter-data.spec'; +import './monitoring-location/components/hydrograph/selectors/scales.spec'; +import './monitoring-location/components/hydrograph/selectors/time-series-data.spec'; + +import './monitoring-location/components/hydrograph/audible.spec'; +import './monitoring-location/components/hydrograph/date-controls.spec'; import './monitoring-location/components/hydrograph/data-table.spec'; import './monitoring-location/components/hydrograph/graph-brush.spec'; import './monitoring-location/components/hydrograph/graph-controls.spec'; import './monitoring-location/components/hydrograph/index.spec'; -import './monitoring-location/components/hydrograph/selectors/layout.spec'; import './monitoring-location/components/hydrograph/legend.spec'; import './monitoring-location/components/hydrograph/method-picker.spec'; import './monitoring-location/components/hydrograph/parameters.spec'; -import './monitoring-location/components/hydrograph/selectors/scales.spec'; -import './monitoring-location/components/hydrograph/selectors/time-series-data.spec'; import './monitoring-location/components/hydrograph/time-series-graph.spec'; import './monitoring-location/components/hydrograph/tooltip.spec'; diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/audible.js b/assets/src/scripts/monitoring-location/components/hydrograph/audible.js index 42d83036dba295287113bc6fe19fb6a18555677b..89ace2cb523e33ebbda1c625f08f0e7b7ec97ba2 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/audible.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/audible.js @@ -12,7 +12,8 @@ import {link} from '../../../lib/d3-redux'; import {getTimeSeries} from '../../selectors/time-series-selector'; import {Actions} from '../../store/instantaneous-value-time-series-state'; -import {getMainXScale, getMainYScale} from './scales'; +import {isAudiblePlaying, getAudiblePoints} from './selectors/audible-data'; +import {getMainXScale, getMainYScale} from './selectors/scales'; // Higher tones get lower volume diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/data-table.js b/assets/src/scripts/monitoring-location/components/hydrograph/data-table.js index 9ce4589fd659358201482911eb0bfac127171da4..53f22a62ff6ea8d2065da12df5aa34610948c1d3 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/data-table.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/data-table.js @@ -3,7 +3,7 @@ import List from 'list.js'; import {link} from '../../../lib/d3-redux'; -import {getCurrentPointData} from './drawing-data'; +import {getCurrentPointData} from './selectors/drawing-data'; const COLUMN_HEADINGS = [ 'Parameter', diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/graph-brush.js b/assets/src/scripts/monitoring-location/components/hydrograph/graph-brush.js index 7845a28c8ae600098f21b798177c3306be7d4616..154d8507409e82e7dd748b0d1765b7f8a8276dd9 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/graph-brush.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/graph-brush.js @@ -7,10 +7,10 @@ import {link} from '../../../lib/d3-redux'; import {Actions} from '../../store/instantaneous-value-time-series-state'; import {getBrushXAxis} from './selectors/axes'; -import {getCurrentVariableLineSegments} from './drawing-data'; +import {getCurrentVariableLineSegments} from './selectors/drawing-data'; import {getBrushLayout} from './selectors/layout'; import {getBrushXScale, getBrushYScale} from './selectors/scales'; -import {isVisibleSelector} from './selectors/time-series-data'; +import {isVisible} from './selectors/time-series-data'; import {drawDataLines} from './time-series-lines'; export const drawGraphBrush = function(container, store) { @@ -52,7 +52,7 @@ export const drawGraphBrush = function(container, store) { layout: getBrushLayout }))) .call(link(store, drawDataLines, createStructuredSelector({ - visible: isVisibleSelector('current'), + visible: isVisible('current'), tsLinesMap: getCurrentVariableLineSegments('current'), xScale: getBrushXScale('current'), yScale: getBrushYScale, diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.js b/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.js index d9ca33d28617417a8f60c9284addbd4ec8c0b26d..93771ab0297484cbc295d8a3b4db7d93fe5d1286 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.js @@ -6,7 +6,7 @@ import {getCurrentVariableTimeSeries} from '../../selectors/time-series-selector import {Actions} from '../../store/instantaneous-value-time-series-state'; import {audibleUI} from './audible'; -import {isVisibleSelector} from './selectors/time-series-data'; +import {isVisible} from './selectors/time-series-data'; /* * Create the show audible toggle, last year toggle, and median toggle for the time series graph. @@ -45,7 +45,7 @@ export const drawGraphControls = function(elem, store) { // Sets the state of the toggle .call(link(store,function(elem, checked) { elem.property('checked', checked); - }, isVisibleSelector('compare'))); + }, isVisible('compare'))); compareControlDiv.append('label') .classed('usa-checkbox__label', true) .attr('id', 'last-year-label') @@ -73,7 +73,7 @@ export const drawGraphControls = function(elem, store) { // Sets the state of the toggle .call(link(store,function(elem, checked) { elem.property('checked', checked); - }, isVisibleSelector('median'))); + }, isVisible('median'))); medianControlDiv.append('label') .classed('usa-checkbox__label', true) diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/index.spec.js b/assets/src/scripts/monitoring-location/components/hydrograph/index.spec.js index 572b6064242554cfbb3310ccf1674c11f4a77dc9..8e91cbeac54994d697395af347c128888ccb33f5 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/index.spec.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/index.spec.js @@ -161,7 +161,6 @@ const TEST_STATE = { } }; - describe('monitoring-location/components/hydrograph module', () => { let graphNode; @@ -518,9 +517,14 @@ describe('monitoring-location/components/hydrograph module', () => { expect(select('#classic-page-link').attr('href')).not.toContain('https://fakenwis.usgs.gov/inventory'); }); - it('should render the correct number of svg nodes', () => { - // one main hydrograph, brush, slider, legend and two sparklines - expect(selectAll('svg').size()).toBe(6); + it('should render the correct number of svg nodes', (done) => { + window.requestAnimationFrame(() => { + window.requestAnimationFrame(() => { + // one main hydrograph, brush, slider, legend and two sparklines + expect(selectAll('svg').size()).toBe(6); + done(); + }); + }); }); it('should have a title div', () => { diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/parameters.js b/assets/src/scripts/monitoring-location/components/hydrograph/parameters.js index 08acbff75ba01bbc381ea5175baec2d5f95f8e41..3e1a8ea71a2238f2a3690c77cc46a7695c973ae9 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/parameters.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/parameters.js @@ -152,7 +152,7 @@ export const plotSeriesSelectTable = function (elem, .attr('width', SPARK_LINE_DIM.width.toString()) .attr('height', SPARK_LINE_DIM.height.toString()); tr.append('td') - .text(parm => parm[1].currentTimeSeriesCount); + .text(parm => parm.timeSeriesCount); tr.append('td') .style('white-space', 'nowrap') .text(parm =>`${config.uvPeriodOfRecord[parm.parameterCode].begin_date} to ${config.uvPeriodOfRecord[parm.parameterCode].end_date}`); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/parameters.spec.js b/assets/src/scripts/monitoring-location/components/hydrograph/parameters.spec.js index 397a6476f4be8c7378c9d55ac4969ec2c6198019..cff44783deb2cd4287896d254c5f436b2e99fa4e 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/parameters.spec.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/parameters.spec.js @@ -20,10 +20,10 @@ describe('monitoring-location/components/hydrograph/parameters module', () => { }; }); - const availableTimeSeries = [ - ['00010', {variableID: '00010ID', description: 'Temperature', selected: true, currentTimeSeriesCount: 1}], - ['00067', {variableID: '00067ID', description: 'Ruthenium (VI) Fluoride', selected: false, currentTimeSeriesCount: 1}], - ['00093', {variableID: '00093ID', description: 'Uranium (V) Oxide', selected: false, currentTimeSeriesCount: 1}] + const availableParameterCodes = [ + {variableID: '00010ID', parameterCode: '00010', description: 'Temperature', selected: true, timeSeriesCount: 1}, + {variableID: '00067ID', parameterCode: '00067', description: 'Ruthenium (VI) Fluoride', selected: false, timeSeriesCount: 1}, + {variableID: '00093ID', parameterCode: '00093', description: 'Uranium (V) Oxide', selected: false, timeSeriesCount: 1} ]; const lineSegmentsByParmCd = { @@ -38,13 +38,14 @@ describe('monitoring-location/components/hydrograph/parameters module', () => { const testArgsWithData = { siteno: '12345678', - availableTimeSeries: availableTimeSeries, + availableParameterCodes: availableParameterCodes, lineSegmentsByParmCd: lineSegmentsByParmCd, timeSeriesScalesByParmCd: timeSeriesScalesByParmCd }; const testArgsWithoutData = { - availableTimeSeries: [], + siteno: '12345678', + availableParameterCodes: [], lineSegmentsByParmCd: {}, timeSeriesScalesByParmCd: {} }; diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/audible-data.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/audible-data.js index 607799bb52b951b8043938210d43daec3986ccbe..fcb7ecf3263db70fa02c4d185b47ba646adc7acf 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/audible-data.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/audible-data.js @@ -8,13 +8,13 @@ import {createSelector} from 'reselect'; import {getTimeSeries} from '../../../selectors/time-series-selector'; -import {tsCursorPointsSelector} from './cursor'; +import {getTsCursorPoints} from './cursor'; import {getMainYScale} from './scales'; /* * Returns a Redux selector function that returns true if the audible interface is playing. */ -export const isAudiblePlaying = state => state.ivTimeSeriesStat.audiblePlayId !== null; +export const isAudiblePlaying = state => state.ivTimeSeriesState.audiblePlayId !== null; const getAudibleYScale = createSelector( getMainYScale, @@ -31,8 +31,8 @@ const getAudibleYScale = createSelector( */ export const getAudiblePoints = createSelector( getTimeSeries, - tsCursorPointsSelector('current'), - tsCursorPointsSelector('compare'), + getTsCursorPoints('current'), + getTsCursorPoints('compare'), getAudibleYScale, (allTimeSeries, currentPoints, comparePoints, yScale) => { // Set null points for all time series, so we can turn audio for those diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/cursor.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/cursor.js index a88a2e10e3279b5063bf84e46dfc627f13e1f178..2a4a9d4ffe4b8f3a8656d1461d163c97155551ae 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/cursor.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/cursor.js @@ -5,7 +5,7 @@ import {getNearestTime} from '../../../../utils'; import {getCurrentMethodID} from '../../../selectors/time-series-selector'; -import {getCurrentVariablePointsByTsId} from '../drawing-data'; +import {getCurrentVariablePointsByTsId} from './drawing-data'; import {getMainXScale, getMainYScale} from './scales'; import {isVisible} from './time-series-data'; diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/cursor.spec.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/cursor.spec.js index 0f4702b38ae2e80b90c73603ddf25d922fff80e7..5750818fb6bcbbe3d801d28752cc6b3cab169328 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/cursor.spec.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/cursor.spec.js @@ -423,11 +423,11 @@ describe('monitoring-location/components/hydrograph/cursor module', () => { }); }); - describe('tooltipPointsSelector', () => { + describe('getTooltipPoints', () => { const id = (val) => val; it('should return the requested time series focus time', () => { - expect(tooltipPointsSelector('current').resultFunc(id, id, { + expect(getTooltipPoints('current').resultFunc(id, id, { '00060:current': { dateTime: '1date', value: 1 diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/domain.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/domain.js index 69d4243065e727a016d9f7259bf285be1577c2ec..17e5b38d52e9c2ed08625a0172d36b973519325c 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/domain.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/domain.js @@ -6,7 +6,7 @@ import config from '../../../../config'; import {mediaQuery} from '../../../../utils'; import {getCurrentParmCd} from '../../../selectors/time-series-selector'; -import {getVisiblePoints} from '../drawing-data'; +import {getVisiblePoints} from './drawing-data'; const PADDING_RATIO = 0.2; @@ -171,53 +171,57 @@ export const getFullArrayOfAdditionalTickMarks = function(tickValues, yDomain) { }; /* - * Returns a Redux selector function that returns the yExtent for the currently - * visible points + * Helper function that returns the yExtent for the points in pointArrays. + * @param {Array of Array of point objects} pointArrays + * @param {String} currentVarParmCd + * @return {Array of two Number} - represents the extent of the points to be used to graph the data. */ -export const getYDomain = createSelector( - getVisiblePoints, - getCurrentParmCd, - (pointArrays, currentVarParmCd) => { - let yExtent; - let scaleDomains = []; - - // Calculate max and min for data - for (const points of pointArrays) { - if (points.length === 0) { - continue; - } - const finitePts = points.map(pt => pt.value).filter(val => isFinite(val)); - let ptExtent = extent(finitePts); - if (ptExtent[0] === ptExtent[1]) { - // when both the lower and upper values of - // extent are the same, the domain of the - // extent is from -Infinity to +Infinity; - // this isn't useful for creation of data - // points, so add this broadens the extent - // a bit for single point series - if (ptExtent[0]) { - ptExtent = [ptExtent[0] - ptExtent[0] / 2, ptExtent[0] + ptExtent[0] / 2]; - } else { // ptExtent of 0 so just set to a constant - ptExtent = [0, 1]; - } - } - scaleDomains.push(ptExtent); +export const getYDomain = function(pointArrays, currentVarParmCd) { + let yExtent; + let scaleDomains = []; + + // Calculate max and min for data + for (const points of pointArrays) { + if (points.length === 0) { + continue; } - if (scaleDomains.length > 0) { - const flatDomains = [].concat(...scaleDomains).filter(val => isFinite(val)); - if (flatDomains.length > 0) { - yExtent = [Math.min(...flatDomains), Math.max(...flatDomains)]; + const finitePts = points.map(pt => pt.value).filter(val => isFinite(val)); + let ptExtent = extent(finitePts); + if (ptExtent[0] === ptExtent[1]) { + // when both the lower and upper values of + // extent are the same, the domain of the + // extent is from -Infinity to +Infinity; + // this isn't useful for creation of data + // points, so add this broadens the extent + // a bit for single point series + if (ptExtent[0]) { + ptExtent = [ptExtent[0] - ptExtent[0] / 2, ptExtent[0] + ptExtent[0] / 2]; + } else { // ptExtent of 0 so just set to a constant + ptExtent = [0, 1]; } } - - // Add padding to the extent and handle empty data sets. - if (yExtent) { - yExtent = extendDomain(yExtent, SYMLOG_PARMS.indexOf(currentVarParmCd) > -1); - } else { - yExtent = [0, 1]; + scaleDomains.push(ptExtent); + } + if (scaleDomains.length > 0) { + const flatDomains = [].concat(...scaleDomains).filter(val => isFinite(val)); + if (flatDomains.length > 0) { + yExtent = [Math.min(...flatDomains), Math.max(...flatDomains)]; } - return yExtent; } + + // Add padding to the extent and handle empty data sets. + if (yExtent) { + yExtent = extendDomain(yExtent, SYMLOG_PARMS.indexOf(currentVarParmCd) > -1); + } else { + yExtent = [0, 1]; + } + return yExtent; +}; + +export const getYDomainForVisiblePoints = createSelector( + getVisiblePoints, + getCurrentParmCd, + getYDomain ); /* @@ -226,7 +230,7 @@ export const getYDomain = createSelector( * @prop tickFormat {Array of String} - formatted tickValues */ export const getYTickDetails = createSelector( - getYDomain, + getYDomainForVisiblePoints, getCurrentParmCd, (yDomain, parmCd) => { const isSymlog = SYMLOG_PARMS.indexOf(parmCd) > -1; diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/domain.spec.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/domain.spec.js index 5eee2781a1897ed9e4c991a4e1cbcdd4ea99b478..623a7e83d898653fc5509d101cb33cd72d8ab52d 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/domain.spec.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/domain.spec.js @@ -9,7 +9,7 @@ import { } from './domain'; -describe('monitoring-location/componens/hydrograph/selectors/domain module', () => { +describe('monitoring-location/components/hydrograph/selectors/domain module', () => { describe('extendDomain', () => { it('lower bounds are calculated based on order of magnitude with the parameter, upper bound 20%', () => { const lowValDomain = extendDomain([50, 1000], true); @@ -115,7 +115,7 @@ describe('monitoring-location/componens/hydrograph/selectors/domain module', () describe('getYTickDetails', () => { it('returns ticks and a formatting function', () => { - const tickDetails = getYTickDetails([0, 1]); + const tickDetails = getYTickDetails.resultFunc([0, 1]); expect(tickDetails.tickValues).toEqual(jasmine.any(Array)); expect(tickDetails.tickFormat).toEqual(jasmine.any(Function)); expect(tickDetails.tickFormat(1)).toEqual(jasmine.any(String)); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/drawing-data.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/drawing-data.js index aed539361449ad195585164f8ee741389ab2013d..895e5c54a94031a8158dd9e0da99b6fd8e727915 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/drawing-data.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/drawing-data.js @@ -10,12 +10,12 @@ import find from 'lodash/find'; import {DateTime} from 'luxon'; import {createSelector} from 'reselect'; -import {getCurrentVariableMedianStatistics} from '../../selectors/median-statistics-selector'; +import {getCurrentVariableMedianStatistics} from '../../../selectors/median-statistics-selector'; import { getVariables, getCurrentMethodID, getTimeSeries, getCurrentVariableTimeSeries, getTimeSeriesForTsKey, getTsRequestKey, getRequestTimeRange, getCurrentVariable -} from '../../selectors/time-series-selector'; -import {getIanaTimeZone} from '../../selectors/time-zone-selector'; +} from '../../../selectors/time-series-selector'; +import {getIanaTimeZone} from '../../../selectors/time-zone-selector'; export const MASK_DESC = { ice: 'Ice Affected', @@ -85,7 +85,7 @@ export const classesForPoint = function(point) { * @param {Object} state * @return {Object} where the keys are ts ids and the values are an Array of point Objects. */ -export const getAllPoints= createSelector( +export const getAllPoints = createSelector( getTimeSeries, getVariables, (timeSeries, variables) => { @@ -157,22 +157,6 @@ export const getCurrentVariablePoints = memoize(tsKey => createSelector( } )); - -/** - * Returns a selector that, for a given tsKey: - * Returns an array of time points for all time series. - * @param {Object} state Redux store - * @param {String} tsKey Time series key - * @return {Array} Array of array of points. - */ -export const getPoints = memoize((tsKey) => createSelector( - getPointsByTsKey(tsKey), - (points) => { - return Object.values(points); - } -)); - - /* * @ return {Array of Arrays of Objects} where the properties are date (universal), and value */ @@ -235,7 +219,7 @@ export const getCurrentVariableMedianStatPoints = createSelector( * @param {Object} state Redux store * @return {Array} Array of point arrays. */ -export const getVisiblePointsSelector = createSelector( +export const getVisiblePoints = createSelector( getCurrentVariablePoints('current'), getCurrentVariablePoints('compare'), getCurrentVariableMedianStatPoints, @@ -409,7 +393,7 @@ export const getLineSegmentsByParmCd = memoize((tsKey, period) => createSelector * Returns mapping of series ID to line segments for the currently selected variable. * @return {Object} - Keys are time series ids and values are the line segment arrays */ -export const currentVariableLineSegmentsSelector = memoize(tsKey => createSelector( +export const getCurrentVariableLineSegments = memoize(tsKey => createSelector( getCurrentVariableTimeSeries(tsKey), getLineSegments(tsKey), (seriesMap, linesMap) => { diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/drawing-data.spec.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/drawing-data.spec.js index d52cffbbb4a55634e0d2005d4d80efd2ef87b036..f38b827918131ea001eb48425c111588308ff1d6 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/drawing-data.spec.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/drawing-data.spec.js @@ -3,11 +3,10 @@ import {DateTime} from 'luxon'; import { getLineSegments, - getPoints, getAllPoints, getPointsByTsKey, classesForPoint, - getLineSegmentsByParmCdSelector, + getLineSegmentsByParmCd, getCurrentVariableLineSegments, getCurrentVariablePoints, getCurrentVariablePointsByTsId, @@ -803,9 +802,9 @@ describe('monitoring-location/components/hydrograph/drawingData module', () => { }); }); - describe('getLineSegmentsByParmCdSelector', () => { + describe('getLineSegmentsByParmCd', () => { it('Should return two mappings for current time series', () => { - const result = getLineSegmentsByParmCdSelector('current')(TEST_DATA); + const result = getLineSegmentsByParmCd('current')(TEST_DATA); expect(Object.keys(result).length).toBe(2); expect(result['00060']).toBeDefined(); @@ -826,50 +825,6 @@ describe('monitoring-location/components/hydrograph/drawingData module', () => { }); }); - describe('getPoints', () => { - it('works with a single collection and two time series', () => { - expect(getPoints('current')({ - ivTimeSeriesData: { - requests: { - current: { - timeSeriesCollections: ['coll1'] - } - }, - timeSeriesCollections: { - 'coll1': { - variable: 45807197, - timeSeries: ['one', 'two'] - } - }, - timeSeries: { - one: { - points: ['ptOne', 'ptTwo', 'ptThree'], - tsKey: 'current:P7D', - variable: 45807197 - }, - two: { - points: ['ptOne2', 'ptTwo2', 'ptThree2'], - tsKey: 'current:P7D', - variable: 45807197 - } - }, - variables: { - '45807197': { - variableCode: { - value: '00060' - }, - oid: 45807197 - } - } - }, - ivTimeSeriesState: { - currentIVVariableID: '45807197', - currentIVDateRangeKind: 'P7D' - } - })).toEqual([['ptOne', 'ptTwo', 'ptThree'], ['ptOne2', 'ptTwo2', 'ptThree2']]); - }); - }); - describe('classesforPoint', () => { it('Return expected classes', () => { expect(classesForPoint({qualifiers: ['F', 'G']})).toEqual({ diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/parameter-data.spec.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/parameter-data.spec.js index f61db3bc44b8fd5fd26ef3ee47abfb0a3e2d3de8..1ecc8e8e809ee69ac17eb9b5e8c535500f39dbcf 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/parameter-data.spec.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/parameter-data.spec.js @@ -10,9 +10,9 @@ describe('monitoring-location/components/hydrograph/selectors/parameter-data', ( '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}]}, 'current:00062': {description: '00062', tsKey: 'current:P7D', variable: 'code2', points: [{x: 3, y: 4}]}, + 'compare:00060': {description: '00060', tsKey: 'compare:P7D', variable: 'code0', points: [{x: 3, y: 46}]}, 'compare:00061': {description: '00061', tsKey: 'compare:P7D', variable: 'code1', points: [{x: 1, y: 17}]}, - 'compare:00062': {description: '00062', tsKey: 'compare:P7D', variable: 'code2', points: [{x: 2, y: 18}]}, - 'compare:00063': {description: '00063', tsKey: 'compare:P7D', variable: 'code3', points: [{x: 3, y: 46}]} + 'compare:00062': {description: '00062', tsKey: 'compare:P7D', variable: 'code2', points: [{x: 2, y: 18}]} }, variables: { 'code0': { @@ -51,76 +51,19 @@ describe('monitoring-location/components/hydrograph/selectors/parameter-data', ( }); // Series are ordered by parameter code and have expected values. expect(available).toEqual([ - ['00060', {variableID: 'code0', description: 'code0 desc', selected: true, currentTimeSeriesCount: 1}], - ['00061', {variableID: 'code1', description: 'code1 desc', selected: false, currentTimeSeriesCount: 1}], - ['00062', {variableID: 'code2', description: 'code2 desc', selected: false, currentTimeSeriesCount: 1}] + {variableID: 'code0', parameterCode: '00060', description: 'code0 desc', selected: true, timeSeriesCount: 1}, + {variableID: 'code1', parameterCode: '00061', description: 'code1 desc', selected: false, timeSeriesCount: 1}, + {variableID: 'code2', parameterCode: '00062', description: 'code2 desc', selected: false, timeSeriesCount: 1} ]); }); it('sets attributes correctly when not all series have data points', () => { - const available = getAvailableParameterCodes({ - 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}]}, - 'current:00062': {description: '00062', tsKey: 'current:P7D', variable: 'code2', points: [{x: 3, y: 4}]}, - 'compare:00061': {description: '00061', tsKey: 'compare:P7D', variable: 'code1', points: []}, - 'compare:00062': {description: '00062', tsKey: 'compare:P7D', variable: 'code2', points: [{x: 2, y: 18}]}, - 'compare:00063': {description: '00063', tsKey: 'compare:P7D', variable: 'code3', points: [{x: 3, y: 46}]} - }, - variables: { - 'code0': { - oid: 'code0', - variableDescription: 'code0 desc', - variableCode: { - value: '00060' - } - }, - 'code1': { - oid: 'code1', - variableDescription: 'code1 desc', - variableCode: { - value: '00061' - } - }, - 'code2': { - oid: 'code2', - variableDescription: 'code2 desc', - variableCode: { - value: '00062' - } - }, - 'code3': { - oid: 'code3', - variableDescription: 'code3 desc', - variableCode: { - value: '00063' - } - } - } - }, - ivTimeSeriesState: { - currentIVVariableID: 'code0' - } - }); - // Series are ordered by parameter code and have expected values. - expect(available).toEqual([ - ['00060', {variableID: 'code0', description: 'code0 desc', selected: true, currentTimeSeriesCount: 1}], - ['00061', {variableID: 'code1', description: 'code1 desc', selected: false, currentTimeSeriesCount: 1}], - ['00062', {variableID: 'code2', description: 'code2 desc', selected: false, currentTimeSeriesCount: 1}] - ]); - }); - - it('time series without data points are considered available', () => { const available = getAvailableParameterCodes({ 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: []}, - 'current:00062': {description: '00062', tsKey: 'current:P7D', variable: 'code2', points: [{x: 3, y: 4}]}, - 'compare:00061': {description: '00061', tsKey: 'compare:P7D', variable: 'code1', points: []}, - 'compare:00062': {description: '00062', tsKey: 'compare:P7D', variable: 'code2', points: [{x: 2, y: 18}]}, - 'compare:00063': {description: '00063', tsKey: 'compare:P7D', variable: 'code3', points: [{x: 3, y: 46}]} + 'current:00062': {description: '00062', tsKey: 'current:P7D', variable: 'code2', points: [{x: 3, y: 4}]} }, variables: { 'code0': { @@ -159,9 +102,9 @@ describe('monitoring-location/components/hydrograph/selectors/parameter-data', ( }); // Series are ordered by parameter code and have expected values. expect(available).toEqual([ - ['00060', {variableID: 'code0', description: 'code0 desc', selected: true, currentTimeSeriesCount: 1}], - ['00061', {variableID: 'code1', description: 'code1 desc', selected: false, currentTimeSeriesCount: 1}], - ['00062', {variableID: 'code2', description: 'code2 desc', selected: false, currentTimeSeriesCount: 1}] + {variableID: 'code0', parameterCode: '00060', description: 'code0 desc', selected: true, timeSeriesCount: 1}, + {variableID: 'code1', parameterCode: '00061', description: 'code1 desc', selected: false, timeSeriesCount: 1}, + {variableID: 'code2', parameterCode: '00062', description: 'code2 desc', selected: false, timeSeriesCount: 1} ]); }); }); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/scales.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/scales.js index dc62f286f9927cb5b9648d02aa1232d4c5daa4ec..c7964147101c8ee8f83adb84939b49c9084b6e75 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/scales.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/scales.js @@ -5,7 +5,7 @@ import {createSelector} from 'reselect'; import {getVariables, getCurrentParmCd, getRequestTimeRange, getTimeSeriesForTsKey} from '../../../selectors/time-series-selector'; import {convertCelsiusToFahrenheit, convertFahrenheitToCelsius} from '../../../../utils'; -import {getYDomain, SYMLOG_PARMS} from './domain'; +import {getYDomain, getYDomainForVisiblePoints, SYMLOG_PARMS} from './domain'; import {getPointsByTsKey} from './drawing-data'; import {getLayout} from './layout'; import {TEMPERATURE_PARAMETERS} from './time-series-data'; @@ -105,7 +105,7 @@ export const getBrushXScale = (tsKey) => getXScale('BRUSH', tsKey); */ export const getYScale = memoize(kind => createSelector( getLayout(kind), - getYDomain, + getYDomainForVisiblePoints, getCurrentParmCd, (layout, yDomain, currentVarParmCd) => { return createYScale(currentVarParmCd, yDomain, layout.height - (layout.margin.top + layout.margin.bottom)); @@ -117,7 +117,7 @@ export const getBrushYScale = getYScale('BRUSH'); export const getSecondaryYScale = memoize(kind => createSelector( getLayout(kind), - getYDomain, + getYDomainForVisiblePoints, getCurrentParmCd, (layout, yDomain, currentVarParmCd) => { let convertedYDomain; diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.js index e0f13af46586f988c126ed3111920edf9d3e1b6e..6c48822aaf830fa1aff499a192f671411e5ffe6b 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.js @@ -39,14 +39,6 @@ const formatTime = function(timeInMillis, timeZone) { return DateTime.fromMillis(timeInMillis, {zone: timeZone}).toFormat('L/d/yyyy tt ZZZ'); }; - -export const hasTimeSeriesWithPoints = memoize((tsKey, period) => createSelector( - getTimeSeriesForTsKey(tsKey, period), - (timeSeries) => { - const seriesWithPoints = Object.values(timeSeries).filter(x => x.points.length > 0); - return seriesWithPoints.length > 0; -})); - /** * Factory function creates a function that: * Returns the current show state of a time series. diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.spec.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.spec.js index 31e5d442b88f8821578c64997ea25d88b385e50a..f7b59277acc423ff7a6aeef3af886b942c79b4ec 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.spec.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.spec.js @@ -1,5 +1,5 @@ import { - hasTimeSeriesWithPoints, isVisible, getYLabel, getTitle, + isVisible, getYLabel, getTitle, getDescription, getTsTimeZone, getSecondaryYLabel} from './time-series-data'; @@ -217,16 +217,6 @@ const TEST_DATA = { describe('monitoring-location/components/hydrograph/time-series module', () => { - describe('hasTimeSeriesWithPoints', () => { - it('Returns true if the time series for tsKey and period have non zero points', () => { - expect(hasTimeSeriesWithPoints('current')(TEST_DATA)).toBe(true); - expect(hasTimeSeriesWithPoints('current', 'P30D')(TEST_DATA)).toBe(true); - }); - it('Returns false if the times series for tsKey and period have zero time series', () => { - expect(hasTimeSeriesWithPoints('compare', 'P30D')(TEST_DATA)).toBe(false); - }); - }); - describe('isVisible', () => { it('Returns whether the time series is visible', () => { const store = { diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.js b/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.js index c0696481b32cdc4e13b4052674ac5fd93dd8bc55..c9e9a23faa46fa580c2bff267c76aee495e14e3a 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.js @@ -16,10 +16,10 @@ import { getCurrentVariableLineSegments, getCurrentVariableMedianStatPoints, HASH_ID -} from './drawing-data'; +} from './selectors/drawing-data'; import {getMainLayout} from './selectors/layout'; import {getMainXScale, getMainYScale, getBrushXScale} from './selectors/scales'; -import {descriptionSelector, isVisibleSelector, titleSelector} from './selectors/time-series-data'; +import {getDescription, isVisible, getTitle} from './selectors/time-series-data'; import {drawDataLines} from './time-series-lines'; import {drawTooltipFocus, drawTooltipText} from './tooltip'; @@ -162,7 +162,7 @@ const createTitle = function(elem, store, siteNo, showMLName) { titleDiv.append('div') .call(link(store,(elem, title) => { elem.html(title); - }, titleSelector)); + }, getTitle)); }; const watermark = function (elem, store) { @@ -221,8 +221,8 @@ export const drawTimeSeriesGraph = function(elem, store, siteNo, showMLName, sho .attr('height', layout.height - layout.margin.bottom); }, getMainLayout)) .call(link(store, addSVGAccessibility, createStructuredSelector({ - title: titleSelector, - description: descriptionSelector, + title: getTitle, + description: getDescription, isInteractive: () => true, idPrefix: () => 'hydrograph' }))) @@ -235,7 +235,7 @@ export const drawTimeSeriesGraph = function(elem, store, siteNo, showMLName, sho }, getMainLayout)) .call(link(store, appendAxes, getAxes())) .call(link(store, drawDataLines, createStructuredSelector({ - visible: isVisibleSelector('current'), + visible: isVisible('current'), tsLinesMap: getCurrentVariableLineSegments('current'), xScale: getMainXScale('current'), yScale: getMainYScale, @@ -243,7 +243,7 @@ export const drawTimeSeriesGraph = function(elem, store, siteNo, showMLName, sho enableClip: () => true }))) .call(link(store, drawDataLines, createStructuredSelector({ - visible: isVisibleSelector('compare'), + visible: isVisible('compare'), tsLinesMap: getCurrentVariableLineSegments('compare'), xScale: getMainXScale('compare'), yScale: getMainYScale, @@ -251,7 +251,7 @@ export const drawTimeSeriesGraph = function(elem, store, siteNo, showMLName, sho enableClip: () => true }))) .call(link(store, plotAllMedianPoints, createStructuredSelector({ - visible: isVisibleSelector('median'), + visible: isVisible('median'), xscale: getMainXScale('current'), yscale: getMainYScale, seriesPoints: getCurrentVariableMedianStatPoints diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/time-series-lines.js b/assets/src/scripts/monitoring-location/components/hydrograph/time-series-lines.js index 5dda146337091c1b85ac39522dc117d18faa172e..6a7dee73536e7fcde532369025e20e2e6f852a90 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/time-series-lines.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/time-series-lines.js @@ -1,7 +1,7 @@ import {extent} from 'd3-array'; import {line as d3Line} from 'd3-shape'; -import {HASH_ID, MASK_DESC} from './drawing-data'; +import {HASH_ID, MASK_DESC} from './selectors/drawing-data'; const CIRCLE_RADIUS_SINGLE_PT = 1; /* diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/tooltip.js b/assets/src/scripts/monitoring-location/components/hydrograph/tooltip.js index 10eb1ad81a1d5b92ed0758f4601788d711573388..d63d51fce1771ae7f6f23d2b70b6af439c416781 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/tooltip.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/tooltip.js @@ -14,7 +14,7 @@ import {getCurrentParmCd} from '../../selectors/time-series-selector'; import {Actions} from '../../store/instantaneous-value-time-series-state'; import {getCursorTime, getTsCursorPoints, getTooltipPoints} from './selectors/cursor'; -import {classesForPoint, MASK_DESC} from './drawing-data'; +import {classesForPoint, MASK_DESC} from './selectors/drawing-data'; import {getMainLayout} from './selectors/layout'; import {getMainXScale, getMainYScale} from './selectors/scales'; import {getTsTimeZone, getQualifiers, getCurrentVariableUnitCode, TEMPERATURE_PARAMETERS} from './selectors/time-series-data'; diff --git a/assets/src/scripts/monitoring-location/selectors/time-series-selector.js b/assets/src/scripts/monitoring-location/selectors/time-series-selector.js index 63a79853bb21dee57440790ac0066e07801fe9ff..01de48cfccba2f08e3bb6677614bbcd5b7cf6d50 100644 --- a/assets/src/scripts/monitoring-location/selectors/time-series-selector.js +++ b/assets/src/scripts/monitoring-location/selectors/time-series-selector.js @@ -25,9 +25,11 @@ export const getCurrentVariableID = state => state.ivTimeSeriesState.currentIVVa export const getCurrentMethodID = state => state.ivTimeSeriesState.currentIVMethodID; -export const getCurrentDateRangeKind = state => state.ivTimeSeriesState.currentIVDateRangeKind; +export const getCurrentDateRangeKind = (state) => { + return state.ivTimeSeriesState.currentIVDateRangeKind || null; +}; -export const getLoadingTsKeys = state => state.ivTimeSeriesState.loadingIVTSKeys; +export const getLoadingTsKeys = state => state.ivTimeSeriesState.loadingIVTSKeys || []; export const getNwisTimeZone = state => state.ivTimeSeriesData.timeZones || {};