diff --git a/public/app/plugins/panel/state-timeline/timeline.ts b/public/app/plugins/panel/state-timeline/timeline.ts index ead53e042af..711b8e7df86 100644 --- a/public/app/plugins/panel/state-timeline/timeline.ts +++ b/public/app/plugins/panel/state-timeline/timeline.ts @@ -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(); } } diff --git a/public/app/plugins/panel/state-timeline/utils.ts b/public/app/plugins/panel/state-timeline/utils.ts index f13926898a7..05862625f9c 100644 --- a/public/app/plugins/panel/state-timeline/utils.ts +++ b/public/app/plugins/panel/state-timeline/utils.ts @@ -99,13 +99,16 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn = ({ 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 = ({ 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);