2022-08-03 21:47:09 +08:00
|
|
|
import React, { Component } from 'react';
|
2022-04-22 21:33:13 +08:00
|
|
|
|
2021-05-05 16:44:31 +08:00
|
|
|
import { DataFrame, TimeRange } from '@grafana/data';
|
2023-11-02 12:59:55 +08:00
|
|
|
import { PanelContextRoot } from '@grafana/ui/src/components/PanelChrome/PanelContext';
|
|
|
|
|
import { hasVisibleLegendSeries, PlotLegend } from '@grafana/ui/src/components/uPlot/PlotLegend';
|
|
|
|
|
import { UPlotConfigBuilder } from '@grafana/ui/src/components/uPlot/config/UPlotConfigBuilder';
|
|
|
|
|
import { withTheme2 } from '@grafana/ui/src/themes/ThemeContext';
|
2022-04-22 21:33:13 +08:00
|
|
|
|
2022-08-03 21:47:09 +08:00
|
|
|
import { GraphNG, GraphNGProps, PropDiffFn } from '../GraphNG/GraphNG';
|
2022-04-22 21:33:13 +08:00
|
|
|
|
|
|
|
|
import { preparePlotConfigBuilder } from './utils';
|
2021-05-05 16:44:31 +08:00
|
|
|
|
2022-12-02 18:55:18 +08:00
|
|
|
const propsToDiff: Array<string | PropDiffFn> = ['legend', 'options', 'theme'];
|
2021-05-05 16:44:31 +08:00
|
|
|
|
|
|
|
|
type TimeSeriesProps = Omit<GraphNGProps, 'prepConfig' | 'propsToDiff' | 'renderLegend'>;
|
|
|
|
|
|
2022-08-03 21:47:09 +08:00
|
|
|
export class UnthemedTimeSeries extends Component<TimeSeriesProps> {
|
2021-05-10 20:24:23 +08:00
|
|
|
static contextType = PanelContextRoot;
|
2023-10-24 18:53:22 +08:00
|
|
|
declare context: React.ContextType<typeof PanelContextRoot>;
|
2021-05-10 20:24:23 +08:00
|
|
|
|
2021-06-11 19:49:26 +08:00
|
|
|
prepConfig = (alignedFrame: DataFrame, allFrames: DataFrame[], getTimeRange: () => TimeRange) => {
|
2023-10-24 18:53:22 +08:00
|
|
|
const { eventBus, eventsScope, sync } = this.context;
|
2024-02-16 06:29:36 +08:00
|
|
|
const { theme, timeZone, options, renderers, tweakAxis, tweakScale } = this.props;
|
2021-08-28 01:30:42 +08:00
|
|
|
|
|
|
|
|
return preparePlotConfigBuilder({
|
|
|
|
|
frame: alignedFrame,
|
|
|
|
|
theme,
|
2022-08-19 22:59:56 +08:00
|
|
|
timeZones: Array.isArray(timeZone) ? timeZone : [timeZone],
|
2021-08-28 01:30:42 +08:00
|
|
|
getTimeRange,
|
|
|
|
|
eventBus,
|
|
|
|
|
sync,
|
|
|
|
|
allFrames,
|
2021-11-06 09:01:26 +08:00
|
|
|
renderers,
|
|
|
|
|
tweakScale,
|
|
|
|
|
tweakAxis,
|
2023-07-18 21:27:33 +08:00
|
|
|
eventsScope,
|
2024-02-16 06:29:36 +08:00
|
|
|
hoverProximity: options?.tooltip?.hoverProximity,
|
2024-02-29 16:53:00 +08:00
|
|
|
orientation: options?.orientation,
|
2021-08-28 01:30:42 +08:00
|
|
|
});
|
2021-05-05 16:44:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderLegend = (config: UPlotConfigBuilder) => {
|
2021-05-12 03:40:04 +08:00
|
|
|
const { legend, frames } = this.props;
|
2021-05-05 16:44:31 +08:00
|
|
|
|
2023-05-11 20:38:01 +08:00
|
|
|
if (!config || (legend && !legend.showLegend) || !hasVisibleLegendSeries(config, frames)) {
|
2021-05-12 03:40:04 +08:00
|
|
|
return null;
|
2021-05-05 16:44:31 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-11 23:42:07 +08:00
|
|
|
return <PlotLegend data={frames} config={config} {...legend} />;
|
2021-05-05 16:44:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<GraphNG
|
|
|
|
|
{...this.props}
|
|
|
|
|
prepConfig={this.prepConfig}
|
|
|
|
|
propsToDiff={propsToDiff}
|
2022-10-07 22:22:21 +08:00
|
|
|
renderLegend={this.renderLegend}
|
2021-05-05 16:44:31 +08:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const TimeSeries = withTheme2(UnthemedTimeSeries);
|
|
|
|
|
TimeSeries.displayName = 'TimeSeries';
|