From 34f678cc14698bff2d988945d89514809ba3e040 Mon Sep 17 00:00:00 2001 From: Juned Chhipa Date: Thu, 12 Dec 2024 12:43:56 +0530 Subject: [PATCH] improve tooltip for marker precision --- src/modules/tooltip/Position.js | 2 +- src/modules/tooltip/Tooltip.js | 21 +++++++++++++++------ src/modules/tooltip/Utils.js | 10 +++++++++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/modules/tooltip/Position.js b/src/modules/tooltip/Position.js index 816c2d865..d4f722c13 100644 --- a/src/modules/tooltip/Position.js +++ b/src/modules/tooltip/Position.js @@ -312,7 +312,7 @@ export default class Position { let points = ttCtx.tooltipUtil.getAllMarkers() - if (points !== null) { + if (points.length) { for (let p = 0; p < w.globals.series.length; p++) { let pointArr = pointsArr[p] diff --git a/src/modules/tooltip/Tooltip.js b/src/modules/tooltip/Tooltip.js index e65762efa..622a267df 100644 --- a/src/modules/tooltip/Tooltip.js +++ b/src/modules/tooltip/Tooltip.js @@ -807,6 +807,14 @@ export default class Tooltip { const bars = this.tooltipUtil.getElBars() + const handlePoints = () => { + if (w.globals.markers.largestSize > 0) { + ttCtx.marker.enlargePoints(j) + } else { + ttCtx.tooltipPosition.moveDynamicPointsOnHover(j) + } + } + if (w.config.legend.tooltipHoverFormatter) { let legendFormatter = w.config.legend.tooltipHoverFormatter @@ -866,11 +874,7 @@ export default class Tooltip { }) if (hasMarkers) { - if (w.globals.markers.largestSize > 0) { - ttCtx.marker.enlargePoints(j) - } else { - ttCtx.tooltipPosition.moveDynamicPointsOnHover(j) - } + handlePoints() } else if (this.tooltipUtil.hasBars()) { this.barSeriesHeight = this.tooltipUtil.getBarsHeight(bars) if (this.barSeriesHeight > 0) { @@ -881,7 +885,12 @@ export default class Tooltip { // de-activate first this.deactivateHoverFilter() - this.tooltipPosition.moveStickyTooltipOverBars(j, capturedSeries) + ttCtx.tooltipPosition.moveStickyTooltipOverBars(j, capturedSeries) + let points = ttCtx.tooltipUtil.getAllMarkers(true) + + if (points.length) { + handlePoints() + } for (let b = 0; b < paths.length; b++) { graphics.pathMouseEnter(paths[b]) diff --git a/src/modules/tooltip/Utils.js b/src/modules/tooltip/Utils.js index 798492984..2c3ec5dae 100644 --- a/src/modules/tooltip/Utils.js +++ b/src/modules/tooltip/Utils.js @@ -264,7 +264,7 @@ export default class Utils { ) } - getAllMarkers() { + getAllMarkers(filterCollapsed = false) { // first get all marker parents. This parent class contains series-index // which helps to sort the markers as they are dynamic let markersWraps = this.w.globals.dom.baseEl.querySelectorAll( @@ -272,6 +272,14 @@ export default class Utils { ) markersWraps = [...markersWraps] + + if (filterCollapsed) { + markersWraps = markersWraps.filter((m) => { + const realIndex = Number(m.getAttribute('data:realIndex')) + return this.w.globals.collapsedSeriesIndices.indexOf(realIndex) === -1 + }) + } + markersWraps.sort((a, b) => { var indexA = Number(a.getAttribute('data:realIndex')) var indexB = Number(b.getAttribute('data:realIndex'))