From 0130bb1901734c0b0ebbcde1e6d062e2e1ed6dd5 Mon Sep 17 00:00:00 2001 From: junedchhipa Date: Thu, 12 Oct 2023 11:39:01 +0530 Subject: [PATCH] fix xposition in rangebar charts (for tooltips) --- src/charts/Bar.js | 38 ++++++++++++++++++++++++++------------ src/charts/RangeBar.js | 12 ++++++++++-- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/charts/Bar.js b/src/charts/Bar.js index 3adb20c72..eaba87bd3 100644 --- a/src/charts/Bar.js +++ b/src/charts/Bar.js @@ -518,18 +518,14 @@ class Bar { let barXPosition if (w.globals.isXNumeric) { - let sxI = realIndex - if (!w.globals.seriesX[realIndex].length) { - sxI = w.globals.maxValsInArrayIndex - } - if (w.globals.seriesX[sxI][j]) { - x = - (w.globals.seriesX[sxI][j] - w.globals.minX) / this.xRatio - - (barWidth * this.seriesLen) / 2 - } - - // re-calc barXPosition as x changed - barXPosition = x + barWidth * this.visibleI + const xForNumericX = this.getBarXForNumericXAxis({ + x, + j, + realIndex, + barWidth, + }) + x = xForNumericX.x + barXPosition = xForNumericX.barXPosition } else { if (w.config.plotOptions.bar.hideZeroBarsWhenGrouped) { const { nonZeroColumns, zeroEncounters } = @@ -584,6 +580,24 @@ class Bar { } } + getBarXForNumericXAxis({ x, barWidth, realIndex, j }) { + const w = this.w + let sxI = realIndex + if (!w.globals.seriesX[realIndex].length) { + sxI = w.globals.maxValsInArrayIndex + } + if (w.globals.seriesX[sxI][j]) { + x = + (w.globals.seriesX[sxI][j] - w.globals.minX) / this.xRatio - + (barWidth * this.seriesLen) / 2 + } + + return { + barXPosition: x + barWidth * this.visibleI, + x, + } + } + /** getPreviousPath is a common function for bars/columns which is used to get previous paths when data changes. * @memberof Bar * @param {int} realIndex - current iterating i diff --git a/src/charts/RangeBar.js b/src/charts/RangeBar.js index 2fe1114c9..5513528bd 100644 --- a/src/charts/RangeBar.js +++ b/src/charts/RangeBar.js @@ -1,7 +1,6 @@ import Bar from './Bar' import Graphics from '../modules/Graphics' import Utils from '../utils/Utils' -import DateTime from '../utils/DateTime' /** * ApexCharts RangeBar Class responsible for drawing Range/Timeline Bars. @@ -76,7 +75,7 @@ class RangeBar extends Bar { }) let elGoalsMarkers = graphics.group({ - class: 'apexcharts-rangebar-goals-markers' + class: 'apexcharts-rangebar-goals-markers', }) for (let j = 0; j < w.globals.dataPoints; j++) { @@ -354,6 +353,15 @@ class RangeBar extends Bar { if (!w.globals.isXNumeric) { x = x + xDivision + } else { + const xForNumericXAxis = this.getBarXForNumericXAxis({ + x, + j, + realIndex, + barWidth, + }) + x = xForNumericXAxis.x + barXPosition = xForNumericXAxis.barXPosition } return {