Skip to content

Commit 7b3acb9

Browse files
authored
Merge pull request #4929 from shpingalet007/fix/tooltip-active-state-blink
Fix tooltip stability for smoother chart interaction
2 parents cb88426 + 10bbb57 commit 7b3acb9

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/modules/tooltip/Tooltip.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -529,19 +529,19 @@ export default class Tooltip {
529529
syncedCharts = this.ctx.getSyncedCharts()
530530
}
531531

532-
let isStickyTooltip =
532+
const isStickyTooltip =
533533
w.globals.xyCharts ||
534534
(w.config.chart.type === 'bar' &&
535535
!w.globals.isBarHorizontal &&
536536
this.tooltipUtil.hasBars() &&
537537
this.tConfig.shared) ||
538538
(w.globals.comboCharts && this.tooltipUtil.hasBars())
539539

540-
if (
541-
e.type === 'mousemove' ||
542-
e.type === 'touchmove' ||
543-
e.type === 'mouseup'
544-
) {
540+
const isInteractionInProcess = (e.type === 'mousemove' || e.type === 'touchmove' || e.type === 'mouseup')
541+
const isInteractionEnd = (e.type === 'mouseout' || e.type === 'touchend')
542+
const isChartContextTarget = w.globals.dom.baseEl.contains(e.relatedTarget)
543+
544+
if (isInteractionInProcess) {
545545
// there is no series to hover over
546546
if (
547547
w.globals.collapsedSeries.length +
@@ -555,10 +555,9 @@ export default class Tooltip {
555555
xcrosshairs.classList.add('apexcharts-active')
556556
}
557557

558-
const hasYAxisTooltip = this.yaxisTooltips.filter((b) => {
559-
return b === true
560-
})
561-
if (this.ycrosshairs !== null && hasYAxisTooltip.length) {
558+
const hasYAxisTooltip = this.yaxisTooltips.includes(true)
559+
560+
if (this.ycrosshairs !== null && hasYAxisTooltip) {
562561
this.ycrosshairs.classList.add('apexcharts-active')
563562
}
564563

@@ -568,10 +567,10 @@ export default class Tooltip {
568567
) {
569568
this.handleStickyTooltip(e, clientX, clientY, opt)
570569
} else {
571-
if (
572-
w.config.chart.type === 'heatmap' ||
573-
w.config.chart.type === 'treemap'
574-
) {
570+
const isHeatmap = w.config.chart.type === 'heatmap'
571+
const isTreemap = w.config.chart.type === 'treemap'
572+
573+
if (isHeatmap || isTreemap) {
575574
let markerXY = this.intersect.handleHeatTreeTooltip({
576575
e,
577576
opt,
@@ -582,8 +581,8 @@ export default class Tooltip {
582581
x = markerXY.x
583582
y = markerXY.y
584583

585-
tooltipEl.style.left = x + 'px'
586-
tooltipEl.style.top = y + 'px'
584+
tooltipEl.style.left = `${x}px`
585+
tooltipEl.style.top = `${y}px`
587586
} else {
588587
if (this.tooltipUtil.hasBars()) {
589588
this.intersect.handleBarTooltip({
@@ -612,7 +611,7 @@ export default class Tooltip {
612611

613612
w.globals.dom.baseEl.classList.add('apexcharts-tooltip-active')
614613
opt.tooltipEl.classList.add('apexcharts-active')
615-
} else if (e.type === 'mouseout' || e.type === 'touchend') {
614+
} else if (!isChartContextTarget && isInteractionEnd) {
616615
this.handleMouseOut(opt)
617616
}
618617
}

0 commit comments

Comments
 (0)