import moment, {Moment} from 'moment'; import {Series} from 'sentry/types/echarts'; import {zeroFillSeries} from 'sentry/views/starfish/utils/zeroFillSeries'; export function queryDataToChartData( data: ({interval: string} & T)[], startTime: Moment, endTime: Moment, seriesOptions: Partial = {} ): Record { const series: Record = {}; if (data.length > 0) { Object.keys(data[0]) .filter(key => key !== 'interval') .forEach(key => { series[key] = {data: [], seriesName: `${key}()`, ...seriesOptions}; }); } data.forEach(point => { Object.keys(point).forEach(key => { if (key !== 'interval') { series[key].data.push({ name: point.interval, value: point[key], }); } }); }); Object.entries(series).forEach(([seriesKey, s]) => { series[seriesKey] = zeroFillSeries( s, moment.duration(12, 'hours'), startTime, endTime ); }); return series as Record; }