mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
57 lines
1.4 KiB
TypeScript
Executable File
57 lines
1.4 KiB
TypeScript
Executable File
import React, { useCallback } from 'react';
|
|
import { PanelProps } from '@grafana/data';
|
|
import { Timeline, GraphNGLegendEvent, TimelineOptions } from '@grafana/ui';
|
|
import { changeSeriesColorConfigFactory } from '../timeseries/overrides/colorSeriesConfigFactory';
|
|
import { hideSeriesConfigFactory } from '../timeseries/overrides/hideSeriesConfigFactory';
|
|
|
|
interface TimelinePanelProps extends PanelProps<TimelineOptions> {}
|
|
|
|
/**
|
|
* @alpha
|
|
*/
|
|
export const TimelinePanel: React.FC<TimelinePanelProps> = ({
|
|
data,
|
|
timeRange,
|
|
timeZone,
|
|
options,
|
|
width,
|
|
height,
|
|
fieldConfig,
|
|
onFieldConfigChange,
|
|
}) => {
|
|
const onLegendClick = useCallback(
|
|
(event: GraphNGLegendEvent) => {
|
|
onFieldConfigChange(hideSeriesConfigFactory(event, fieldConfig, data.series));
|
|
},
|
|
[fieldConfig, onFieldConfigChange, data.series]
|
|
);
|
|
|
|
const onSeriesColorChange = useCallback(
|
|
(label: string, color: string) => {
|
|
onFieldConfigChange(changeSeriesColorConfigFactory(label, color, fieldConfig));
|
|
},
|
|
[fieldConfig, onFieldConfigChange]
|
|
);
|
|
|
|
if (!data || !data.series?.length) {
|
|
return (
|
|
<div className="panel-empty">
|
|
<p>No data found in response</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Timeline
|
|
data={data.series}
|
|
timeRange={timeRange}
|
|
timeZone={timeZone}
|
|
width={width}
|
|
height={height}
|
|
onLegendClick={onLegendClick}
|
|
onSeriesColorChange={onSeriesColorChange}
|
|
{...options}
|
|
/>
|
|
);
|
|
};
|