\ No newline at end of file
diff --git a/__tests__/plots/tooltip/index.ts b/__tests__/plots/tooltip/index.ts
index 808bfe7e53..45c27b7408 100644
--- a/__tests__/plots/tooltip/index.ts
+++ b/__tests__/plots/tooltip/index.ts
@@ -74,3 +74,4 @@ export { moviesIntervalScaleKeyScrollbar } from './movies-interval-scale-key-scr
export { oneElementLine } from './one-element-line';
export { disastersPointSlider } from './disasters-point-slider';
export { alphabetText } from './alphabet-text';
+export { mockLineFlex } from './mock-line-flex';
diff --git a/__tests__/plots/tooltip/mock-line-flex.ts b/__tests__/plots/tooltip/mock-line-flex.ts
new file mode 100644
index 0000000000..778674ebf4
--- /dev/null
+++ b/__tests__/plots/tooltip/mock-line-flex.ts
@@ -0,0 +1,72 @@
+import { CustomEvent } from '@antv/g';
+import { G2Spec, PLOT_CLASS_NAME } from '../../../src';
+
+export function mockLineFlex(): G2Spec {
+ return {
+ type: 'spaceFlex',
+ width: 928,
+ height: 320,
+ paddingLeft: 90,
+ paddingBottom: 60,
+ children: [
+ {
+ type: 'view',
+ data: [
+ { x: 1, y: 2 },
+ { x: 2, y: 6 },
+ { x: 3, y: 4 },
+ { x: 4, y: 9 },
+ ],
+ axis: {
+ x: { title: 'X', line: true, lineLineWidth: 1, grid: false },
+ y: {
+ title: 'Y',
+ line: true,
+ lineLineWidth: 1,
+ grid: true,
+ gridLineWidth: 2,
+ },
+ },
+ children: [{ type: 'line', encode: { x: 'x', y: 'y' } }],
+ },
+ {
+ type: 'view',
+ data: [
+ { x: 1, y: 3 },
+ { x: 2, y: 6 },
+ { x: 3, y: 7 },
+ { x: 4, y: 9 },
+ ],
+ axis: {
+ x: { title: 'X', line: true, lineLineWidth: 1, grid: false },
+ y: {
+ title: 'Y',
+ line: true,
+ lineLineWidth: 1,
+ grid: true,
+ gridLineWidth: 2,
+ },
+ },
+ children: [{ type: 'line', encode: { x: 'x', y: 'y' } }],
+ },
+ ],
+ };
+}
+
+mockLineFlex.steps = ({ canvas }) => {
+ const { document } = canvas;
+ const plot = document.getElementsByClassName(PLOT_CLASS_NAME)[1];
+ return [
+ {
+ changeState: async () => {
+ plot.dispatchEvent(
+ // @ts-ignore
+ new CustomEvent('pointermove', {
+ offsetX: 600,
+ offsetY: 50,
+ }),
+ );
+ },
+ },
+ ];
+};
diff --git a/src/interaction/utils.ts b/src/interaction/utils.ts
index 2697204012..144300fe72 100644
--- a/src/interaction/utils.ts
+++ b/src/interaction/utils.ts
@@ -1,4 +1,4 @@
-import { DisplayObject, Path } from '@antv/g';
+import { DisplayObject, Path, AABB } from '@antv/g';
import { path as d3Path } from 'd3-path';
import { sort } from 'd3-array';
import { Vector2 } from '@antv/coord';
@@ -44,10 +44,15 @@ export function selectPlotArea(root: DisplayObject): DisplayObject {
return select(root).select(`.${PLOT_CLASS_NAME}`).node();
}
-export function bboxOf(node) {
- if (node.nodeName !== 'rect') return node.getRenderBounds();
- const { x, y, width, height } = node.style;
- return { min: [x, y], max: [x + width, y + height] };
+export function bboxOf(element: DisplayObject) {
+ // The geometry bounds of a group is empty, so return the render bounds.
+ if (element.tagName === 'g') return element.getRenderBounds();
+
+ // Compute the geometry bounds related to the parent.
+ const bounds = element.getGeometryBounds();
+ const aabb = new AABB();
+ aabb.setFromTransformedAABB(bounds, element.getWorldTransform());
+ return aabb;
}
export function mousePosition(target, event) {