Skip to content

Commit bba9f3c

Browse files
committed
fix ohlc/candlestick hover when high===low
1 parent 46a177a commit bba9f3c

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/traces/ohlc/hover.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ function getClosestPoint(pointData, xval, yval, hovermode) {
6161
}
6262

6363
function dy(di) {
64-
return Fx.inbox(di[minAttr] - yval, di[maxAttr] - yval, hoverPseudoDistance);
64+
var min = di[minAttr];
65+
var max = di[maxAttr];
66+
return min === max || Fx.inbox(min - yval, max - yval, hoverPseudoDistance);
6567
}
6668

6769
function dxy(di) { return (dx(di) + dy(di)) / 2; }

test/jasmine/tests/finance_test.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -1113,8 +1113,8 @@ describe('finance trace hover:', function() {
11131113
margin: {t: 0, b: 0, l: 0, r: 0, pad: 0}
11141114
}, specs.layout || {});
11151115

1116-
var xval = 'xval' in specs ? specs.xvals : 0;
1117-
var yval = 'yval' in specs ? specs.yvals : 1;
1116+
var xval = 'xval' in specs ? specs.xval : 0;
1117+
var yval = 'yval' in specs ? specs.yval : 1;
11181118
var hovermode = layout.hovermode || 'x';
11191119

11201120
return Plotly.plot(gd, data, layout).then(function() {
@@ -1136,7 +1136,6 @@ describe('finance trace hover:', function() {
11361136
var actual = results[0];
11371137
var exp = specs.exp;
11381138

1139-
11401139
for(var k in exp) {
11411140
var msg = '- key ' + k;
11421141
expect(actual[k]).toBe(exp[k], msg);
@@ -1187,6 +1186,21 @@ describe('finance trace hover:', function() {
11871186
exp: {
11881187
extraText: 'A'
11891188
}
1189+
}, {
1190+
type: type,
1191+
desc: 'when high === low in *closest* mode',
1192+
traces: [{
1193+
high: [6, null, 7, 8],
1194+
close: [4, null, 7, 8],
1195+
low: [5, null, 7, 8],
1196+
open: [3, null, 7, 8]
1197+
}],
1198+
layout: {hovermode: 'closest'},
1199+
xval: 2,
1200+
yval: 6.9,
1201+
exp: {
1202+
extraText: 'open: 7<br>high: 7<br>low: 7<br>close: 7 ▲'
1203+
}
11901204
}]
11911205
.forEach(function(specs) {
11921206
it('should generate correct hover labels ' + type + ' - ' + specs.desc, function(done) {

0 commit comments

Comments
 (0)