import React, { useMemo } from 'react'; import { Field, PanelProps } from '@grafana/data'; import { PanelDataErrorView } from '@grafana/runtime'; import { TooltipDisplayMode } from '@grafana/schema'; import { usePanelContext, TimeSeries, TooltipPlugin, ZoomPlugin, KeyboardPlugin } from '@grafana/ui'; import { config } from 'app/core/config'; import { getFieldLinksForExplore } from 'app/features/explore/utils/links'; import { AnnotationEditorPlugin } from './plugins/AnnotationEditorPlugin'; import { AnnotationsPlugin } from './plugins/AnnotationsPlugin'; import { ContextMenuPlugin } from './plugins/ContextMenuPlugin'; import { ExemplarsPlugin } from './plugins/ExemplarsPlugin'; import { OutsideRangePlugin } from './plugins/OutsideRangePlugin'; import { ThresholdControlsPlugin } from './plugins/ThresholdControlsPlugin'; import { TimeSeriesOptions } from './types'; import { prepareGraphableFields } from './utils'; interface TimeSeriesPanelProps extends PanelProps {} export const TimeSeriesPanel: React.FC = ({ data, timeRange, timeZone, width, height, options, fieldConfig, onChangeTimeRange, replaceVariables, id, }) => { const { sync, canAddAnnotations, onThresholdsChange, canEditThresholds, onSplitOpen } = usePanelContext(); const getFieldLinks = (field: Field, rowIndex: number) => { return getFieldLinksForExplore({ field, rowIndex, splitOpenFn: onSplitOpen, range: timeRange }); }; const frames = useMemo(() => prepareGraphableFields(data.series, config.theme2, timeRange), [data, timeRange]); if (!frames) { return ( ); } const enableAnnotationCreation = Boolean(canAddAnnotations && canAddAnnotations()); return ( {(config, alignedDataFrame) => { return ( <> {options.tooltip.mode === TooltipDisplayMode.None || ( )} {/* Renders annotation markers*/} {data.annotations && ( )} {/* Enables annotations creation*/} {enableAnnotationCreation ? ( {({ startAnnotating }) => { return ( { if (!p) { return; } startAnnotating({ coords: p.coords }); }, }, ], }, ]} /> ); }} ) : ( )} {data.annotations && ( )} {canEditThresholds && onThresholdsChange && ( )} ); }} ); };