2021-05-10 14:00:59 -05:00
|
|
|
import React, { useMemo } from 'react';
|
|
|
|
import { PanelProps, buildHistogram, getHistogramFields } from '@grafana/data';
|
|
|
|
|
|
|
|
import { Histogram } from './Histogram';
|
|
|
|
import { PanelOptions } from './models.gen';
|
|
|
|
import { useTheme2 } from '@grafana/ui';
|
|
|
|
|
|
|
|
type Props = PanelProps<PanelOptions>;
|
|
|
|
|
|
|
|
import { histogramFieldsToFrame } from '@grafana/data/src/transformations/transformers/histogram';
|
|
|
|
|
|
|
|
export const HistogramPanel: React.FC<Props> = ({ data, options, width, height }) => {
|
|
|
|
const theme = useTheme2();
|
|
|
|
|
|
|
|
const histogram = useMemo(() => {
|
|
|
|
if (!data?.series?.length) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
if (data.series.length === 1) {
|
|
|
|
const info = getHistogramFields(data.series[0]);
|
|
|
|
if (info) {
|
|
|
|
return histogramFieldsToFrame(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const hist = buildHistogram(data.series, options);
|
|
|
|
if (!hist) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2021-05-19 19:13:17 -05:00
|
|
|
|
2021-05-10 14:00:59 -05:00
|
|
|
return histogramFieldsToFrame(hist);
|
|
|
|
}, [data.series, options]);
|
|
|
|
|
|
|
|
if (!histogram || !histogram.fields.length) {
|
|
|
|
return (
|
|
|
|
<div className="panel-empty">
|
|
|
|
<p>No histogram found in response</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Histogram
|
|
|
|
options={options}
|
|
|
|
theme={theme}
|
2021-05-19 19:13:17 -05:00
|
|
|
legend={options.legend}
|
2021-05-10 14:00:59 -05:00
|
|
|
structureRev={data.structureRev}
|
|
|
|
width={width}
|
|
|
|
height={height}
|
|
|
|
alignedFrame={histogram}
|
2021-05-19 19:13:17 -05:00
|
|
|
>
|
|
|
|
{(config, alignedFrame) => {
|
|
|
|
return null; // <TooltipPlugin data={alignedFrame} config={config} mode={options.tooltip.mode} timeZone={timeZone} />;
|
|
|
|
}}
|
|
|
|
</Histogram>
|
2021-05-10 14:00:59 -05:00
|
|
|
);
|
|
|
|
};
|