Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d5c220f

Browse files
authored
Merge pull request plotly#631 from plotly/hover-resize-fix
Fix hover label after resize bug
2 parents 2c7c2db + d0887b8 commit d5c220f

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/plots/cartesian/graph_interact.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,13 @@ function hover(gd, evt, subplot) {
337337
// 'cartesian' case
338338
var plotObj = plots[spId];
339339
if(plotObj) {
340-
xaArray[i] = plotObj.xaxis;
341-
yaArray[i] = plotObj.yaxis;
340+
341+
// TODO make sure that fullLayout_plots axis refs
342+
// get updated properly so that we don't have
343+
// to use Axes.getFromId in general.
344+
345+
xaArray[i] = Axes.getFromId(gd, plotObj.xaxis._id);
346+
yaArray[i] = Axes.getFromId(gd, plotObj.yaxis._id);
342347
continue;
343348
}
344349

test/jasmine/tests/hover_label_test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var d3 = require('d3');
22

33
var Plotly = require('@lib/index');
44
var Fx = require('@src/plots/cartesian/graph_interact');
5+
var constants = require('@src/plots/cartesian/constants');
56
var Lib = require('@src/lib');
67

78
var createGraphDiv = require('../assets/create_graph_div');
@@ -605,3 +606,49 @@ describe('hover info on overlaid subplots', function() {
605606
}).then(done);
606607
});
607608
});
609+
610+
describe('hover after resizing', function() {
611+
'use strict';
612+
613+
afterEach(destroyGraphDiv);
614+
615+
function assertLabelCount(pos, cnt, msg) {
616+
return new Promise(function(resolve) {
617+
mouseEvent('mousemove', pos[0], pos[1]);
618+
619+
setTimeout(function() {
620+
var hoverText = d3.selectAll('g.hovertext');
621+
expect(hoverText.size()).toEqual(cnt, msg);
622+
623+
resolve();
624+
}, constants.HOVERMINTIME);
625+
});
626+
}
627+
628+
it('should work', function(done) {
629+
var data = [{ y: [2, 1, 2] }],
630+
layout = { width: 600, height: 500 },
631+
gd = createGraphDiv();
632+
633+
var pos0 = [311, 409],
634+
pos1 = [407, 128];
635+
636+
Plotly.plot(gd, data, layout).then(function() {
637+
return assertLabelCount(pos0, 1, 'before resize, showing pt label');
638+
}).then(function() {
639+
return assertLabelCount(pos1, 0, 'before resize, not showing blank spot');
640+
}).then(function() {
641+
return Plotly.relayout(gd, 'width', 500);
642+
}).then(function() {
643+
return assertLabelCount(pos0, 0, 'after resize, not showing blank spot');
644+
}).then(function() {
645+
return assertLabelCount(pos1, 1, 'after resize, showing pt label');
646+
}).then(function() {
647+
return Plotly.relayout(gd, 'width', 600);
648+
}).then(function() {
649+
return assertLabelCount(pos0, 1, 'back to initial, showing pt label');
650+
}).then(function() {
651+
return assertLabelCount(pos1, 0, 'back to initial, not showing blank spot');
652+
}).then(done);
653+
});
654+
});

0 commit comments

Comments
 (0)