Tooltip: fix time label mismatched with cursor & hover points (#37615)

pull/37622/head^2
Leon Sorokin 4 years ago committed by GitHub
parent ef19e2edce
commit cf1c2c374f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      packages/grafana-ui/src/components/uPlot/plugins/TooltipPlugin.tsx

@ -29,6 +29,15 @@ interface TooltipPluginProps {
renderTooltip?: (alignedFrame: DataFrame, seriesIdx: number | null, datapointIdx: number | null) => React.ReactNode; renderTooltip?: (alignedFrame: DataFrame, seriesIdx: number | null, datapointIdx: number | null) => React.ReactNode;
} }
const eqArrays = (a: any[], b: any[]) => {
for (let i = 0; i < a.length; i++) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
};
const TOOLTIP_OFFSET = 10; const TOOLTIP_OFFSET = 10;
/** /**
@ -114,13 +123,16 @@ export const TooltipPlugin: React.FC<TooltipPluginProps> = ({
})(u); })(u);
}); });
} else { } else {
config.addHook('setLegend', (u) => { let prevIdx: number | null = null;
setFocusedPointIdx(u.cursor.idx!); let prevIdxs: Array<number | null> | null = null;
setFocusedPointIdxs(u.cursor.idxs!.slice());
});
// default series/datapoint idx retireval // default series/datapoint idx retireval
config.addHook('setCursor', (u) => { config.addHook('setCursor', (u) => {
if (u.cursor.idx !== prevIdx || prevIdxs == null || !eqArrays(prevIdxs, u.cursor.idxs!)) {
setFocusedPointIdx((prevIdx = u.cursor.idx!));
setFocusedPointIdxs((prevIdxs = u.cursor.idxs!.slice()));
}
const bbox = plotCtx.getCanvasBoundingBox(); const bbox = plotCtx.getCanvasBoundingBox();
if (!bbox) { if (!bbox) {
return; return;
@ -138,7 +150,7 @@ export const TooltipPlugin: React.FC<TooltipPluginProps> = ({
setFocusedSeriesIdx(idx); setFocusedSeriesIdx(idx);
}); });
} }
}, [plotCtx, config, setFocusedPointIdx, setFocusedSeriesIdx, setCoords]); }, [plotCtx, config]);
if (!plotInstance || focusedPointIdx === null || (!isActive && sync === DashboardCursorSync.Crosshair)) { if (!plotInstance || focusedPointIdx === null || (!isActive && sync === DashboardCursorSync.Crosshair)) {
return null; return null;

Loading…
Cancel
Save