Skip to content

Commit 9269352

Browse files
committed
revert heatmap hover and only return early when z is undefined and hoverongaps is false
- adjust new tests to make sure plotly_hover is not triggered on gaps when hoverongaps is false
1 parent fbaf636 commit 9269352

File tree

3 files changed

+36
-35
lines changed

3 files changed

+36
-35
lines changed

src/traces/heatmap/hover.js

+20-22
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,30 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLay
8888
}
8989
}
9090

91+
var zVal = z[ny][nx];
92+
if(zmask && !zmask[ny][nx]) zVal = undefined;
93+
94+
if(zVal === undefined && !trace.hoverongaps) return;
95+
9196
var text;
9297
if(Array.isArray(cd0.hovertext) && Array.isArray(cd0.hovertext[ny])) {
9398
text = cd0.hovertext[ny][nx];
9499
} else if(Array.isArray(cd0.text) && Array.isArray(cd0.text[ny])) {
95100
text = cd0.text[ny][nx];
96101
}
97102

98-
var obj = {
103+
// dummy axis for formatting the z value
104+
var cOpts = extractOpts(trace);
105+
var dummyAx = {
106+
type: 'linear',
107+
range: [cOpts.min, cOpts.max],
108+
hoverformat: zhoverformat,
109+
_separators: xa._separators,
110+
_numFormat: xa._numFormat
111+
};
112+
var zLabel = Axes.tickText(dummyAx, zVal, 'hover').text;
113+
114+
return [Lib.extendFlat(pointData, {
99115
index: [ny, nx],
100116
// never let a 2D override 1D type as closest point
101117
distance: pointData.maxHoverDistance,
@@ -106,26 +122,8 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLay
106122
y1: y1,
107123
xLabelVal: xl,
108124
yLabelVal: yl,
125+
zLabelVal: zVal,
126+
zLabel: zLabel,
109127
text: text
110-
};
111-
112-
var zVal = z[ny][nx];
113-
if(zmask && !zmask[ny][nx]) zVal = undefined;
114-
115-
if(zVal !== undefined || trace.hoverongaps) {
116-
// dummy axis for formatting the z value
117-
var cOpts = extractOpts(trace);
118-
var dummyAx = {
119-
type: 'linear',
120-
range: [cOpts.min, cOpts.max],
121-
hoverformat: zhoverformat,
122-
_separators: xa._separators,
123-
_numFormat: xa._numFormat
124-
};
125-
126-
obj.zLabelVal = zVal;
127-
obj.zLabel = Axes.tickText(dummyAx, zVal, 'hover').text;
128-
}
129-
130-
return [Lib.extendFlat(pointData, obj)];
128+
})];
131129
};

test/jasmine/tests/contour_test.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -619,13 +619,6 @@ describe('contour hover', function() {
619619
return hoverData;
620620
}
621621

622-
function assertLabels(hoverPoint, xLabel, yLabel, zLabel, text) {
623-
expect(hoverPoint.xLabelVal).toBe(xLabel, 'have correct x label');
624-
expect(hoverPoint.yLabelVal).toBe(yLabel, 'have correct y label');
625-
expect(hoverPoint.zLabelVal).toBe(zLabel, 'have correct z label');
626-
expect(hoverPoint.text).toBe(text, 'have correct text label');
627-
}
628-
629622
describe('missing data', function() {
630623
beforeAll(function(done) {
631624
gd = createGraphDiv();
@@ -643,11 +636,16 @@ describe('contour hover', function() {
643636
});
644637
afterAll(destroyGraphDiv);
645638

646-
it('should not create zLabels when hovering on missing data and hoverongaps is disabled', function() {
639+
it('should not display hover on missing data and hoverongaps is disabled', function() {
647640
var pt = _hover(gd, 10, 100)[0];
648641

649-
expect(pt.index).toEqual([0, 0], 'have correct index');
650-
assertLabels(pt, 10, 100, undefined);
642+
var hoverData;
643+
gd.on('plotly_hover', function(data) {
644+
hoverData = data;
645+
});
646+
647+
expect(hoverData).toEqual(undefined);
648+
expect(pt).toEqual(undefined);
651649
});
652650
});
653651
});

test/jasmine/tests/heatmap_test.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -994,11 +994,16 @@ describe('heatmap hover', function() {
994994
});
995995
afterAll(destroyGraphDiv);
996996

997-
it('should not create zLabels when hovering on missing data and hoverongaps is disabled', function() {
997+
it('should not display hover on missing data and hoverongaps is disabled', function() {
998998
var pt = _hover(gd, 10, 100)[0];
999999

1000-
expect(pt.index).toEqual([0, 0], 'have correct index');
1001-
assertLabels(pt, 10, 100, undefined);
1000+
var hoverData;
1001+
gd.on('plotly_hover', function(data) {
1002+
hoverData = data;
1003+
});
1004+
1005+
expect(hoverData).toEqual(undefined);
1006+
expect(pt).toEqual(undefined);
10021007
});
10031008
});
10041009
});

0 commit comments

Comments
 (0)