import { css } from '@emotion/css'; import React, { useCallback, useMemo, useState } from 'react'; import { useToggle } from 'react-use'; import { DataFrame, EventBus, AbsoluteTimeRange, TimeZone, SplitOpen, LoadingState, ThresholdsConfig, GrafanaTheme2, } from '@grafana/data'; import { GraphThresholdsStyleConfig, PanelChrome, PanelChromeProps, Icon, Button, useStyles2, Tooltip, } from '@grafana/ui'; import { t, Trans } from 'app/core/internationalization'; import { ExploreGraphStyle } from 'app/types'; 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; absoluteRange: AbsoluteTimeRange; timeZone: TimeZone; onChangeTime: (absoluteRange: AbsoluteTimeRange) => void; splitOpenFn: SplitOpen; loadingState: LoadingState; thresholdsConfig?: ThresholdsConfig; thresholdsStyle?: GraphThresholdsStyleConfig; } export const GraphContainer = ({ data, eventBus, height, width, absoluteRange, timeZone, annotations, onChangeTime, splitOpenFn, thresholdsConfig, thresholdsStyle, loadingState, statusMessage, }: Props) => { const [showAllSeries, toggleShowAllSeries] = useToggle(false); const [graphStyle, setGraphStyle] = useState(loadGraphStyle); const styles = useStyles2(getStyles); 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 ( ), ].filter(Boolean)} width={width} height={height} loadingState={loadingState} statusMessage={statusMessage} actions={} > {(innerWidth, innerHeight) => ( )} ); }; const getStyles = (theme: GrafanaTheme2) => ({ timeSeriesDisclaimer: css({ label: 'time-series-disclaimer', display: 'flex', alignItems: 'center', gap: theme.spacing(1), }), warningMessage: css({ display: 'flex', alignItems: 'center', gap: theme.spacing(0.5), color: theme.colors.warning.main, fontSize: theme.typography.bodySmall.fontSize, }), });