From f0afdf09c5f2d552aa1e22df0ec66d952ad2613e Mon Sep 17 00:00:00 2001 From: Aaron Briggs <abriggs@contractor.usgs.gov> Date: Wed, 13 Jul 2022 10:01:53 -0500 Subject: [PATCH] combine y-scale methods --- .../components/hydrograph/selectors/axes.js | 6 ++-- .../components/hydrograph/selectors/scales.js | 34 +++++++------------ .../hydrograph/selectors/time-series-data.js | 8 ++++- .../hydrograph/time-series-graph.js | 4 +-- 4 files changed, 25 insertions(+), 27 deletions(-) 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 8d2dd14f2..6c1044452 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 4310e57fe..c4dc630a0 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 438042a54..8fa38151f 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 ff61065a7..9e9d25c90 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({ -- GitLab