mirror of
https://github.com/grafana/grafana.git
synced 2025-01-09 15:43:23 -06:00
Timeline: tooltip fixups (#35145)
This commit is contained in:
parent
057ba4a6e7
commit
a3ba605aff
@ -47,8 +47,8 @@ export interface TimelineCoreOptions {
|
||||
getTimeRange: () => TimeRange;
|
||||
formatValue?: (seriesIdx: number, value: any) => string;
|
||||
getFieldConfig: (seriesIdx: number) => TimelineFieldConfig;
|
||||
onHover?: (seriesIdx: number, valueIdx: number, rect: Rect) => void;
|
||||
onLeave?: () => void;
|
||||
onHover: (seriesIdx: number, valueIdx: number, rect: Rect) => void;
|
||||
onLeave: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -416,12 +416,11 @@ export function getConfig(opts: TimelineCoreOptions) {
|
||||
if (foundAtCursor) {
|
||||
if (foundAtCursor !== hoveredAtCursor) {
|
||||
hoveredAtCursor = foundAtCursor;
|
||||
// @ts-ignore
|
||||
onHover && onHover(foundAtCursor.sidx, foundAtCursor.didx, foundAtCursor);
|
||||
onHover(foundAtCursor!.sidx, foundAtCursor!.didx, foundAtCursor);
|
||||
}
|
||||
} else if (hoveredAtCursor) {
|
||||
hoveredAtCursor = null;
|
||||
onLeave && onLeave();
|
||||
onLeave();
|
||||
}
|
||||
}
|
||||
|
||||
@ -439,13 +438,12 @@ export function getConfig(opts: TimelineCoreOptions) {
|
||||
|
||||
if (foundAtCursor !== hoveredAtCursor) {
|
||||
hoveredAtCursor = foundAtCursor;
|
||||
// @ts-ignore
|
||||
onHover && onHover(foundAtCursor.sidx, foundAtCursor.didx, foundAtCursor);
|
||||
onHover(foundAtCursor!.sidx, foundAtCursor!.didx, foundAtCursor);
|
||||
}
|
||||
} else if (hoveredAtCursor) {
|
||||
setHoverMark(0, null);
|
||||
hoveredAtCursor = null;
|
||||
onLeave && onLeave();
|
||||
onLeave();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,13 +99,16 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<TimelineOptions> = ({
|
||||
onHover: (seriesIndex, valueIndex) => {
|
||||
hoveredSeriesIdx = seriesIndex;
|
||||
hoveredDataIdx = valueIndex;
|
||||
shouldChangeHover = true;
|
||||
},
|
||||
onLeave: () => {
|
||||
hoveredSeriesIdx = null;
|
||||
hoveredDataIdx = null;
|
||||
shouldChangeHover = true;
|
||||
},
|
||||
};
|
||||
|
||||
let shouldChangeHover = false;
|
||||
let hoveredSeriesIdx: number | null = null;
|
||||
let hoveredDataIdx: number | null = null;
|
||||
|
||||
@ -123,15 +126,16 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<TimelineOptions> = ({
|
||||
updateActiveDatapointIdx,
|
||||
updateTooltipPosition
|
||||
) => (u: uPlot) => {
|
||||
if (hoveredSeriesIdx != null) {
|
||||
// @ts-ignore
|
||||
updateActiveSeriesIdx(hoveredSeriesIdx);
|
||||
// @ts-ignore
|
||||
updateActiveDatapointIdx(hoveredDataIdx);
|
||||
updateTooltipPosition();
|
||||
} else {
|
||||
updateTooltipPosition(true);
|
||||
if (shouldChangeHover) {
|
||||
if (hoveredSeriesIdx != null) {
|
||||
updateActiveSeriesIdx(hoveredSeriesIdx);
|
||||
updateActiveDatapointIdx(hoveredDataIdx);
|
||||
}
|
||||
|
||||
shouldChangeHover = false;
|
||||
}
|
||||
|
||||
updateTooltipPosition(hoveredSeriesIdx == null);
|
||||
};
|
||||
|
||||
builder.setTooltipInterpolator(interpolateTooltip);
|
||||
|
Loading…
Reference in New Issue
Block a user