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

Skip to content

Commit 409b771

Browse files
authored
Merge pull request plotly#1627 from plotly/hover-misc-bugs
Hover bugs plotly#1575 and plotly#1600
2 parents 8321959 + cf61dc2 commit 409b771

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

src/components/fx/hover.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ function createHoverText(hoverData, opts) {
696696
// to get custom 'name' labels pass cleanPoint
697697
if(d.nameOverride !== undefined) d.name = d.nameOverride;
698698

699-
if(d.name && d.zLabelVal === undefined) {
699+
if(d.name) {
700700
// strip out our pseudo-html elements from d.name (if it exists at all)
701701
name = svgTextUtils.plainText(d.name || '');
702702

test/jasmine/tests/hover_label_test.js

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@ var fail = require('../assets/fail_test');
1616
describe('hover info', function() {
1717
'use strict';
1818

19-
var mock = require('@mocks/14.json'),
20-
evt = {
21-
clientX: mock.layout.width / 2,
22-
clientY: mock.layout.height / 2
23-
};
19+
var mock = require('@mocks/14.json');
20+
var evt = { xpx: 355, ypx: 150 };
2421

2522
afterEach(destroyGraphDiv);
2623

@@ -447,7 +444,53 @@ describe('hover info', function() {
447444

448445
done();
449446
});
447+
});
448+
});
449+
450+
describe('\'hover info for x/y/z traces', function() {
451+
function _hover(gd, xpx, ypx) {
452+
Fx.hover(gd, { xpx: xpx, ypx: ypx }, 'xy');
453+
delete gd._lastHoverTime;
454+
}
455+
456+
function _assert(nameLabel, lines) {
457+
expect(d3.select('g.axistext').size()).toEqual(0, 'no common label');
458+
459+
var sel = d3.select('g.hovertext');
460+
expect(sel.select('text.name').html()).toEqual(nameLabel, 'name label');
461+
sel.select('text.nums').selectAll('tspan').each(function(_, i) {
462+
expect(d3.select(this).html()).toEqual(lines[i], 'lines ' + i);
463+
});
464+
}
450465

466+
it('should display correct label content', function(done) {
467+
var gd = createGraphDiv();
468+
469+
Plotly.plot(gd, [{
470+
type: 'heatmap',
471+
y: [0, 1],
472+
z: [[1, 2, 3], [2, 2, 1]],
473+
name: 'one',
474+
}, {
475+
type: 'heatmap',
476+
y: [2, 3],
477+
z: [[1, 2, 3], [2, 2, 1]],
478+
name: 'two'
479+
}], {
480+
width: 500,
481+
height: 400,
482+
margin: {l: 0, t: 0, r: 0, b: 0}
483+
})
484+
.then(function() {
485+
_hover(gd, 250, 100);
486+
_assert('two', ['x: 1', 'y: 3', 'z: 2']);
487+
})
488+
.then(function() {
489+
_hover(gd, 250, 300);
490+
_assert('one', ['x: 1', 'y: 1', 'z: 2']);
491+
})
492+
.catch(fail)
493+
.then(done);
451494
});
452495
});
453496

0 commit comments

Comments
 (0)