Properly handle strings in data for line graphs
parent
ac788d1289
commit
782186d180
|
@ -1,3 +1,4 @@
|
||||||
|
import _ from 'lodash'
|
||||||
import React, {Component} from 'react'
|
import React, {Component} from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import Dygraph from 'shared/components/Dygraph'
|
import Dygraph from 'shared/components/Dygraph'
|
||||||
|
@ -9,15 +10,36 @@ import {colorsStringSchema} from 'shared/schemas'
|
||||||
import {ErrorHandlingWith} from 'src/shared/decorators/errors'
|
import {ErrorHandlingWith} from 'src/shared/decorators/errors'
|
||||||
import InvalidData from 'src/shared/components/InvalidData'
|
import InvalidData from 'src/shared/components/InvalidData'
|
||||||
|
|
||||||
|
const validateTimeSeries = timeseries => {
|
||||||
|
return _.every(timeseries, r =>
|
||||||
|
_.every(r, (v, i) => {
|
||||||
|
if (i === 0) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return _.isNumber(v) || _.isNull(v)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
@ErrorHandlingWith(InvalidData)
|
@ErrorHandlingWith(InvalidData)
|
||||||
class LineGraph extends Component {
|
class LineGraph extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
this.invalidData = false
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
const {data, isInDataExplorer} = this.props
|
const {data, isInDataExplorer} = this.props
|
||||||
|
this.parseTimeSeries(data, isInDataExplorer)
|
||||||
|
}
|
||||||
|
|
||||||
|
parseTimeSeries(data, isInDataExplorer) {
|
||||||
this._timeSeries = timeSeriesToDygraph(data, isInDataExplorer)
|
this._timeSeries = timeSeriesToDygraph(data, isInDataExplorer)
|
||||||
|
const valid = validateTimeSeries(_.get(this._timeSeries, 'timeSeries', []))
|
||||||
|
if (valid) {
|
||||||
|
this.invalidData = false
|
||||||
|
} else {
|
||||||
|
this.invalidData = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUpdate(nextProps) {
|
componentWillUpdate(nextProps) {
|
||||||
|
@ -26,14 +48,15 @@ class LineGraph extends Component {
|
||||||
data !== nextProps.data ||
|
data !== nextProps.data ||
|
||||||
activeQueryIndex !== nextProps.activeQueryIndex
|
activeQueryIndex !== nextProps.activeQueryIndex
|
||||||
) {
|
) {
|
||||||
this._timeSeries = timeSeriesToDygraph(
|
this.parseTimeSeries(nextProps.data, nextProps.isInDataExplorer)
|
||||||
nextProps.data,
|
|
||||||
nextProps.isInDataExplorer
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
if (this.invalidData) {
|
||||||
|
return <InvalidData />
|
||||||
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data,
|
data,
|
||||||
axes,
|
axes,
|
||||||
|
|
Loading…
Reference in New Issue