Skip to content

Commit dfd73b8

Browse files
committed
set Fx defaults after legend defaults so unified hover label can inherit
1 parent 6483ac9 commit dfd73b8

File tree

5 files changed

+43
-12
lines changed

5 files changed

+43
-12
lines changed

src/components/fx/hover.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ function createHoverText(hoverData, opts, gd) {
991991
legend: {
992992
title: {text: t0, font: fullLayout.hoverlabel.font},
993993
font: fullLayout.hoverlabel.font,
994-
bgcolor: fullLayout.hoverlabel.bgcolor || fullLayout.paper_bgcolor,
994+
bgcolor: fullLayout.hoverlabel.bgcolor,
995995
bordercolor: fullLayout.hoverlabel.bordercolor,
996996
borderwidth: 1,
997997
tracegroupgap: 7,

src/components/fx/hoverlabel_defaults.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ module.exports = function handleHoverLabelDefaults(contIn, contOut, coerce, opts
1616

1717
function inheritFontAttr(attr) {
1818
if(!opts.font[attr]) {
19-
if(contIn.legend && contIn.legend.font && contIn.legend.font[attr]) {
20-
opts.font[attr] = contIn.legend.font[attr];
21-
} else if(contIn.font && contIn.font[attr]) {
22-
opts.font[attr] = contIn.font[attr];
23-
}
19+
opts.font[attr] = contOut.legend ? contOut.legend.font[attr] : contOut.font[attr];
2420
}
2521
}
2622

27-
// In unified hover, inherit from legend if available
28-
if(contIn && isUnifiedHover(contIn.hovermode)) {
23+
// In unified hover, inherit from layout.legend if available or layout
24+
if(contOut && isUnifiedHover(contOut.hovermode)) {
2925
if(!opts.font) opts.font = {};
3026
inheritFontAttr('size');
3127
inheritFontAttr('family');
3228
inheritFontAttr('color');
3329

34-
if(!opts.bgcolor && contIn.legend && contIn.legend.bgcolor) opts.bgcolor = contIn.legend.bgcolor;
35-
if(!opts.bordercolor && contIn.legend && contIn.legend.bordercolor) opts.bordercolor = contIn.legend.bordercolor;
30+
if(contOut.legend) {
31+
if(!opts.bgcolor) opts.bgcolor = contOut.legend.bgcolor;
32+
if(!opts.bordercolor) opts.bordercolor = contOut.legend.bordercolor;
33+
} else {
34+
if(!opts.bgcolor) opts.bgcolor = contOut.paper_bgcolor;
35+
}
3636
}
3737

3838
coerce('hoverlabel.bgcolor', opts.bgcolor);

src/components/fx/layout_defaults.js

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var Lib = require('../../lib');
1212
var isUnifiedHover = require('./helpers').isUnifiedHover;
1313
var layoutAttributes = require('./layout_attributes');
1414
var handleHoverModeDefaults = require('./hovermode_defaults');
15+
var handleHoverLabelDefaults = require('./hoverlabel_defaults');
1516

1617
module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
1718
function coerce(attr, dflt) {
@@ -40,4 +41,6 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
4041
)) {
4142
layoutOut.dragmode = 'pan';
4243
}
44+
45+
handleHoverLabelDefaults(layoutIn, layoutOut, coerce);
4346
};

src/core.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ register(require('./traces/scatter'));
4242

4343
// register all registrable components modules
4444
register([
45-
require('./components/fx'),
4645
require('./components/legend'),
46+
require('./components/fx'),
4747
require('./components/annotations'),
4848
require('./components/annotations3d'),
4949
require('./components/shapes'),

test/jasmine/tests/hover_label_test.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -4376,7 +4376,21 @@ describe('hovermode: (x|y)unified', function() {
43764376

43774377
assertRectColor(bgcolor[2], bgcolor[2]);
43784378

4379-
// Finally, check that a hoverlabel.bgcolor defined in template wins
4379+
// Check that a legend.bgcolor defined in template works
4380+
delete mockCopy.layout;
4381+
mockCopy.layout = {
4382+
hovermode: 'x unified',
4383+
template: { layout: { legend: { bgcolor: bgcolor[1], bordercolor: bgcolor[1] } } }
4384+
};
4385+
4386+
return Plotly.newPlot(gd, mockCopy);
4387+
})
4388+
.then(function(gd) {
4389+
_hover(gd, { xval: 3 });
4390+
4391+
assertRectColor(bgcolor[1], bgcolor[1]);
4392+
4393+
// Check that a hoverlabel.bgcolor defined in template wins
43804394
delete mockCopy.layout;
43814395
mockCopy.layout = {
43824396
hovermode: 'x unified',
@@ -4431,6 +4445,20 @@ describe('hovermode: (x|y)unified', function() {
44314445

44324446
assertFont('Arial', '22px', 'rgb(30, 30, 30)');
44334447

4448+
// Check that a legend.font defined in template wins
4449+
delete mockCopy.layout;
4450+
mockCopy.layout = {
4451+
hovermode: 'x unified',
4452+
template: { layout: { legend: {font: {size: 5, family: 'Mono', color: 'rgb(5, 5, 5)'}}}},
4453+
};
4454+
4455+
return Plotly.newPlot(gd, mockCopy);
4456+
})
4457+
.then(function() {
4458+
_hover(gd, { xval: 3 });
4459+
4460+
assertFont('Mono', '5px', 'rgb(5, 5, 5)');
4461+
44344462
// Finally, check that a hoverlabel.font defined in template wins
44354463
delete mockCopy.layout;
44364464
mockCopy.layout = {

0 commit comments

Comments
 (0)