Skip to content

Commit 8f60909

Browse files
authored
Merge pull request #4644 from plotly/rangebreaks-fix-bar-hover
Handle hover over rangebreaks for bar-like traces
2 parents 9072918 + a5c1a66 commit 8f60909

File tree

3 files changed

+85
-4
lines changed

3 files changed

+85
-4
lines changed

src/traces/bar/hover.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var Color = require('../../components/color');
1616
var fillText = require('../../lib').fillText;
1717
var getLineWidth = require('./helpers').getLineWidth;
1818
var hoverLabelText = require('../../plots/cartesian/axes').hoverLabelText;
19+
var BADNUM = require('../../constants/numerical').BADNUM;
1920

2021
function hoverPoints(pointData, xval, yval, hovermode) {
2122
var barPointData = hoverOnBars(pointData, xval, yval, hovermode);
@@ -131,6 +132,9 @@ function hoverOnBars(pointData, xval, yval, hovermode) {
131132
// skip the rest (for this trace) if we didn't find a close point
132133
if(pointData.index === false) return;
133134

135+
// skip points inside axis rangebreaks
136+
if(cd[pointData.index].p === BADNUM) return;
137+
134138
// if we get here and we're not in 'closest' mode, push min/max pos back
135139
// onto the group - even though that means occasionally the mouse will be
136140
// over the hover label.

test/jasmine/tests/axes_test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4022,8 +4022,6 @@ describe('Test axes', function() {
40224022
});
40234023

40244024
describe('*rangebreaks*', function() {
4025-
// TODO adapt `type: 'date'` requirement !!
4026-
40274025
describe('during doCalcdata', function() {
40284026
var gd;
40294027

test/jasmine/tests/hover_label_test.js

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2698,8 +2698,8 @@ describe('Hover on axes with rangebreaks', function() {
26982698
mouseEvent('mousemove', x, y);
26992699
}
27002700

2701-
function _assert(msg, exp) {
2702-
assertHoverLabelContent({ nums: exp.nums, axis: exp.axis }, msg + '| hover label');
2701+
function _assert(msg, exp, noHoverLabel) {
2702+
if(!noHoverLabel) assertHoverLabelContent({ nums: exp.nums, axis: exp.axis }, msg + '| hover label');
27032703
expect(eventData.x).toBe(exp.x, 'event data x');
27042704
expect(eventData.y).toBe(exp.y, 'event data y');
27052705
}
@@ -2772,6 +2772,85 @@ describe('Hover on axes with rangebreaks', function() {
27722772
.then(done);
27732773
});
27742774

2775+
it('should work when rangebreaks are present on y-axis using hovermode x (case of bar and autorange reversed)', function(done) {
2776+
Plotly.plot(gd, [{
2777+
type: 'bar',
2778+
orientation: 'h',
2779+
y: [
2780+
'1970-01-01 00:00:00.000',
2781+
'1970-01-01 00:00:00.010',
2782+
'1970-01-01 00:00:00.050',
2783+
'1970-01-01 00:00:00.090',
2784+
'1970-01-01 00:00:00.095',
2785+
'1970-01-01 00:00:00.100',
2786+
'1970-01-01 00:00:00.150',
2787+
'1970-01-01 00:00:00.190',
2788+
'1970-01-01 00:00:00.200'
2789+
],
2790+
x: [0, 1, 2, 3, 4, 5, 6, 7, 8]
2791+
}], {
2792+
yaxis: {
2793+
autorange: 'reversed',
2794+
rangebreaks: [
2795+
{bounds: [
2796+
'1970-01-01 00:00:00.011',
2797+
'1970-01-01 00:00:00.089'
2798+
]},
2799+
{bounds: [
2800+
'1970-01-01 00:00:00.101',
2801+
'1970-01-01 00:00:00.189'
2802+
]}
2803+
]
2804+
},
2805+
width: 400,
2806+
height: 400,
2807+
margin: {l: 10, t: 10, b: 10, r: 10},
2808+
hovermode: 'x'
2809+
})
2810+
.then(function() {
2811+
gd.on('plotly_hover', function(d) {
2812+
eventData = d.points[0];
2813+
});
2814+
})
2815+
.then(function() { _hover(50, 350); })
2816+
.then(function() {
2817+
_assert('1st test', {
2818+
axis: '1',
2819+
nums: 'Jan 1, 1970, 00:00:00.01',
2820+
y: '1970-01-01 00:00:00.01',
2821+
x: 1
2822+
});
2823+
})
2824+
.then(function() { _hover(200, 200); })
2825+
.then(function() {
2826+
_assert('2nd test', {
2827+
axis: '5',
2828+
nums: 'Jan 1, 1970, 00:00:00.1',
2829+
y: '1970-01-01 00:00:00.1',
2830+
x: 5
2831+
});
2832+
})
2833+
.then(function() { _hover(250, 150); }) // hover over break
2834+
.then(function() {
2835+
_assert('3rd test', {
2836+
// previous values
2837+
y: '1970-01-01 00:00:00.1',
2838+
x: 5
2839+
}, 'noHoverLabel');
2840+
})
2841+
.then(function() { _hover(350, 50); })
2842+
.then(function() {
2843+
_assert('4th test', {
2844+
axis: '8',
2845+
nums: 'Jan 1, 1970, 00:00:00.2',
2846+
y: '1970-01-01 00:00:00.2',
2847+
x: 8
2848+
});
2849+
})
2850+
.catch(failTest)
2851+
.then(done);
2852+
});
2853+
27752854
it('should work when rangebreaks are present on y-axis', function(done) {
27762855
Plotly.plot(gd, [{
27772856
mode: 'lines', // i.e. no autorange padding

0 commit comments

Comments
 (0)