Skip to content

Commit 26d6384

Browse files
authored
Merge pull request #3537 from jakubkottnauer/ohlc-null-hover
Fix finance chart null item hover
2 parents ed7983c + 7b3f9c0 commit 26d6384

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/traces/ohlc/hover.js

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ function getClosestPoint(pointData, xval, yval, hovermode) {
7474
if(pointData.index === false) return null;
7575

7676
var di = cd[pointData.index];
77+
78+
if(di.empty) return null;
79+
7780
var dir = di.dir;
7881
var container = trace[dir];
7982
var lc = container.line.color;

test/jasmine/tests/finance_test.js

+39
Original file line numberDiff line numberDiff line change
@@ -1269,5 +1269,44 @@ describe('finance trace hover via Fx.hover():', function() {
12691269
.catch(failTest)
12701270
.then(done);
12711271
});
1272+
1273+
it('should ignore empty ' + type + ' item', function(done) {
1274+
// only the bar chart's hover will be displayed when hovering over the 3rd items
1275+
var x = ['time1', 'time2', 'time3', 'time4'];
1276+
1277+
Plotly.newPlot(gd, [{
1278+
x: x,
1279+
high: [6, 3, null, 8],
1280+
close: [4, 3, null, 8],
1281+
low: [5, 3, null, 8],
1282+
open: [3, 3, null, 8],
1283+
type: type
1284+
}, {
1285+
x: x,
1286+
y: [1, 2, 3, 4],
1287+
type: 'bar'
1288+
}], {
1289+
xaxis: { rangeslider: {visible: false} },
1290+
width: 500,
1291+
height: 500
1292+
})
1293+
.then(function() {
1294+
gd.on('plotly_hover', function(d) {
1295+
Plotly.Fx.hover(gd, [
1296+
{curveNumber: 0, pointNumber: d.points[0].pointNumber},
1297+
{curveNumber: 1, pointNumber: d.points[0].pointNumber}
1298+
]);
1299+
});
1300+
})
1301+
.then(function() { hover(281, 252); })
1302+
.then(function() {
1303+
assertHoverLabelContent({
1304+
nums: '(time3, 3)',
1305+
name: 'trace 1'
1306+
}, 'hover over 3rd items');
1307+
})
1308+
.catch(failTest)
1309+
.then(done);
1310+
});
12721311
});
12731312
});

0 commit comments

Comments
 (0)