Skip to content

Commit 81d07c0

Browse files
committed
Report center of hovered cell for heatmap with category axis
1 parent ce47785 commit 81d07c0

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

‎draftlogs/7960_fix.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
- Ensure that hoverlabels on category axes with hovermode "x", "y", "x unified" and "y unified" never include data points from other categories than the hovered one [[#7960](https://github.com/plotly/plotly.js/pull/7960)]
2+
- Fix heatmap hover on category axes to report the cell center, not the cell edge, as the point position [[#7960](https://github.com/plotly/plotly.js/pull/7960)]

‎src/traces/heatmap/hover.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, opts) {
8282
xl = xc ? _x[nx] : ((_x[nx] + _x[nx + 1]) / 2);
8383
yl = yc ? _y[ny] : ((_y[ny] + _y[ny + 1]) / 2);
8484

85-
if(xa && xa.type === 'category') xl = x[nx];
86-
if(ya && ya.type === 'category') yl = y[ny];
85+
// Report the cell center, which is the category position
86+
if (xa?.type === 'category') xl = (x[nx] + x[nx + 1]) / 2;
87+
if (ya?.type === 'category') yl = (y[ny] + y[ny + 1]) / 2;
8788

8889
if(trace.zsmooth) {
8990
x0 = x1 = xa.c2p(xl);

‎test/jasmine/tests/heatmap_test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ describe('heatmap hover', function() {
10161016
it('should find closest point (case 1) and should', function() {
10171017
var pt = _hover(gd, 3, 1)[0];
10181018
expect(pt.index).toEqual([1, 3], 'have correct index');
1019-
assertLabels(pt, 2.5, 0.5, 0);
1019+
assertLabels(pt, 3, 1, 0);
10201020
});
10211021
});
10221022

0 commit comments

Comments
 (0)