mirror of
https://github.com/grafana/grafana.git
synced 2025-08-03 03:13:49 +08:00
86 lines
2.2 KiB
TypeScript
86 lines
2.2 KiB
TypeScript
import React, { useCallback, useState } from 'react';
|
|
|
|
import {
|
|
DataFrame,
|
|
EventBus,
|
|
AbsoluteTimeRange,
|
|
TimeZone,
|
|
SplitOpen,
|
|
LoadingState,
|
|
ThresholdsConfig,
|
|
} from '@grafana/data';
|
|
import { GraphThresholdsStyleConfig, PanelChrome, PanelChromeProps } from '@grafana/ui';
|
|
import { ExploreGraphStyle } from 'app/types';
|
|
|
|
import { storeGraphStyle } from '../state/utils';
|
|
|
|
import { ExploreGraph } from './ExploreGraph';
|
|
import { ExploreGraphLabel } from './ExploreGraphLabel';
|
|
import { loadGraphStyle } from './utils';
|
|
|
|
interface Props extends Pick<PanelChromeProps, 'width' | 'height' | 'statusMessage'> {
|
|
loading: boolean;
|
|
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 [graphStyle, setGraphStyle] = useState(loadGraphStyle);
|
|
|
|
const onGraphStyleChange = useCallback((graphStyle: ExploreGraphStyle) => {
|
|
storeGraphStyle(graphStyle);
|
|
setGraphStyle(graphStyle);
|
|
}, []);
|
|
|
|
return (
|
|
<PanelChrome
|
|
title="Graph"
|
|
width={width}
|
|
height={height}
|
|
loadingState={loadingState}
|
|
statusMessage={statusMessage}
|
|
actions={<ExploreGraphLabel graphStyle={graphStyle} onChangeGraphStyle={onGraphStyleChange} />}
|
|
>
|
|
{(innerWidth, innerHeight) => (
|
|
<ExploreGraph
|
|
graphStyle={graphStyle}
|
|
data={data}
|
|
height={innerHeight}
|
|
width={innerWidth}
|
|
absoluteRange={absoluteRange}
|
|
onChangeTime={onChangeTime}
|
|
timeZone={timeZone}
|
|
annotations={annotations}
|
|
splitOpenFn={splitOpenFn}
|
|
loadingState={loadingState}
|
|
thresholdsConfig={thresholdsConfig}
|
|
thresholdsStyle={thresholdsStyle}
|
|
eventBus={eventBus}
|
|
/>
|
|
)}
|
|
</PanelChrome>
|
|
);
|
|
};
|