From 693ae2b99ab22ed79a0e0bb8bc92049c1e2807b3 Mon Sep 17 00:00:00 2001 From: wisonic-s <51065359+wisonic-s@users.noreply.github.com> Date: Tue, 11 Mar 2025 15:22:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E7=AB=AF=E5=9B=BE=E8=A1=A8=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E9=9A=90=E8=97=8F=20#15117?= =?UTF-8?q?=20(#15275)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chart/components/js/panel/common/common_antv.ts | 12 ++++++++++-- .../views/components/ChartComponentG2Plot.vue | 11 +++++++++++ .../src/views/chart/components/views/index.vue | 9 +++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/js/panel/common/common_antv.ts b/core/core-frontend/src/views/chart/components/js/panel/common/common_antv.ts index eac82d2ae4..db88743248 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/common/common_antv.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/common/common_antv.ts @@ -1467,14 +1467,22 @@ export function configPlotTooltipEvent> if (!tooltipCtl) { return } - const container = tooltipCtl.tooltip.cfg.container + const container = tooltipCtl.tooltip?.cfg.container for (const ele of wrapperDom.children) { - if (container.id !== ele.id) { + if (!container || container.id !== ele.id) { ele.style.display = 'none' } } } }) + plot.on('tooltip:hidden', () => { + const tooltipCtl = plot.chart.getController('tooltip') + if (!tooltipCtl) { + return + } + const container = tooltipCtl.tooltip?.cfg.container + container && (container.style.display = 'none') + }) } export const TOOLTIP_TPL = diff --git a/core/core-frontend/src/views/chart/components/views/components/ChartComponentG2Plot.vue b/core/core-frontend/src/views/chart/components/views/components/ChartComponentG2Plot.vue index 2b5a22ffdb..72546e08d2 100644 --- a/core/core-frontend/src/views/chart/components/views/components/ChartComponentG2Plot.vue +++ b/core/core-frontend/src/views/chart/components/views/components/ChartComponentG2Plot.vue @@ -742,6 +742,7 @@ defineExpose({ trackMenu, clearLinkage }) +let intersectionObserver let resizeObserver const TOLERANCE = 0.01 const RESIZE_MONITOR_CHARTS = ['map', 'bubble-map', 'flow-map', 'heat-map'] @@ -766,6 +767,15 @@ onMounted(() => { preSize[1] = size.blockSize }) resizeObserver.observe(containerDom) + intersectionObserver = new IntersectionObserver(([entry]) => { + if (RESIZE_MONITOR_CHARTS.includes(view.value.type)) { + return + } + if (entry.intersectionRatio <= 0) { + myChart?.emit('tooltip:hidden') + } + }) + intersectionObserver.observe(containerDom) useEmitt({ name: 'l7-prepare-picture', callback: preparePicture }) useEmitt({ name: 'l7-unprepare-picture', callback: unPreparePicture }) }) @@ -773,6 +783,7 @@ onBeforeUnmount(() => { try { myChart?.destroy() resizeObserver?.disconnect() + intersectionObserver?.disconnect() } catch (e) { console.warn(e) } diff --git a/core/core-frontend/src/views/chart/components/views/index.vue b/core/core-frontend/src/views/chart/components/views/index.vue index 17f19982c2..7976c77841 100644 --- a/core/core-frontend/src/views/chart/components/views/index.vue +++ b/core/core-frontend/src/views/chart/components/views/index.vue @@ -1028,6 +1028,14 @@ const titleTooltipWidth = computed(() => { } return '500px' }) +const clearG2Tooltip = () => { + const g2TooltipWrapper = document.getElementById('g2-tooltip-wrapper') + if (g2TooltipWrapper) { + for (const ele of g2TooltipWrapper.children) { + ele.style.display = 'none' + } + } +}