From da48f8782e0817e8e1c479bb7ab4f7642eda7674 Mon Sep 17 00:00:00 2001 From: hanaTsuk1 <101488209+hanaTsuk1@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:23:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=80=BB=E8=A7=88=E6=8B=96=E6=8B=BD?= =?UTF-8?q?=E5=9B=BE=E8=A1=A8=E5=90=8E=E6=B5=AE=E7=AA=97=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useEcharts.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/hooks/useEcharts.ts b/src/hooks/useEcharts.ts index 6460bd2..721de10 100644 --- a/src/hooks/useEcharts.ts +++ b/src/hooks/useEcharts.ts @@ -3,16 +3,20 @@ import type { TooltipComponentPositionCallback } from 'echarts' export function useEcharts() { const { bottom, mouseY } = layoutMainInject() const parentEl = useParentElement() - const { top: parentTop } = useElementBounding(parentEl) const position: TooltipComponentPositionCallback = (point, _, __, ___, size) => { + if (!parentEl.value) + return [0, 0] + + const { top: parentTop } = parentEl.value.getBoundingClientRect() + const [x] = point const [contentWidth, contentHeight] = size.contentSize const [viewWidth] = size.viewSize const offset = 20 let left = x + offset - let top = mouseY.value - parentTop.value + let top = mouseY.value - parentTop if (x + contentWidth > viewWidth) { left = x - contentWidth - offset @@ -21,7 +25,7 @@ export function useEcharts() { } if (mouseY.value + contentHeight > bottom.value) - top = mouseY.value - contentHeight - parentTop.value + top = mouseY.value - contentHeight - parentTop return [left, top] }