TSify timeSerieToDygraph function

pull/10616/head
ebb-tide 2018-05-16 16:15:00 -07:00
parent 76fc779467
commit 4ed8542fe7
1 changed files with 15 additions and 12 deletions

View File

@ -4,6 +4,8 @@ import {groupByTimeSeriesTransform} from 'src/utils/groupByTimeSeriesTransform'
import {TimeSeriesServerResponse, TimeSeries} from 'src/types/series'
import {TimeSeriesValue} from 'src/types/series'
type DygraphValue = string | number | Date | null
interface Label {
label: string
seriesIndex: number
@ -12,7 +14,7 @@ interface Label {
interface TimeSeriesToDyGraphReturnType {
labels: string[]
timeSeries: TimeSeries[]
timeSeries: DygraphValue[][]
dygraphSeries: DygraphSeries
}
@ -37,6 +39,16 @@ export const timeSeriesToDygraph = (
isTable
)
const labels = [
'time',
...fastMap<Label, string>(sortedLabels, ({label}) => label),
]
const timeSeries = fastMap<TimeSeries, DygraphValue[]>(
sortedTimeSeries,
({time, values}) => [new Date(time), ...values]
)
const dygraphSeries = fastReduce<Label, DygraphSeries>(
sortedLabels,
(acc, {label, responseIndex}) => {
@ -49,17 +61,8 @@ export const timeSeriesToDygraph = (
},
{}
)
return {
labels: [
'time',
...fastMap<Label, string>(sortedLabels, ({label}) => label),
],
timeSeries: fastMap<TimeSeries, TimeSeries>(
sortedTimeSeries,
({time, values}) => [new Date(time), ...values]
),
dygraphSeries,
}
return {labels, timeSeries, dygraphSeries}
}
export const timeSeriesToTableGraph = (