diff --git a/ts/graphs/graphs.html b/ts/graphs/graphs.html index bf8a9bdf9..c73ddda18 100644 --- a/ts/graphs/graphs.html +++ b/ts/graphs/graphs.html @@ -4,30 +4,31 @@ + +
+ + - - - diff --git a/ts/graphs/tooltip.ts b/ts/graphs/tooltip.ts index 3e402fe56..ea12a0668 100644 --- a/ts/graphs/tooltip.ts +++ b/ts/graphs/tooltip.ts @@ -3,11 +3,24 @@ import throttle from "lodash.throttle"; -const tooltipDiv: HTMLDivElement = document.createElement("div"); -tooltipDiv.className = "graph-tooltip"; -document.body.appendChild(tooltipDiv); +function getOrCreateTooltipDiv(): HTMLDivElement { + const existingTooltip = document.getElementById("graphTooltip") as HTMLDivElement; + + if (existingTooltip) { + return existingTooltip; + } + + const tooltipDiv: HTMLDivElement = document.createElement("div"); + tooltipDiv.id = "graphTooltip"; + tooltipDiv.className = "graph-tooltip"; + document.body.appendChild(tooltipDiv); + + return tooltipDiv; +} function showTooltipInner(msg: string, x: number, y: number): void { + const tooltipDiv = getOrCreateTooltipDiv(); + tooltipDiv.innerHTML = msg; // move tooltip away from edge as user approaches right side @@ -26,6 +39,8 @@ function showTooltipInner(msg: string, x: number, y: number): void { export const showTooltip = throttle(showTooltipInner, 16); export function hideTooltip(): void { + const tooltipDiv = getOrCreateTooltipDiv(); + showTooltip.cancel(); tooltipDiv.style.opacity = "0"; }