Add logic to handle ranges that are submitted as equal

pull/10616/head
Andrew Watkins 2017-08-03 14:28:58 -07:00
parent 6a0a4fc4fa
commit 47b5f6cf4d
2 changed files with 16 additions and 7 deletions

View File

@ -23,6 +23,14 @@ describe('getRangeForDygraphSpec', () => {
expect(actual).to.deep.equal([0, 4])
})
it('does not use the user submitted range if they are equal', () => {
const timeSeries = [[date, min], [date, max], [date, mid]]
const providedRange = ['0', '0']
const actual = getRange(timeSeries, providedRange)
expect(actual).to.deep.equal([min, max])
})
it('gets the range for multiple timeSeries', () => {
const timeSeries = [[date, null, min], [date, max, mid], [date, null, mid]]
const actual = getRange(timeSeries)

View File

@ -1,6 +1,6 @@
const PADDING_FACTOR = 0.1
const considerZero = (userNumber, number) => {
const considerEmpty = (userNumber, number) => {
if (userNumber === '') {
return null
}
@ -20,10 +20,6 @@ const getRange = (
const {value, rangeValue, operator} = ruleValues
const [userMin, userMax] = userSelectedRange
if (userMin && userMax) {
return [considerZero(userMin), considerZero(userMax)]
}
const subtractPadding = val => +val - Math.abs(val * PADDING_FACTOR)
const addPadding = val => +val + Math.abs(val * PADDING_FACTOR)
@ -65,8 +61,9 @@ const getRange = (
[null, null]
)
// If time series is such that min and max are equal use Dygraph defaults
const [min, max] = range
// If time series is such that min and max are equal use Dygraph defaults
if (min === max) {
return [null, null]
}
@ -75,7 +72,11 @@ const getRange = (
return [min, max]
}
return [considerZero(userMin, min), considerZero(userMax, max)]
if (userMin && userMax) {
return [considerEmpty(userMin), considerEmpty(userMax)]
}
return [considerEmpty(userMin, min), considerEmpty(userMax, max)]
}
export default getRange