Skip to content
Snippets Groups Projects

WDFN - 710 - Inverting the DV graph for certain parameter codes

Merged Williams, Darius Shamar requested to merge dswilliams/waterdataui:wdfn-710 into main
All threads resolved!
Files
8
import {scaleLinear} from 'd3-scale';
import memoize from 'fast-memoize';
import {createSelector} from 'reselect';
import config from 'ui/config.js';
import {
getDVGraphBrushOffset,
getCurrentDVTimeSeriesTimeRange,
getCurrentDVTimeSeriesValueRange,
getCurrentDVTimeSeriesData
getCurrentDVTimeSeriesData,
getCurrentDVTimeSeriesParameterCodes
} from 'ml/selectors/daily-value-time-series-selector';
import {getLayout} from './layout';
/*
* Returns a selector function which returns a d3 scale for either the brush,
* kind = 'BRUSH' or the main xscale for the dv graph.
@@ -35,10 +38,20 @@ export const getXScale = memoize((kind) => createSelector(
export const getMainXScale = getXScale();
export const getBrushXScale = getXScale('BRUSH');
const createYScale = function(layout, valueRange) {
const createYScale = function(layout, valueRange, parameterCodes) {
const PADDING_RATIO = 0.2;
let yScale = scaleLinear();
yScale.range([layout.height - layout.margin.top - layout.margin.bottom, 0]);
let reverse = false;
parameterCodes.forEach((parameterCode) => {
if (config.REVERSE_AXIS_PARMS.includes(parameterCode)) {
reverse = true;
}
});
if (reverse) {
yScale.range([0, layout.height - layout.margin.top - layout.margin.bottom]);
} else {
yScale.range([layout.height - layout.margin.top - layout.margin.bottom, 0]);
}
if (valueRange) {
const isPositive = valueRange.min > 0 && valueRange.max > 0;
@@ -66,7 +79,8 @@ export const getMainYScale = createSelector(
getLayout('MAIN'),
getCurrentDVTimeSeriesData,
getXScale('MAIN'),
(layout, allTSData, xScale) => {
getCurrentDVTimeSeriesParameterCodes,
(layout, allTSData, xScale, parameterCodes) => {
const [startTime, endTime] = xScale.domain();
let minValues = [];
let maxValues = [];
@@ -88,7 +102,7 @@ export const getMainYScale = createSelector(
max: Math.max(...maxValues)
};
}
return createYScale(layout, valueRange);
return createYScale(layout, valueRange, parameterCodes);
}
);
@@ -98,8 +112,9 @@ export const getMainYScale = createSelector(
export const getBrushYScale = createSelector(
getLayout('BRUSH'),
getCurrentDVTimeSeriesValueRange,
(layout, valueRange) => {
return createYScale(layout, valueRange);
getCurrentDVTimeSeriesParameterCodes,
(layout, valueRange, parameterCodes) => {
return createYScale(layout, valueRange, parameterCodes);
}
);
Loading