@ -1,6 +1,7 @@
import {
ArrayVector ,
DataFrame ,
DataFrameType ,
Field ,
FieldType ,
getDisplayProcessor ,
@ -14,6 +15,7 @@ import {
import { GraphFieldConfig , LineInterpolation } from '@grafana/schema' ;
import { applyNullInsertThreshold } from '@grafana/ui/src/components/GraphNG/nullInsertThreshold' ;
import { nullToValue } from '@grafana/ui/src/components/GraphNG/nullToValue' ;
import { partitionByValuesTransformer } from 'app/features/transformers/partitionByValues/partitionByValues' ;
/ * *
* Returns null if there are no graphable fields
@ -27,6 +29,10 @@ export function prepareGraphableFields(
return null ;
}
if ( series . every ( ( df ) = > df . meta ? . type === DataFrameType . TimeSeriesLong ) ) {
series = prepareTimeSeriesLong ( series ) ;
}
let copy : Field ;
const frames : DataFrame [ ] = [ ] ;
@ -173,3 +179,20 @@ export function regenerateLinksSupplier(
return alignedDataFrame ;
}
export function prepareTimeSeriesLong ( series : DataFrame [ ] ) : DataFrame [ ] {
// Transform each dataframe of the series
// to handle different field names in different frames
return series . reduce ( ( acc : DataFrame [ ] , dataFrame : DataFrame ) = > {
// these could be different in each frame
const stringFields = dataFrame . fields . filter ( ( field ) = > field . type === FieldType . string ) . map ( ( field ) = > field . name ) ;
// transform one dataFrame at a time and concat into DataFrame[]
const transformedSeries = partitionByValuesTransformer . transformer (
{ fields : stringFields } ,
{ interpolate : ( value : string ) = > value }
) ( [ dataFrame ] ) ;
return acc . concat ( transformedSeries ) ;
} , [ ] ) ;
}