2021-05-17 11:52:47 -05:00
|
|
|
import { DashboardCursorSync, Field, PanelProps } from '@grafana/data';
|
|
|
|
import { config } from '@grafana/runtime';
|
2021-05-10 07:24:23 -05:00
|
|
|
import { TooltipDisplayMode, usePanelContext, TimeSeries, TooltipPlugin, ZoomPlugin } from '@grafana/ui';
|
2021-01-15 09:20:20 -06:00
|
|
|
import { getFieldLinksForExplore } from 'app/features/explore/utils/links';
|
2021-05-17 11:52:47 -05:00
|
|
|
import React, { useMemo } from 'react';
|
2020-10-06 04:39:06 -05:00
|
|
|
import { AnnotationsPlugin } from './plugins/AnnotationsPlugin';
|
2020-12-15 03:53:04 -06:00
|
|
|
import { ContextMenuPlugin } from './plugins/ContextMenuPlugin';
|
2021-01-15 09:20:20 -06:00
|
|
|
import { ExemplarsPlugin } from './plugins/ExemplarsPlugin';
|
2021-05-11 08:46:12 -05:00
|
|
|
import { TimeSeriesOptions } from './types';
|
2021-05-17 11:52:47 -05:00
|
|
|
import { prepareGraphableFields } from './utils';
|
2020-09-29 06:25:10 -05:00
|
|
|
|
2021-05-11 08:46:12 -05:00
|
|
|
interface TimeSeriesPanelProps extends PanelProps<TimeSeriesOptions> {}
|
2020-09-24 09:44:35 -05:00
|
|
|
|
2021-01-08 13:06:52 -06:00
|
|
|
export const TimeSeriesPanel: React.FC<TimeSeriesPanelProps> = ({
|
2020-09-24 09:44:35 -05:00
|
|
|
data,
|
|
|
|
timeRange,
|
|
|
|
timeZone,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
options,
|
|
|
|
onChangeTimeRange,
|
2020-12-15 06:29:37 -06:00
|
|
|
replaceVariables,
|
2020-09-24 09:44:35 -05:00
|
|
|
}) => {
|
2021-05-12 07:14:39 -05:00
|
|
|
const { sync } = usePanelContext();
|
|
|
|
|
2021-01-15 09:20:20 -06:00
|
|
|
const getFieldLinks = (field: Field, rowIndex: number) => {
|
|
|
|
return getFieldLinksForExplore({ field, rowIndex, range: timeRange });
|
|
|
|
};
|
|
|
|
|
2021-05-17 11:52:47 -05:00
|
|
|
const { frames, warn } = useMemo(() => prepareGraphableFields(data?.series, config.theme2), [data]);
|
2021-02-15 09:46:29 -06:00
|
|
|
|
2021-05-17 11:52:47 -05:00
|
|
|
if (!frames || warn) {
|
2021-05-12 07:14:39 -05:00
|
|
|
return (
|
|
|
|
<div className="panel-empty">
|
2021-05-17 11:52:47 -05:00
|
|
|
<p>{warn ?? 'No data found in response'}</p>
|
2021-05-12 07:14:39 -05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-24 09:44:35 -05:00
|
|
|
return (
|
2021-05-05 03:44:31 -05:00
|
|
|
<TimeSeries
|
2021-05-17 11:52:47 -05:00
|
|
|
frames={frames}
|
2021-04-20 04:05:50 -05:00
|
|
|
structureRev={data.structureRev}
|
2020-11-09 08:31:03 -06:00
|
|
|
timeRange={timeRange}
|
|
|
|
timeZone={timeZone}
|
|
|
|
width={width}
|
2020-11-13 10:08:55 -06:00
|
|
|
height={height}
|
2020-11-09 08:31:03 -06:00
|
|
|
legend={options.legend}
|
|
|
|
>
|
2021-04-26 06:30:04 -05:00
|
|
|
{(config, alignedDataFrame) => {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<ZoomPlugin config={config} onZoom={onChangeTimeRange} />
|
|
|
|
<TooltipPlugin
|
|
|
|
data={alignedDataFrame}
|
|
|
|
config={config}
|
2021-05-11 08:46:12 -05:00
|
|
|
mode={sync === DashboardCursorSync.Tooltip ? TooltipDisplayMode.Multi : options.tooltip.mode}
|
2021-04-26 06:30:04 -05:00
|
|
|
timeZone={timeZone}
|
|
|
|
/>
|
|
|
|
<ContextMenuPlugin
|
|
|
|
data={alignedDataFrame}
|
|
|
|
config={config}
|
|
|
|
timeZone={timeZone}
|
|
|
|
replaceVariables={replaceVariables}
|
|
|
|
/>
|
|
|
|
{data.annotations && (
|
|
|
|
<AnnotationsPlugin annotations={data.annotations} config={config} timeZone={timeZone} />
|
|
|
|
)}
|
|
|
|
|
|
|
|
{data.annotations && (
|
|
|
|
<ExemplarsPlugin
|
|
|
|
config={config}
|
|
|
|
exemplars={data.annotations}
|
|
|
|
timeZone={timeZone}
|
|
|
|
getFieldLinks={getFieldLinks}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}}
|
2021-05-05 03:44:31 -05:00
|
|
|
</TimeSeries>
|
2020-09-24 09:44:35 -05:00
|
|
|
);
|
|
|
|
};
|