grafana/public/app/plugins/panel/status-history/StatusHistoryPanel.tsx

71 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-05-19 23:38:31 -05:00
import React, { useMemo } from 'react';
import { PanelProps } from '@grafana/data';
2021-05-13 13:57:45 -05:00
import { useTheme2, ZoomPlugin } from '@grafana/ui';
import { StatusPanelOptions } from './types';
import { TimelineChart } from '../state-timeline/TimelineChart';
import { TimelineMode } from '../state-timeline/types';
2021-05-19 23:38:31 -05:00
import { prepareTimelineFields, prepareTimelineLegendItems } from '../state-timeline/utils';
interface TimelinePanelProps extends PanelProps<StatusPanelOptions> {}
/**
* @alpha
*/
export const StatusHistoryPanel: React.FC<TimelinePanelProps> = ({
2021-05-13 13:57:45 -05:00
data,
timeRange,
timeZone,
options,
width,
height,
onChangeTimeRange,
}) => {
const theme = useTheme2();
2021-05-19 23:38:31 -05:00
const { frames, warn } = useMemo(() => prepareTimelineFields(data?.series, false), [data]);
const legendItems = useMemo(() => prepareTimelineLegendItems(frames, options.legend, theme), [
frames,
options.legend,
theme,
]);
2021-05-19 23:38:31 -05:00
if (!frames || warn) {
return (
<div className="panel-empty">
2021-05-19 23:38:31 -05:00
<p>{warn ?? 'No data found in response'}</p>
</div>
);
}
// Status grid requires some space between values
if (frames[0].length > width / 2) {
return (
<div className="panel-empty">
<p>
Too many points to visualize properly. <br />
Update the query to return fewer points. <br />({frames[0].length} points recieved)
</p>
</div>
);
}
return (
<TimelineChart
theme={theme}
2021-05-19 23:38:31 -05:00
frames={frames}
structureRev={data.structureRev}
timeRange={timeRange}
timeZone={timeZone}
width={width}
height={height}
2021-05-19 23:38:31 -05:00
legendItems={legendItems}
{...options}
// hardcoded
mode={TimelineMode.Samples}
2021-05-13 13:57:45 -05:00
>
{(config) => <ZoomPlugin config={config} onZoom={onChangeTimeRange} />}
2021-05-13 13:57:45 -05:00
</TimelineChart>
);
};