Skip to content

Commit

Permalink
fix(tooltip): wrong container (#5890)
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Dec 6, 2023
1 parent 97014bb commit 9ed535a
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/interaction/tooltip.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Canvas, Circle, DisplayObject, IElement, Line } from '@antv/g';
import { Circle, DisplayObject, IElement, Line } from '@antv/g';
import { sort, group, mean, bisector, minIndex } from 'd3-array';
import { deepMix, lowerFirst, throttle } from '@antv/util';
import { Tooltip as TooltipComponent } from '@antv/component';
Expand All @@ -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,14 +113,10 @@ function showTooltip({
mount,
bounding,
}) {
const canvasContainer = (root.ownerDocument.defaultView as Canvas)
.getContextService()
.getDomElement() as unknown as HTMLElement;
const container = getContainer(root, mount);

const canvasContainer = getContainer(root);
// All the views share the same tooltip.
const parent = single ? canvasContainer : root;

const b = bounding || getBounding(root);
const containerOffset = getContainerOffset(canvasContainer, container);
const {
Expand Down Expand Up @@ -153,21 +150,17 @@ function hideTooltip({ root, single, emitter, nativeEvent = true }) {
if (nativeEvent) {
emitter.emit('tooltip:hide', { nativeEvent });
}
const canvasContainer = root.ownerDocument.defaultView
.getContextService()
.getDomElement();
const parent = single ? canvasContainer : root;
const container = getContainer(root);
const parent = single ? container : root;
const { tooltipElement } = parent;
if (tooltipElement) {
tooltipElement.hide();
}
}

function destroyTooltip({ root, single }) {
const canvasContainer = root.ownerDocument.defaultView
.getContextService()
.getDomElement() as unknown as HTMLElement;
const parent = single ? canvasContainer : root;
const container = getContainer(root);
const parent = single ? container : root;
if (!parent) return;
const { tooltipElement } = parent;
if (tooltipElement) {
Expand Down

0 comments on commit 9ed535a

Please sign in to comment.