mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Tooltip: bring back optimized hoverpoint code (#37901)
This commit is contained in:
parent
f5b8e8b48a
commit
0e3fb55caa
@ -29,15 +29,6 @@ interface TooltipPluginProps {
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -123,16 +114,13 @@ export const TooltipPlugin: React.FC<TooltipPluginProps> = ({
|
||||
})(u);
|
||||
});
|
||||
} else {
|
||||
let prevIdx: number | null = null;
|
||||
let prevIdxs: Array<number | null> | null = null;
|
||||
config.addHook('setLegend', (u) => {
|
||||
setFocusedPointIdx(u.legend.idx!);
|
||||
setFocusedPointIdxs(u.legend.idxs!.slice());
|
||||
});
|
||||
|
||||
// default series/datapoint idx retireval
|
||||
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();
|
||||
if (!bbox) {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user