Skip to content

Commit 0f3a4d7

Browse files
committed
shared tooltip fix in bar chart; fixes #3439
1 parent cfe1ca9 commit 0f3a4d7

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

src/charts/Bar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class Bar {
139139
w.config.yaxis[this.yaxisIndex] &&
140140
w.config.yaxis[this.yaxisIndex].reversed
141141

142-
let initPositions = this.barHelpers.initialPositions()
142+
let initPositions = this.barHelpers.initialPositions(realIndex)
143143

144144
y = initPositions.y
145145
barHeight = initPositions.barHeight

src/charts/BoxCandleStick.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class BoxCandleStick extends Bar {
7474
translationsIndex = realIndex
7575
}
7676

77-
let initPositions = this.barHelpers.initialPositions()
77+
let initPositions = this.barHelpers.initialPositions(realIndex)
7878

7979
y = initPositions.y
8080
barHeight = initPositions.barHeight

src/charts/RangeBar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class RangeBar extends Bar {
5959
translationsIndex = realIndex
6060
}
6161

62-
let initPositions = this.barHelpers.initialPositions()
62+
let initPositions = this.barHelpers.initialPositions(realIndex)
6363

6464
y = initPositions.y
6565
zeroW = initPositions.zeroW

src/charts/common/bar/Helpers.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default class Helpers {
5050
}
5151
}
5252

53-
initialPositions() {
53+
initialPositions(realIndex) {
5454
let w = this.w
5555
let x, y, yDivision, xDivision, barHeight, barWidth, zeroH, zeroW
5656

@@ -136,9 +136,19 @@ export default class Helpers {
136136
? this.barCtx.baseLineY[this.barCtx.translationsIndex] * 2
137137
: 0)
138138

139-
x =
140-
w.globals.padHorizontal +
141-
Utils.noExponents(xDivision - barWidth * this.barCtx.seriesLen) / 2
139+
if (w.globals.isXNumeric) {
140+
const xForNumericX = this.barCtx.getBarXForNumericXAxis({
141+
x,
142+
j: 0,
143+
realIndex,
144+
barWidth,
145+
})
146+
x = xForNumericX.x
147+
} else {
148+
x =
149+
w.globals.padHorizontal +
150+
Utils.noExponents(xDivision - barWidth * this.barCtx.seriesLen) / 2
151+
}
142152
}
143153

144154
w.globals.barHeight = barHeight

src/modules/tooltip/Utils.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,18 @@ export default class Utils {
172172
const xArr = Xarrays[i]
173173
const yArr = Yarrays[i]
174174

175-
// Ensure both xArr and yArr have equal lengths and valid data
176175
const len = Math.min(xArr.length, yArr.length)
177176

178177
for (let j = 0; j < len; j++) {
179178
const xVal = xArr[j]
180-
const yVal = yArr[j]
181-
182179
const distX = hoverX - xVal
183-
const distY = hoverY - yVal
184-
const dist = Math.sqrt(distX * distX + distY * distY)
180+
let dist = Math.sqrt(distX * distX)
181+
182+
if (!w.globals.allSeriesHasEqualX) {
183+
const yVal = yArr[j]
184+
const distY = hoverY - yVal
185+
dist = Math.sqrt(distX * distX + distY * distY)
186+
}
185187

186188
if (dist < closestDist) {
187189
closestDist = dist

0 commit comments

Comments
 (0)