Skip to content

Commit

Permalink
Merge pull request #3480 from plotly/3478-fix-hovertemplate
Browse files Browse the repository at this point in the history
do not delete hoverlabel when hovertemplate is defined
  • Loading branch information
antoinerg authored Jan 28, 2019
2 parents e94ee3d + 7bff254 commit ea7941b
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/components/fx/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,8 +957,9 @@ function createHoverText(hoverData, opts, gd) {
if(d.extraText !== undefined) text += (text ? '<br>' : '') + d.extraText;

// if 'text' is empty at this point,
// and hovertemplate is not defined,
// put 'name' in main label and don't show secondary label
if(text === '') {
if(text === '' && !d.hovertemplate) {
// if 'name' is also empty, remove entire label
if(name === '') g.remove();
text = name;
Expand Down
1 change: 1 addition & 0 deletions test/jasmine/tests/pie_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,7 @@ describe('pie hovering', function() {
});

it('should use hovertemplate if specified', function(done) {
mockCopy.data[0].name = '';
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
.then(_hover)
.then(function() {
Expand Down
11 changes: 11 additions & 0 deletions test/jasmine/tests/scattergeo_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,17 @@ describe('Test scattergeo hover', function() {
.then(done);
});

it('should not hide hover label when hovertemplate', function(done) {
Plotly.restyle(gd, {
name: '',
hovertemplate: 'tpl %{lat}<extra>x</extra>'
}).then(function() {
check([381, 221], ['tpl 10', 'x']);
})
.catch(failTest)
.then(done);
});

it('should generate hover label info (\'text\' single value case)', function(done) {
Plotly.restyle(gd, 'text', 'text').then(function() {
check([381, 221], ['(10°, 10°)\ntext', null]);
Expand Down
21 changes: 21 additions & 0 deletions test/jasmine/tests/scattermapbox_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var destroyGraphDiv = require('../assets/destroy_graph_div');
var failTest = require('../assets/fail_test');
var supplyAllDefaults = require('../assets/supply_defaults');

var assertHoverLabelContent = require('../assets/custom_assertions').assertHoverLabelContent;
var mouseEvent = require('../assets/mouse_event');
var click = require('../assets/click');
var HOVERMINTIME = require('@src/components/fx').constants.HOVERMINTIME;
Expand Down Expand Up @@ -601,6 +602,15 @@ describe('@noCI scattermapbox hover', function() {
};
}

function checkHoverLabel(pos, content) {
mouseEvent('mousemove', pos[0], pos[1]);

assertHoverLabelContent({
nums: content[0],
name: content[1]
});
}

it('should generate hover label info (base case)', function() {
var xval = 11;
var yval = 11;
Expand Down Expand Up @@ -788,6 +798,17 @@ describe('@noCI scattermapbox hover', function() {
done();
});
});

it('should always display hoverlabel when hovertemplate is defined', function(done) {
Plotly.restyle(gd, {
name: '',
hovertemplate: 'tpl2<extra></extra>'
})
.then(function() {
checkHoverLabel([190, 215], ['tpl2', '']);
done();
});
});
});

describe('@noCI Test plotly events on a scattermapbox plot:', function() {
Expand Down
9 changes: 9 additions & 0 deletions test/jasmine/tests/scatterpolar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ describe('Test scatterpolar hover:', function() {
},
nums: 'template 4.02289202968 128.342009045',
name: 'Trial 3'
}, {
desc: 'with hovertemplate and empty trace name',
patch: function(fig) {
fig.data[2].hovertemplate = 'template %{r} %{theta}';
fig.data[2].name = '';
return fig;
},
nums: 'template 4.02289202968 128.342009045',
name: ''
}, {
desc: '(no labels - out of sector)',
patch: function(fig) {
Expand Down
33 changes: 31 additions & 2 deletions test/jasmine/tests/scatterternary_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ var failTest = require('../assets/fail_test');
var customAssertions = require('../assets/custom_assertions');
var supplyAllDefaults = require('../assets/supply_defaults');

var mouseEvent = require('../assets/mouse_event');
var assertHoverLabelContent = customAssertions.assertHoverLabelContent;

var assertClip = customAssertions.assertClip;
var assertNodeDisplay = customAssertions.assertNodeDisplay;

Expand Down Expand Up @@ -334,17 +337,24 @@ describe('scatterternary hover', function() {

var gd;

function check(pos, content) {
mouseEvent('mousemove', pos[0], pos[1]);

assertHoverLabelContent({
nums: content[0],
name: content[1]
});
}

beforeAll(function(done) {
gd = createGraphDiv();

var data = [{
type: 'scatterternary',
a: [0.1, 0.2, 0.3],
b: [0.3, 0.2, 0.1],
c: [0.1, 0.4, 0.5],
text: ['A', 'B', 'C']
}];

Plotly.plot(gd, data).then(done);
});

Expand Down Expand Up @@ -418,6 +428,25 @@ describe('scatterternary hover', function() {
.then(done);
});

it('should always display hoverlabel when hovertemplate is defined', function(done) {
var fig = Lib.extendDeep({}, require('@mocks/ternary_simple.json'));

Plotly.newPlot(gd, fig)
.then(function() {
return Plotly.restyle(gd, {
hovertemplate: '%{a}, %{b}, %{c}',
name: '',
text: null,
hovertext: null
});
})
.then(function() {
check([380, 210], ['0.5, 0.25, 0.25']);
})
.catch(failTest)
.then(done);
});

});

describe('Test scatterternary *cliponaxis*', function() {
Expand Down

0 comments on commit ea7941b

Please sign in to comment.