From 15e41284e3d9d637b8cac9b12ee1e79540f64760 Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Mon, 24 Jul 2017 11:31:32 -0700 Subject: [PATCH] Handle user submitted zero --- ui/spec/shared/parsing/getRangeForDygraphSpec.js | 2 +- ui/src/shared/parsing/getRangeForDygraph.js | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ui/spec/shared/parsing/getRangeForDygraphSpec.js b/ui/spec/shared/parsing/getRangeForDygraphSpec.js index d467a7c79f..2cec89bcfe 100644 --- a/ui/spec/shared/parsing/getRangeForDygraphSpec.js +++ b/ui/spec/shared/parsing/getRangeForDygraphSpec.js @@ -6,7 +6,7 @@ const mid = 10 const min = 5 const kapacitor = {value: null, rangeValue: null, operator: null} -describe('getRangeForDygraphSpec', () => { +describe.only('getRangeForDygraphSpec', () => { it('gets the range for one timeSeries', () => { const timeSeries = [[date, min], [date, mid], [date, max]] const actual = getRange(timeSeries) diff --git a/ui/src/shared/parsing/getRangeForDygraph.js b/ui/src/shared/parsing/getRangeForDygraph.js index 6a162708d0..2f2561e1b2 100644 --- a/ui/src/shared/parsing/getRangeForDygraph.js +++ b/ui/src/shared/parsing/getRangeForDygraph.js @@ -1,10 +1,18 @@ const PADDING_FACTOR = 0.1 -export default function getRange( +const considerZero = (userNumber, number) => { + if (typeof userNumber === 'number') { + return userNumber + } + + return number +} + +const getRange = ( timeSeries, userSelectedRange = [null, null], ruleValues = {value: null, rangeValue: null} -) { +) => { const {value, rangeValue, operator} = ruleValues const subtractPadding = val => +val - Math.abs(val * PADDING_FACTOR) @@ -56,5 +64,7 @@ export default function getRange( const [userMin, userMax] = userSelectedRange const [min, max] = range - return [+userMin || min, +userMax || max] + return [considerZero(userMin, min), considerZero(userMax, max)] } + +export default getRange