Skip to content

Commit b721c56

Browse files
fix(图表): 优化提示轮播在编辑移动端是,显示不正确的问题,以及zIndex过高的问题,在部分浏览页无法轮播的问题。
1 parent 595c398 commit b721c56

File tree

2 files changed

+60
-29
lines changed

2 files changed

+60
-29
lines changed

core/core-frontend/src/views/chart/components/js/g2plot_tooltip_carousel.ts

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ class ChartCarouselTooltip {
113113
private init() {
114114
this.values = [].concat(this.getUniqueValues())
115115
if (!this.values.length) return
116+
this.chartIsVisible = true
117+
this.states.paused = false
118+
this.states.destroyed = false
116119
this.bindEventListeners()
117120
this.startCarousel()
118121
}
@@ -193,7 +196,7 @@ class ChartCarouselTooltip {
193196
this.debounce(() => {
194197
this.stop()
195198
startNestedTimers()
196-
}, 200)()
199+
}, 300)()
197200
}
198201

199202
/**
@@ -305,7 +308,19 @@ class ChartCarouselTooltip {
305308
* 绑定事件监听
306309
* */
307310
private bindEventListeners() {
308-
const { chart } = this.plot
311+
let deCanvasElement = document.getElementById('de-canvas-canvas-main')
312+
if (!deCanvasElement) {
313+
deCanvasElement = document.getElementById('preview-canvas-main')
314+
}
315+
if (!deCanvasElement) {
316+
deCanvasElement = document.getElementById('canvas-mark-line')
317+
}
318+
if (!deCanvasElement) {
319+
this.unHighlightPoint()
320+
this.hideTooltip()
321+
this.setPaused(true)
322+
}
323+
deCanvasElement?.addEventListener('scroll', this.handleScroll.bind(this))
309324
const chartElement = document.getElementById(this.chart.container)
310325
chartElement.addEventListener('mouseenter', () => {
311326
this.unHighlightPoint()
@@ -315,24 +330,28 @@ class ChartCarouselTooltip {
315330

316331
// 当鼠标离开 chart 时,检查状态
317332
chartElement.addEventListener('mouseleave', () => {
318-
this.setPaused(false)
319-
})
320-
321-
// 页面可见性控制
322-
document.addEventListener('visibilitychange', () => {
323-
if (document.visibilityState === 'hidden') {
324-
this.unHighlightPoint()
325-
this.hideTooltip()
326-
this.setPaused(true)
327-
} else if (this.chartIsVisible) {
333+
if (deCanvasElement) {
328334
this.setPaused(false)
329335
}
330336
})
331337

332-
// 元素可视性观察(交叉观察器)
333-
this.setupIntersectionObserver()
334-
const deCanvasElement = document.getElementById('de-canvas-canvas-main')
335-
deCanvasElement.addEventListener('scroll', this.handleScroll.bind(this))
338+
if (deCanvasElement) {
339+
// 页面可见性控制
340+
document.addEventListener('visibilitychange', () => {
341+
if (document.visibilityState === 'hidden') {
342+
this.unHighlightPoint()
343+
this.hideTooltip()
344+
this.setPaused(true)
345+
} else if (this.chartIsVisible) {
346+
this.setPaused(false)
347+
}
348+
})
349+
}
350+
351+
if (deCanvasElement) {
352+
// 元素可视性观察(交叉观察器)
353+
this.setupIntersectionObserver()
354+
}
336355
}
337356

338357
private handleScroll() {

core/core-frontend/src/views/chart/components/js/panel/common/common_antv.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,12 @@ export function configPlotTooltipEvent<O extends PickOptions, P extends Plot<O>>
17141714
return
17151715
}
17161716
// 图表容器,用于计算 tooltip 的位置
1717-
const chartElement = document.getElementById('shape-id-' + chart.id)
1717+
// 编辑时
1718+
let chartElement = document.getElementById('shape-id-' + chart.id)
1719+
if (!chartElement) {
1720+
// 公共连接时
1721+
chartElement = document.getElementById('enlarge-inner-content-' + chart.id)
1722+
}
17181723
configCarouselTooltip(plot, chart)
17191724
// 鼠标可移入, 移入之后保持显示, 移出之后隐藏
17201725
plot.options.tooltip.container.addEventListener('mouseenter', e => {
@@ -1733,6 +1738,16 @@ export function configPlotTooltipEvent<O extends PickOptions, P extends Plot<O>>
17331738
return
17341739
}
17351740
const event = plot.chart.interactions.tooltip?.context?.event
1741+
const isCarousel =
1742+
!event ||
1743+
event?.type === 'plot:leave' ||
1744+
['pie', 'pie-rose', 'pie-donut'].includes(chart.type)
1745+
const wrapperDom = document.getElementById(G2_TOOLTIP_WRAPPER)
1746+
if (isCarousel && wrapperDom) {
1747+
wrapperDom.style.zIndex = '1'
1748+
} else {
1749+
wrapperDom.style.zIndex = '9999'
1750+
}
17361751
if (tooltipCtl.tooltip) {
17371752
// 处理视图放大后再关闭 tooltip 的 dom 被清除
17381753
const container = tooltipCtl.tooltip.cfg.container
@@ -1751,18 +1766,15 @@ export function configPlotTooltipEvent<O extends PickOptions, P extends Plot<O>>
17511766
plot.chart.getOptions().tooltip.follow = false
17521767
tooltipCtl.title = Math.random().toString()
17531768
// 当显示提示为事件触发时,使用event的client坐标,否则使用tooltipCtl.point 数据点的位置,在图表中,需要加上图表在绘制区的位置
1754-
const { x, y } =
1755-
!event ||
1756-
event?.type === 'plot:leave' ||
1757-
['pie', 'pie-rose', 'pie-donut'].includes(chart.type)
1758-
? {
1759-
x: tooltipCtl.point.x + Number(chartElement.getBoundingClientRect().left),
1760-
y:
1761-
60 +
1762-
Number(chartElement.getBoundingClientRect().top) +
1763-
Number(chartElement.style.height.split('px')[0]) / 2
1764-
}
1765-
: { x: event.clientX, y: event.clientY }
1769+
const { x, y } = isCarousel
1770+
? {
1771+
x: tooltipCtl.point.x + Number(chartElement.getBoundingClientRect().left),
1772+
y:
1773+
60 +
1774+
Number(chartElement.getBoundingClientRect().top) +
1775+
Number(chartElement.style.height.split('px')[0]) / 2
1776+
}
1777+
: { x: event.clientX, y: event.clientY }
17661778
plot.chart.getTheme().components.tooltip.x = x
17671779
plot.chart.getTheme().components.tooltip.y = y
17681780
})

0 commit comments

Comments
 (0)