mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
EventBus: Add ability to tag events with arbitrary classification meta (#82087)
This commit is contained in:
parent
829672759c
commit
930c8c5aa3
@ -19,10 +19,22 @@ export abstract class BusEventBase implements BusEvent {
|
||||
readonly payload?: any;
|
||||
readonly origin?: EventBus;
|
||||
|
||||
/** @internal */
|
||||
tags?: Set<string>;
|
||||
|
||||
constructor() {
|
||||
//@ts-ignore
|
||||
this.type = this.__proto__.constructor.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* Tag event for finer-grained filtering in subscribers
|
||||
*/
|
||||
setTags(tags: string[]) {
|
||||
this.tags = new Set(tags);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -139,6 +139,11 @@ export class GraphNG extends Component<GraphNGProps, GraphNGState> {
|
||||
}
|
||||
|
||||
handleCursorUpdate(evt: DataHoverEvent | LegacyGraphHoverEvent) {
|
||||
// ignore uplot-emitted events, since we already use uPlot's sync
|
||||
if (evt.tags?.has('uplot')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const time = evt.payload?.point?.time;
|
||||
const u = this.plotInstance.current;
|
||||
if (u && time) {
|
||||
|
@ -583,7 +583,9 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<{
|
||||
data: frame,
|
||||
};
|
||||
|
||||
const hoverEvent = new DataHoverEvent(payload);
|
||||
const hoverEvent = new DataHoverEvent(payload).setTags(['uplot']);
|
||||
const clearEvent = new DataHoverClearEvent().setTags(['uplot']);
|
||||
|
||||
cursor.sync = {
|
||||
key: eventsScope,
|
||||
filters: {
|
||||
@ -594,9 +596,7 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<{
|
||||
|
||||
payload.rowIndex = dataIdx;
|
||||
if (x < 0 && y < 0) {
|
||||
payload.point[xScaleUnit] = null;
|
||||
payload.point[yScaleKey] = null;
|
||||
eventBus.publish(new DataHoverClearEvent());
|
||||
eventBus.publish(clearEvent);
|
||||
} else {
|
||||
// convert the points
|
||||
payload.point[xScaleUnit] = src.posToVal(x, xScaleKey);
|
||||
|
@ -180,6 +180,9 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<UPlotConfigOptions> = (
|
||||
data: frame,
|
||||
};
|
||||
|
||||
const hoverEvent = new DataHoverEvent(payload).setTags(['uplot']);
|
||||
const clearEvent = new DataHoverClearEvent().setTags(['uplot']);
|
||||
|
||||
builder.addHook('init', coreConfig.init);
|
||||
builder.addHook('drawClear', coreConfig.drawClear);
|
||||
|
||||
@ -293,14 +296,12 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<UPlotConfigOptions> = (
|
||||
}
|
||||
payload.rowIndex = dataIdx;
|
||||
if (x < 0 && y < 0) {
|
||||
payload.point[xScaleUnit] = null;
|
||||
payload.point[FIXED_UNIT] = null;
|
||||
eventBus.publish(new DataHoverClearEvent());
|
||||
eventBus.publish(clearEvent);
|
||||
} else {
|
||||
payload.point[xScaleUnit] = src.posToVal(x, xScaleKey);
|
||||
payload.point.panelRelY = y > 0 ? y / h : 1; // used for old graph panel to position tooltip
|
||||
payload.down = undefined;
|
||||
eventBus.publish(new DataHoverEvent(payload));
|
||||
eventBus.publish(hoverEvent);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
@ -172,7 +172,9 @@ export function prepConfig(opts: PrepConfigOpts) {
|
||||
},
|
||||
data: dataRef.current?.heatmap,
|
||||
};
|
||||
const hoverEvent = new DataHoverEvent(payload);
|
||||
|
||||
const hoverEvent = new DataHoverEvent(payload).setTags(['uplot']);
|
||||
const clearEvent = new DataHoverClearEvent().setTags(['uplot']);
|
||||
|
||||
let pendingOnleave: ReturnType<typeof setTimeout> | 0;
|
||||
|
||||
@ -209,9 +211,7 @@ export function prepConfig(opts: PrepConfigOpts) {
|
||||
if (!pendingOnleave) {
|
||||
pendingOnleave = setTimeout(() => {
|
||||
onhover(null);
|
||||
payload.rowIndex = undefined;
|
||||
payload.point[xScaleUnit] = null;
|
||||
eventBus.publish(hoverEvent);
|
||||
eventBus.publish(clearEvent);
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user