Skip to content

Commit

Permalink
Merge pull request #5821 from influxdata/5820/no_data_chart
Browse files Browse the repository at this point in the history
fix(ui/flux): skip missing values in line chart instead of returning zeros
  • Loading branch information
sranka authored Sep 30, 2021
2 parents d2c6209 + 0f2c011 commit 9e29f95
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
1. [#5810](https://github.com/influxdata/chronograf/pull/5810): Repair calculation of flux query range duration.
1. [#5815](https://github.com/influxdata/chronograf/pull/5815): Update time range of flux queries on dashboard zoom.
1. [#5818](https://github.com/influxdata/chronograf/pull/5818): Support Firefox private mode.

1. [#5821](https://github.com/influxdata/chronograf/pull/5821): Skip missing values in line chart instead of returning zeros.

### Other

Expand Down
2 changes: 1 addition & 1 deletion ui/src/worker/jobs/fluxTablesToDygraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const fluxTablesToDygraphWork = (

for (const [seriesName, value] of Object.entries(values)) {
const i = allColumnNames.indexOf(seriesName) + DATE_INDEX_OFFSET
dygraphValuesByTime[date][i] = Number(value)
dygraphValuesByTime[date][i] = value === '' ? null : Number(value)
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions ui/test/shared/parsing/flux/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,14 @@ export const ERROR_RESPONSE = `#datatype,string,string
#default,,
,error,reference
,${ERROR}`

export const WINDOWED_WITH_EMPTY = `
#group,false,false,true,true,false,false,true,true
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string
#default,_result,,,,,,,
,result,table,_start,_stop,_time,_value,_field,_measurement
,,0,2020-12-31T23:00:00Z,2021-01-01T04:00:00Z,2021-01-01T02:44:10Z,,value,temperature2
,,0,2020-12-31T23:00:00Z,2021-01-01T04:00:00Z,2021-01-01T02:45:00Z,22,value,temperature2
,,0,2020-12-31T23:00:00Z,2021-01-01T04:00:00Z,2021-01-01T02:45:50Z,,value,temperature2
,,0,2020-12-31T23:00:00Z,2021-01-01T04:00:00Z,2021-01-01T02:46:40Z,23,value,temperature2
,,0,2020-12-31T23:00:00Z,2021-01-01T04:00:00Z,2021-01-01T02:47:30Z,,value,temperature2`
14 changes: 14 additions & 0 deletions ui/test/shared/parsing/flux/dygraph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
MISMATCHED,
MULTI_VALUE_ROW,
MIXED_DATATYPES,
WINDOWED_WITH_EMPTY,
} from 'test/shared/parsing/flux/constants'

describe('fluxTablesToDygraph', () => {
Expand Down Expand Up @@ -70,4 +71,17 @@ describe('fluxTablesToDygraph', () => {
}
expect(actual).toEqual(expected)
})
it('returns null if value is not available', () => {
const fluxTables = parseResponse(WINDOWED_WITH_EMPTY)
const actual = fluxTablesToDygraph(fluxTables)
const expected = [
[new Date('2021-01-01T02:44:10Z'), null],
[new Date('2021-01-01T02:45:00Z'), 22],
[new Date('2021-01-01T02:45:50Z'), null],
[new Date('2021-01-01T02:46:40Z'), 23],
[new Date('2021-01-01T02:47:30Z'), null],
]

expect(actual.dygraphsData).toEqual(expected)
})
})

0 comments on commit 9e29f95

Please sign in to comment.