Skip to content

Commit

Permalink
fix: tooltip should account for container in string format (#5856)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoiver committed Nov 28, 2023
1 parent 4e0ea73 commit d923eb9
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/interaction/tooltip.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Circle, DisplayObject, IElement, Line } from '@antv/g';
import { Canvas, 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 Down Expand Up @@ -26,8 +26,10 @@ function getContainer(
): HTMLElement {
if (mount)
return typeof mount === 'string' ? document.querySelector(mount) : mount;
// @ts-ignore
return group.getRootNode().defaultView.getConfig().container;

return group.ownerDocument.defaultView
.getContextService()
.getDomElement() as unknown as HTMLElement;
}

function getBounding(root): BBox {
Expand Down Expand Up @@ -110,7 +112,9 @@ function showTooltip({
mount,
bounding,
}) {
const canvasContainer = root.getRootNode().defaultView.getConfig().container;
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.
Expand Down Expand Up @@ -149,7 +153,9 @@ function hideTooltip({ root, single, emitter, nativeEvent = true }) {
if (nativeEvent) {
emitter.emit('tooltip:hide', { nativeEvent });
}
const canvasContainer = root.getRootNode().defaultView.getConfig().container;
const canvasContainer = root.ownerDocument.defaultView
.getContextService()
.getDomElement();
const parent = single ? canvasContainer : root;
const { tooltipElement } = parent;
if (tooltipElement) {
Expand All @@ -158,7 +164,9 @@ function hideTooltip({ root, single, emitter, nativeEvent = true }) {
}

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

0 comments on commit d923eb9

Please sign in to comment.