DataFrame: Add explicit histogram frame type (panel & transforms) (#61195)

This commit is contained in:
Leon Sorokin
2023-01-10 17:42:45 -06:00
committed by GitHub
parent 86b5fbbf60
commit be1c5e13d5
7 changed files with 865 additions and 467 deletions

View File

@@ -175,7 +175,7 @@ const prepConfig = (frame: DataFrame, theme: GrafanaTheme2) => {
let seriesIndex = 0;
// assumes BucketMax is [1]
// assumes xMin is [0], xMax is [1]
for (let i = 2; i < frame.fields.length; i++) {
const field = frame.fields[i];
@@ -209,10 +209,7 @@ const prepConfig = (frame: DataFrame, theme: GrafanaTheme2) => {
softMax: customConfig.axisSoftMax,
// The following properties are not used in the uPlot config, but are utilized as transport for legend config
dataFrameFieldIndex: {
fieldIndex: 1,
frameIndex: i - 2,
},
dataFrameFieldIndex: field.state.origin,
});
}
@@ -272,11 +269,12 @@ export class Histogram extends React.Component<HistogramProps, State> {
renderLegend(config: UPlotConfigBuilder) {
const { legend } = this.props;
if (!config || legend.showLegend === false || !this.props.rawSeries) {
if (!config || legend.showLegend === false) {
return null;
}
return <PlotLegend data={this.props.rawSeries} config={config} maxHeight="35%" maxWidth="60%" {...legend} />;
return <PlotLegend data={this.props.rawSeries!} config={config} maxHeight="35%" maxWidth="60%" {...legend} />;
}
componentDidUpdate(prevProps: HistogramProps) {

View File

@@ -16,6 +16,20 @@ export const HistogramPanel = ({ data, options, width, height }: Props) => {
if (!data?.series?.length) {
return undefined;
}
// stamp origins for legend's calcs (from raw values)
data.series.forEach((frame, frameIndex) => {
frame.fields.forEach((field, fieldIndex) => {
field.state = {
...field.state,
origin: {
frameIndex,
fieldIndex,
},
};
});
});
if (data.series.length === 1) {
const info = getHistogramFields(data.series[0]);
if (info) {

View File

@@ -1,7 +1,7 @@
import { DataFrame, FieldType } from '@grafana/data';
import {
histogramFrameBucketMinFieldName,
histogramFrameBucketMaxFieldName,
isHistogramFrameBucketMinFieldName,
isHistogramFrameBucketMaxFieldName,
} from '@grafana/data/src/transformations/transformers/histogram';
export function originalDataHasHistogram(frames?: DataFrame[]): boolean {
@@ -14,8 +14,8 @@ export function originalDataHasHistogram(frames?: DataFrame[]): boolean {
}
if (
frame.fields[0].name !== histogramFrameBucketMinFieldName ||
frame.fields[1].name !== histogramFrameBucketMaxFieldName
!isHistogramFrameBucketMinFieldName(frame.fields[0].name) ||
!isHistogramFrameBucketMaxFieldName(frame.fields[1].name)
) {
return false;
}