mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 10:03:33 -06:00
* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import React, { useMemo } from 'react';
|
|
|
|
import { PanelProps, buildHistogram, getHistogramFields } from '@grafana/data';
|
|
import { histogramFieldsToFrame } from '@grafana/data/src/transformations/transformers/histogram';
|
|
import { useTheme2 } from '@grafana/ui';
|
|
|
|
import { Histogram, getBucketSize } from './Histogram';
|
|
import { PanelOptions } from './models.gen';
|
|
|
|
type Props = PanelProps<PanelOptions>;
|
|
|
|
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;
|
|
}
|
|
|
|
return histogramFieldsToFrame(hist, theme);
|
|
}, [data.series, options, theme]);
|
|
|
|
if (!histogram || !histogram.fields.length) {
|
|
return (
|
|
<div className="panel-empty">
|
|
<p>No histogram found in response</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const bucketSize = getBucketSize(histogram);
|
|
|
|
return (
|
|
<Histogram
|
|
options={options}
|
|
theme={theme}
|
|
legend={options.legend}
|
|
structureRev={data.structureRev}
|
|
width={width}
|
|
height={height}
|
|
alignedFrame={histogram}
|
|
bucketSize={bucketSize}
|
|
>
|
|
{(config, alignedFrame) => {
|
|
return null; // <TooltipPlugin data={alignedFrame} config={config} mode={options.tooltip.mode} timeZone={timeZone} />;
|
|
}}
|
|
</Histogram>
|
|
);
|
|
};
|