mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
PanelContext: Provide events scope identifier (#71561)
* PanelContext: Provide events scope identifier * What a console log
This commit is contained in:
parent
18b910e654
commit
34c9faf140
@ -17,6 +17,8 @@ import { SeriesVisibilityChangeMode } from '.';
|
|||||||
|
|
||||||
/** @alpha */
|
/** @alpha */
|
||||||
export interface PanelContext {
|
export interface PanelContext {
|
||||||
|
/** Identifier for the events scope */
|
||||||
|
eventsScope: string;
|
||||||
eventBus: EventBus;
|
eventBus: EventBus;
|
||||||
|
|
||||||
/** Dashboard panels sync */
|
/** Dashboard panels sync */
|
||||||
@ -92,6 +94,7 @@ export interface PanelContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const PanelContextRoot = React.createContext<PanelContext>({
|
export const PanelContextRoot = React.createContext<PanelContext>({
|
||||||
|
eventsScope: 'global',
|
||||||
eventBus: new EventBusSrv(),
|
eventBus: new EventBusSrv(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ export class UnthemedTimeSeries extends Component<TimeSeriesProps> {
|
|||||||
panelContext: PanelContext = {} as PanelContext;
|
panelContext: PanelContext = {} as PanelContext;
|
||||||
|
|
||||||
prepConfig = (alignedFrame: DataFrame, allFrames: DataFrame[], getTimeRange: () => TimeRange) => {
|
prepConfig = (alignedFrame: DataFrame, allFrames: DataFrame[], getTimeRange: () => TimeRange) => {
|
||||||
const { eventBus, sync } = this.context as PanelContext;
|
const { eventBus, eventsScope, sync } = this.context as PanelContext;
|
||||||
const { theme, timeZone, renderers, tweakAxis, tweakScale } = this.props;
|
const { theme, timeZone, renderers, tweakAxis, tweakScale } = this.props;
|
||||||
|
|
||||||
return preparePlotConfigBuilder({
|
return preparePlotConfigBuilder({
|
||||||
@ -33,6 +33,7 @@ export class UnthemedTimeSeries extends Component<TimeSeriesProps> {
|
|||||||
renderers,
|
renderers,
|
||||||
tweakScale,
|
tweakScale,
|
||||||
tweakAxis,
|
tweakAxis,
|
||||||
|
eventsScope,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -87,6 +87,7 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<{
|
|||||||
renderers,
|
renderers,
|
||||||
tweakScale = (opts) => opts,
|
tweakScale = (opts) => opts,
|
||||||
tweakAxis = (opts) => opts,
|
tweakAxis = (opts) => opts,
|
||||||
|
eventsScope = '__global_',
|
||||||
}) => {
|
}) => {
|
||||||
const builder = new UPlotConfigBuilder(timeZones[0]);
|
const builder = new UPlotConfigBuilder(timeZones[0]);
|
||||||
|
|
||||||
@ -598,9 +599,10 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<{
|
|||||||
},
|
},
|
||||||
data: frame,
|
data: frame,
|
||||||
};
|
};
|
||||||
|
|
||||||
const hoverEvent = new DataHoverEvent(payload);
|
const hoverEvent = new DataHoverEvent(payload);
|
||||||
cursor.sync = {
|
cursor.sync = {
|
||||||
key: '__global_',
|
key: eventsScope,
|
||||||
filters: {
|
filters: {
|
||||||
pub: (type: string, src: uPlot, x: number, y: number, w: number, h: number, dataIdx: number) => {
|
pub: (type: string, src: uPlot, x: number, y: number, w: number, h: number, dataIdx: number) => {
|
||||||
if (sync && sync() === DashboardCursorSync.Off) {
|
if (sync && sync() === DashboardCursorSync.Off) {
|
||||||
|
@ -305,6 +305,8 @@ type UPlotConfigPrepOpts<T extends Record<string, any> = {}> = {
|
|||||||
renderers?: Renderers;
|
renderers?: Renderers;
|
||||||
tweakScale?: (opts: ScaleProps, forField: Field) => ScaleProps;
|
tweakScale?: (opts: ScaleProps, forField: Field) => ScaleProps;
|
||||||
tweakAxis?: (opts: AxisProps, forField: Field) => AxisProps;
|
tweakAxis?: (opts: AxisProps, forField: Field) => AxisProps;
|
||||||
|
// Identifies the shared key for uPlot cursor sync
|
||||||
|
eventsScope?: string;
|
||||||
} & T;
|
} & T;
|
||||||
|
|
||||||
/** @alpha */
|
/** @alpha */
|
||||||
|
@ -61,6 +61,8 @@ interface UPlotConfigOptions {
|
|||||||
alignValue?: TimelineValueAlignment;
|
alignValue?: TimelineValueAlignment;
|
||||||
mergeValues?: boolean;
|
mergeValues?: boolean;
|
||||||
getValueColor: (frameIdx: number, fieldIdx: number, value: unknown) => string;
|
getValueColor: (frameIdx: number, fieldIdx: number, value: unknown) => string;
|
||||||
|
// Identifies the shared key for uPlot cursor sync
|
||||||
|
eventsScope?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,6 +104,7 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<UPlotConfigOptions> = (
|
|||||||
alignValue,
|
alignValue,
|
||||||
mergeValues,
|
mergeValues,
|
||||||
getValueColor,
|
getValueColor,
|
||||||
|
eventsScope = '__global_',
|
||||||
}) => {
|
}) => {
|
||||||
const builder = new UPlotConfigBuilder(timeZones[0]);
|
const builder = new UPlotConfigBuilder(timeZones[0]);
|
||||||
|
|
||||||
@ -283,7 +286,7 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<UPlotConfigOptions> = (
|
|||||||
let cursor: Partial<uPlot.Cursor> = {};
|
let cursor: Partial<uPlot.Cursor> = {};
|
||||||
|
|
||||||
cursor.sync = {
|
cursor.sync = {
|
||||||
key: '__global_',
|
key: eventsScope,
|
||||||
filters: {
|
filters: {
|
||||||
pub: (type: string, src: uPlot, x: number, y: number, w: number, h: number, dataIdx: number) => {
|
pub: (type: string, src: uPlot, x: number, y: number, w: number, h: number, dataIdx: number) => {
|
||||||
if (sync && sync() === DashboardCursorSync.Off) {
|
if (sync && sync() === DashboardCursorSync.Off) {
|
||||||
|
@ -99,6 +99,7 @@ export class PanelStateWrapper extends PureComponent<Props, State> {
|
|||||||
renderCounter: 0,
|
renderCounter: 0,
|
||||||
refreshWhenInView: false,
|
refreshWhenInView: false,
|
||||||
context: {
|
context: {
|
||||||
|
eventsScope: '__global_',
|
||||||
eventBus,
|
eventBus,
|
||||||
app: this.getPanelContextApp(),
|
app: this.getPanelContextApp(),
|
||||||
sync: this.getSync,
|
sync: this.getSync,
|
||||||
|
@ -153,6 +153,7 @@ export function ExploreGraph({
|
|||||||
}, [dataWithConfig, onHiddenSeriesChanged]);
|
}, [dataWithConfig, onHiddenSeriesChanged]);
|
||||||
|
|
||||||
const panelContext: PanelContext = {
|
const panelContext: PanelContext = {
|
||||||
|
eventsScope: 'explore',
|
||||||
eventBus,
|
eventBus,
|
||||||
sync: () => DashboardCursorSync.Crosshair,
|
sync: () => DashboardCursorSync.Crosshair,
|
||||||
onSplitOpen: splitOpenFn,
|
onSplitOpen: splitOpenFn,
|
||||||
|
@ -74,6 +74,8 @@ interface PrepConfigOpts {
|
|||||||
yAxisConfig: YAxisConfig;
|
yAxisConfig: YAxisConfig;
|
||||||
ySizeDivisor?: number;
|
ySizeDivisor?: number;
|
||||||
sync?: () => DashboardCursorSync;
|
sync?: () => DashboardCursorSync;
|
||||||
|
// Identifies the shared key for uPlot cursor sync
|
||||||
|
eventsScope?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function prepConfig(opts: PrepConfigOpts) {
|
export function prepConfig(opts: PrepConfigOpts) {
|
||||||
@ -93,6 +95,7 @@ export function prepConfig(opts: PrepConfigOpts) {
|
|||||||
yAxisConfig,
|
yAxisConfig,
|
||||||
ySizeDivisor,
|
ySizeDivisor,
|
||||||
sync,
|
sync,
|
||||||
|
eventsScope = '__global_',
|
||||||
} = opts;
|
} = opts;
|
||||||
|
|
||||||
const xScaleKey = 'x';
|
const xScaleKey = 'x';
|
||||||
@ -603,7 +606,7 @@ export function prepConfig(opts: PrepConfigOpts) {
|
|||||||
|
|
||||||
if (sync && sync() !== DashboardCursorSync.Off) {
|
if (sync && sync() !== DashboardCursorSync.Off) {
|
||||||
cursor.sync = {
|
cursor.sync = {
|
||||||
key: '__global_',
|
key: eventsScope,
|
||||||
scales: [xScaleKey, yScaleKey],
|
scales: [xScaleKey, yScaleKey],
|
||||||
filters: {
|
filters: {
|
||||||
pub: (type: string, src: uPlot, x: number, y: number, w: number, h: number, dataIdx: number) => {
|
pub: (type: string, src: uPlot, x: number, y: number, w: number, h: number, dataIdx: number) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user