From 41f46e1300b421fe0a3ba981abdd33573ef7e154 Mon Sep 17 00:00:00 2001 From: jianneng-fit2cloud Date: Thu, 3 Apr 2025 19:59:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=BD=AE=E6=92=AD=E6=8F=90=E7=A4=BA=E5=9C=A8=E5=8F=8C=E8=BD=B4?= =?UTF-8?q?=E5=9B=BE=E5=8F=AA=E6=9C=89=E4=B8=80=E4=B8=AA=E8=BD=B4=E6=9C=89?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=97=B6=EF=BC=8C=E6=97=A0=E6=B3=95=E8=BD=AE?= =?UTF-8?q?=E6=92=AD=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/js/g2plot_tooltip_carousel.ts | 35 ++++++++++++++----- .../components/js/panel/common/common_antv.ts | 13 +++---- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/js/g2plot_tooltip_carousel.ts b/core/core-frontend/src/views/chart/components/js/g2plot_tooltip_carousel.ts index 02d8cb1bd1..7ca69cd39f 100644 --- a/core/core-frontend/src/views/chart/components/js/g2plot_tooltip_carousel.ts +++ b/core/core-frontend/src/views/chart/components/js/g2plot_tooltip_carousel.ts @@ -219,6 +219,9 @@ class ChartCarouselTooltip { if (['pie', 'pie-donut'].includes(this.chart.type)) { return this.getPieTooltipPosition(view, value) } + if (this.plot instanceof DualAxes) { + return this.getDualAxesTooltipPosition(view, value) + } const types = view .scale() .getGeometries() @@ -266,6 +269,23 @@ class ChartCarouselTooltip { } } + /** + * 获取双轴图表的 Tooltip 位置 + * @param view + * @param value + * @private + */ + private getDualAxesTooltipPosition(view, value: string) { + const xScale = view.getXScale() + const values = xScale.values + const [rangeStart, rangeEnd] = xScale.range + const totalMonths = values.length + const bandWidth = (rangeEnd - rangeStart) / totalMonths + const index = values.indexOf(value) + const xPos = rangeStart + bandWidth * (index + 0.5) + return view.getCoordinate().convert({ x: xPos, y: 0 }) + } + /** * 高亮指定元素 * */ @@ -308,12 +328,12 @@ class ChartCarouselTooltip { * 绑定事件监听 * */ private bindEventListeners() { - let deCanvasElement = document.getElementById('de-canvas-canvas-main') - if (!deCanvasElement) { - deCanvasElement = document.getElementById('preview-canvas-main') - } - if (!deCanvasElement) { - deCanvasElement = document.getElementById('canvas-mark-line') + // 用于监听在不同的浏览页面的滚动事件 + const elementIds = ['de-canvas-canvas-main', 'preview-canvas-main', 'canvas-mark-line'] + let deCanvasElement = null + for (const id of elementIds) { + deCanvasElement = document.getElementById(id) + if (deCanvasElement) break } if (!deCanvasElement) { this.unHighlightPoint() @@ -346,9 +366,6 @@ class ChartCarouselTooltip { this.setPaused(false) } }) - } - - if (deCanvasElement) { // 元素可视性观察(交叉观察器) this.setupIntersectionObserver() } 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 7dddf51e1a..83bcf4d3d3 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 @@ -1716,10 +1716,8 @@ export function configPlotTooltipEvent> // 图表容器,用于计算 tooltip 的位置 // 编辑时 let chartElement = document.getElementById('shape-id-' + chart.id) - if (!chartElement) { - // 公共连接时 - chartElement = document.getElementById('enlarge-inner-content-' + chart.id) - } + // 公共连接页面 + chartElement = chartElement || document.getElementById('enlarge-inner-content-' + chart.id) configCarouselTooltip(plot, chart) // 鼠标可移入, 移入之后保持显示, 移出之后隐藏 plot.options.tooltip.container.addEventListener('mouseenter', e => { @@ -1742,12 +1740,9 @@ export function configPlotTooltipEvent> !event || event?.type === 'plot:leave' || ['pie', 'pie-rose', 'pie-donut'].includes(chart.type) + plot.options.tooltip.showMarkers = isCarousel ? true : false const wrapperDom = document.getElementById(G2_TOOLTIP_WRAPPER) - if (isCarousel && wrapperDom) { - wrapperDom.style.zIndex = '1' - } else { - wrapperDom.style.zIndex = '9999' - } + wrapperDom.style.zIndex = isCarousel && wrapperDom ? '1' : '9999' if (tooltipCtl.tooltip) { // 处理视图放大后再关闭 tooltip 的 dom 被清除 const container = tooltipCtl.tooltip.cfg.container