import { useCallback, useMemo, useState } from 'react'; import { useToggle } from 'react-use'; import { DataFrame, EventBus, AbsoluteTimeRange, TimeZone, SplitOpen, LoadingState, ThresholdsConfig, TimeRange, } from '@grafana/data'; import { GraphThresholdsStyleConfig, PanelChrome, PanelChromeProps } from '@grafana/ui'; import { t, Trans } from 'app/core/internationalization'; import { ExploreGraphStyle } from 'app/types'; import { LimitedDataDisclaimer } from '../LimitedDataDisclaimer'; import { storeGraphStyle } from '../state/utils'; import { ExploreGraph } from './ExploreGraph'; import { ExploreGraphLabel } from './ExploreGraphLabel'; import { loadGraphStyle } from './utils'; const MAX_NUMBER_OF_TIME_SERIES = 20; interface Props extends Pick { width: number; height: number; data: DataFrame[]; annotations?: DataFrame[]; eventBus: EventBus; timeRange: TimeRange; timeZone: TimeZone; onChangeTime: (absoluteRange: AbsoluteTimeRange) => void; splitOpenFn: SplitOpen; loadingState: LoadingState; thresholdsConfig?: ThresholdsConfig; thresholdsStyle?: GraphThresholdsStyleConfig; } export const GraphContainer = ({ data, eventBus, height, width, timeRange, timeZone, annotations, onChangeTime, splitOpenFn, thresholdsConfig, thresholdsStyle, loadingState, statusMessage, }: Props) => { const [showAllSeries, toggleShowAllSeries] = useToggle(false); const [graphStyle, setGraphStyle] = useState(loadGraphStyle); const onGraphStyleChange = useCallback((graphStyle: ExploreGraphStyle) => { storeGraphStyle(graphStyle); setGraphStyle(graphStyle); }, []); const slicedData = useMemo(() => { return showAllSeries ? data : data.slice(0, MAX_NUMBER_OF_TIME_SERIES); }, [data, showAllSeries]); return ( Showing only {{ MAX_NUMBER_OF_TIME_SERIES }} series } buttonLabel={Show all {{ length: data.length }}} tooltip={t( 'graph.container.content', 'Rendering too many series in a single panel may impact performance and make data harder to read. Consider refining your queries.' )} /> ), ].filter(Boolean)} width={width} height={height} loadingState={loadingState} statusMessage={statusMessage} actions={} > {(innerWidth, innerHeight) => ( )} ); };