diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/axes.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/axes.js index 8d2dd14f2bef9915901bc4356bdc451a051166b9..6c10444522449963c93c26e8c8867e709d0a8a75 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/axes.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/axes.js @@ -9,7 +9,7 @@ import {getIVParameter} from 'ml/selectors/hydrograph-data-selector'; import {getSecondaryYAxisTickDetails, getPrimaryYAxisTickDetails} from './domain'; import {getLayout} from './layout'; -import {getXScale, getBrushXScale, getYScale, getSecondaryYScale} from './scales'; +import {getXScale, getBrushXScale, getYScale} from './scales'; import {getPrimaryParameter} from './time-series-data'; @@ -69,8 +69,8 @@ export const getBrushXAxis = createSelector( */ export const getAxes = memoize(graphKind => createSelector( getXScale(graphKind, 'current'), - getYScale(graphKind), - getSecondaryYScale(graphKind), + getYScale(graphKind, 'primary'), + getYScale(graphKind, 'secondary'), getPrimaryYAxisTickDetails, getSecondaryYAxisTickDetails, getLayout(graphKind), 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 4310e57fe45f867c7f6fb96612195e7caf0590fd..c4dc630a0bc9f9129ed30e3d7b7ab35d5f930f3e 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/scales.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/scales.js @@ -104,34 +104,26 @@ export const getBrushXScale = getXScale('BRUSH', 'current'); /** * Selector for y-scale + * @param {String} graphKind -- indicates if the y-scale (axis) will be used on the hydrograph ('MAIN') or the timeframe + * slider, AKA brush graph ('BRUSH') + * @param {String} dataKind -- indicates if the y-scale will be used with the primary y-axis ('primary') or secondary + * y-axis ('secondary'). If not provided, it is assumed to be 'primary' * @param {Object} state Redux store * @return {Function} D3 scale function */ -export const getYScale = memoize(graphKind => createSelector( +export const getYScale = memoize((graphKind, dataKind) => createSelector( getLayout(graphKind), getPrimaryValueRange, - getPrimaryParameter, - (layout, yDomain, parameter) => { - return createYScale(parameter ? parameter.parameterCode : '', yDomain, layout.height - (layout.margin.top + layout.margin.bottom)); - } -)); - -/** - * Selector for secondary y-scale - * @param {Object} state Redux store - * @return {Function} D3 scale function - */ -export const getSecondaryYScale = memoize(graphKind => createSelector( - getLayout(graphKind), getSecondaryValueRange, + getPrimaryParameter, getSelectedSecondaryParameterCode, - (layout, yDomain, secondaryParameterCode) => { - return createYScale(secondaryParameterCode ? secondaryParameterCode.parameterCode : '', yDomain, layout.height - (layout.margin.top + layout.margin.bottom)); + (layout, primaryYDomain, secondaryYDomain, primaryParameter, secondaryParameter) => { + const parameter = dataKind === 'secondary' ? secondaryParameter : primaryParameter; + const yDomain = dataKind === 'secondary' ? secondaryYDomain : primaryYDomain; + + return createYScale(parameter ? parameter.parameterCode : '', yDomain, layout.height - (layout.margin.top + layout.margin.bottom)); } )); - - - -export const getMainYScale = getYScale(); -export const getBrushYScale = getYScale('BRUSH'); +export const getMainYScale = getYScale('MAIN', 'primary'); +export const getBrushYScale = getYScale('BRUSH', 'primary'); 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 438042a54ff1b446d4899aca1f49c7bc1f70d3eb..8fa38151ff5c525c7f10fcd5a24f6a18b6d6860e 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 @@ -96,7 +96,13 @@ export const hasAnyVisibleData = createSelector( } ); - +/** + * A Redux selector function that returns the title of the main hydrograph. + * @param {String} titleKind -- is either the title for the primary data ('primary'), which is always shown (if available) + * or the secondary data ('secondary') if a secondary parameter is selected by the user. Defaults to 'primary' if argument + * is not explicitly included. + * @returns {String} - the primary or secondary title for the main hydrograph + */ export const getTitle = memoize(titleKind => createSelector( getPrimaryParameter, getSelectedPrimaryIVMethodID, 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 ff61065a74d26bb76241dfdd469c2a3500f04d3b..9e9d25c904bfda84b63cd929f7367ff465de2864 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 @@ -19,7 +19,7 @@ import {getGroundwaterLevelPoints} from './selectors/discrete-data'; import {getFloodLevelData} from './selectors/flood-level-data'; import {getIVDataSegments, HASH_ID} from './selectors/iv-data'; import {getMainLayout} from './selectors/layout'; -import {getMainXScale, getMainYScale, getSecondaryYScale} from './selectors/scales'; +import {getMainXScale, getMainYScale, getYScale} from './selectors/scales'; import { getTitle, getDescription, @@ -236,7 +236,7 @@ export const drawTimeSeriesGraphData = function(elem, store, showTooltip) { segments: getIVDataSegments('secondary'), dataKind: () => 'secondary', xScale: getMainXScale('current'), - yScale: getSecondaryYScale('MAIN'), + yScale: getYScale('MAIN', 'secondary'), enableClip: () => true }))) .call(link(store, drawDataSegments, createStructuredSelector({