Skip to content

Commit

Permalink
fix xposition in rangebar charts (for tooltips)
Browse files Browse the repository at this point in the history
  • Loading branch information
junedchhipa committed Oct 12, 2023
1 parent 394237c commit 0130bb1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
38 changes: 26 additions & 12 deletions src/charts/Bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } =
Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions src/charts/RangeBar.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0130bb1

Please sign in to comment.