Skip to content

Commit cf61dc2

Browse files
committed
fixes #1600 - allow z cartesian traces to have a name hover label
1 parent be9e6b9 commit cf61dc2

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/components/fx/hover.js

+1-1
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

+46
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,53 @@ describe('hover info', function() {
444444

445445
done();
446446
});
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+
}
447465

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);
448494
});
449495
});
450496

0 commit comments

Comments
 (0)