Skip to content

Commit 0130bb1

Browse files
committed
fix xposition in rangebar charts (for tooltips)
1 parent 394237c commit 0130bb1

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

src/charts/Bar.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -518,18 +518,14 @@ class Bar {
518518
let barXPosition
519519

520520
if (w.globals.isXNumeric) {
521-
let sxI = realIndex
522-
if (!w.globals.seriesX[realIndex].length) {
523-
sxI = w.globals.maxValsInArrayIndex
524-
}
525-
if (w.globals.seriesX[sxI][j]) {
526-
x =
527-
(w.globals.seriesX[sxI][j] - w.globals.minX) / this.xRatio -
528-
(barWidth * this.seriesLen) / 2
529-
}
530-
531-
// re-calc barXPosition as x changed
532-
barXPosition = x + barWidth * this.visibleI
521+
const xForNumericX = this.getBarXForNumericXAxis({
522+
x,
523+
j,
524+
realIndex,
525+
barWidth,
526+
})
527+
x = xForNumericX.x
528+
barXPosition = xForNumericX.barXPosition
533529
} else {
534530
if (w.config.plotOptions.bar.hideZeroBarsWhenGrouped) {
535531
const { nonZeroColumns, zeroEncounters } =
@@ -584,6 +580,24 @@ class Bar {
584580
}
585581
}
586582

583+
getBarXForNumericXAxis({ x, barWidth, realIndex, j }) {
584+
const w = this.w
585+
let sxI = realIndex
586+
if (!w.globals.seriesX[realIndex].length) {
587+
sxI = w.globals.maxValsInArrayIndex
588+
}
589+
if (w.globals.seriesX[sxI][j]) {
590+
x =
591+
(w.globals.seriesX[sxI][j] - w.globals.minX) / this.xRatio -
592+
(barWidth * this.seriesLen) / 2
593+
}
594+
595+
return {
596+
barXPosition: x + barWidth * this.visibleI,
597+
x,
598+
}
599+
}
600+
587601
/** getPreviousPath is a common function for bars/columns which is used to get previous paths when data changes.
588602
* @memberof Bar
589603
* @param {int} realIndex - current iterating i

src/charts/RangeBar.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Bar from './Bar'
22
import Graphics from '../modules/Graphics'
33
import Utils from '../utils/Utils'
4-
import DateTime from '../utils/DateTime'
54

65
/**
76
* ApexCharts RangeBar Class responsible for drawing Range/Timeline Bars.
@@ -76,7 +75,7 @@ class RangeBar extends Bar {
7675
})
7776

7877
let elGoalsMarkers = graphics.group({
79-
class: 'apexcharts-rangebar-goals-markers'
78+
class: 'apexcharts-rangebar-goals-markers',
8079
})
8180

8281
for (let j = 0; j < w.globals.dataPoints; j++) {
@@ -354,6 +353,15 @@ class RangeBar extends Bar {
354353

355354
if (!w.globals.isXNumeric) {
356355
x = x + xDivision
356+
} else {
357+
const xForNumericXAxis = this.getBarXForNumericXAxis({
358+
x,
359+
j,
360+
realIndex,
361+
barWidth,
362+
})
363+
x = xForNumericXAxis.x
364+
barXPosition = xForNumericXAxis.barXPosition
357365
}
358366

359367
return {

0 commit comments

Comments
 (0)