Skip to content

Commit

Permalink
fix(tooltip): wrong container
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Dec 6, 2023
1 parent a4be1ab commit 92faa67
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/interaction/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit 92faa67

Please sign in to comment.