diff --git a/src/interaction/tooltip.ts b/src/interaction/tooltip.ts index c950fe0fd5..5e1647180b 100644 --- a/src/interaction/tooltip.ts +++ b/src/interaction/tooltip.ts @@ -22,14 +22,15 @@ import { dataOf } from './event'; function getContainer( group: IElement, - mount: string | HTMLElement, + mount?: string | HTMLElement, ): HTMLElement { - if (mount) + if (mount) { return typeof mount === 'string' ? document.querySelector(mount) : mount; - - return group.ownerDocument.defaultView + } + const canvas: any = group.ownerDocument.defaultView .getContextService() - .getDomElement() as unknown as HTMLElement; + .getDomElement(); + return canvas.parentElement as unknown as HTMLElement; } function getBounding(root): BBox { @@ -112,16 +113,13 @@ function showTooltip({ mount, bounding, }) { - const canvasContainer = (root.ownerDocument.defaultView as Canvas) - .getContextService() - .getDomElement() as unknown as HTMLElement; const container = getContainer(root, mount); // All the views share the same tooltip. - const parent = single ? canvasContainer : root; + const parent = single ? container : root; const b = bounding || getBounding(root); - const containerOffset = getContainerOffset(canvasContainer, container); + const containerOffset = getContainerOffset(container, container); const { tooltipElement = createTooltip( container, @@ -153,9 +151,7 @@ function hideTooltip({ root, single, emitter, nativeEvent = true }) { if (nativeEvent) { emitter.emit('tooltip:hide', { nativeEvent }); } - const canvasContainer = root.ownerDocument.defaultView - .getContextService() - .getDomElement(); + const canvasContainer = getContainer(root); const parent = single ? canvasContainer : root; const { tooltipElement } = parent; if (tooltipElement) { @@ -164,9 +160,7 @@ function hideTooltip({ root, single, emitter, nativeEvent = true }) { } function destroyTooltip({ root, single }) { - const canvasContainer = root.ownerDocument.defaultView - .getContextService() - .getDomElement() as unknown as HTMLElement; + const canvasContainer = getContainer(root); const parent = single ? canvasContainer : root; if (!parent) return; const { tooltipElement } = parent;