Skip to content

Fix hover label after resize bug #631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/plots/cartesian/graph_interact.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,13 @@ function hover(gd, evt, subplot) {
// 'cartesian' case
var plotObj = plots[spId];
if(plotObj) {
xaArray[i] = plotObj.xaxis;
yaArray[i] = plotObj.yaxis;

// TODO make sure that fullLayout_plots axis refs
// get updated properly so that we don't have
// to use Axes.getFromId in general.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you open an issue for this so we don't forget?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Done in #634


xaArray[i] = Axes.getFromId(gd, plotObj.xaxis._id);
yaArray[i] = Axes.getFromId(gd, plotObj.yaxis._id);
continue;
}

Expand Down
47 changes: 47 additions & 0 deletions test/jasmine/tests/hover_label_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var d3 = require('d3');

var Plotly = require('@lib/index');
var Fx = require('@src/plots/cartesian/graph_interact');
var constants = require('@src/plots/cartesian/constants');
var Lib = require('@src/lib');

var createGraphDiv = require('../assets/create_graph_div');
Expand Down Expand Up @@ -605,3 +606,49 @@ describe('hover info on overlaid subplots', function() {
}).then(done);
});
});

describe('hover after resizing', function() {
'use strict';

afterEach(destroyGraphDiv);

function assertLabelCount(pos, cnt, msg) {
return new Promise(function(resolve) {
mouseEvent('mousemove', pos[0], pos[1]);

setTimeout(function() {
var hoverText = d3.selectAll('g.hovertext');
expect(hoverText.size()).toEqual(cnt, msg);

resolve();
}, constants.HOVERMINTIME);
});
}

it('should work', function(done) {
var data = [{ y: [2, 1, 2] }],
layout = { width: 600, height: 500 },
gd = createGraphDiv();

var pos0 = [311, 409],
pos1 = [407, 128];

Plotly.plot(gd, data, layout).then(function() {
return assertLabelCount(pos0, 1, 'before resize, showing pt label');
}).then(function() {
return assertLabelCount(pos1, 0, 'before resize, not showing blank spot');
}).then(function() {
return Plotly.relayout(gd, 'width', 500);
}).then(function() {
return assertLabelCount(pos0, 0, 'after resize, not showing blank spot');
}).then(function() {
return assertLabelCount(pos1, 1, 'after resize, showing pt label');
}).then(function() {
return Plotly.relayout(gd, 'width', 600);
}).then(function() {
return assertLabelCount(pos0, 1, 'back to initial, showing pt label');
}).then(function() {
return assertLabelCount(pos1, 0, 'back to initial, not showing blank spot');
}).then(done);
});
});