diff --git a/web/ui/mantine-ui/src/pages/query/uPlotChartHelpers.ts b/web/ui/mantine-ui/src/pages/query/uPlotChartHelpers.ts index ba6cdbae41..816ddf7578 100644 --- a/web/ui/mantine-ui/src/pages/query/uPlotChartHelpers.ts +++ b/web/ui/mantine-ui/src/pages/query/uPlotChartHelpers.ts @@ -83,8 +83,6 @@ const formatLabels = (labels: { [key: string]: string }): string => ` const tooltipPlugin = (useLocalTime: boolean, data: AlignedData) => { let over: HTMLDivElement; - let boundingLeft: number; - let boundingTop: number; let selectedSeriesIdx: number | null = null; const overlay = document.createElement("div"); @@ -111,12 +109,6 @@ const tooltipPlugin = (useLocalTime: boolean, data: AlignedData) => { destroy: () => { overlay.remove(); }, - // When the chart is resized, store the bounding box of the overlay. - setSize: () => { - const bbox = over.getBoundingClientRect(); - boundingLeft = bbox.left; - boundingTop = bbox.top; - }, // When a series is selected by hovering close to it, store the // index of the selected series, so we can update the hover tooltip // in setCursor. @@ -150,8 +142,12 @@ const tooltipPlugin = (useLocalTime: boolean, data: AlignedData) => { } const color = series.stroke(u, selectedSeriesIdx); - const x = left + boundingLeft; - const y = top + boundingTop; + // Get the bounding rect fresh on every cursor move to account for + // page scrolling, which would otherwise cause a growing Y offset + // for charts further down the page. + const bbox = over.getBoundingClientRect(); + const x = left + bbox.left; + const y = top + bbox.top; overlay.innerHTML = `
${formatTimestamp(ts, useLocalTime)}