Timeline: tooltip fixups (#35145) (#35191)

(cherry picked from commit a3ba605aff)

Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2021-06-03 09:50:16 -05:00
committed by GitHub
co-authored by Leon Sorokin
parent 4fe55be39e
commit a8b2415b1f
2 changed files with 18 additions and 16 deletions
@@ -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);