Add logic to handle ranges that are submitted as equal
parent
6a0a4fc4fa
commit
47b5f6cf4d
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue