Skip to content

Commit 3933b88

Browse files
committed
fixup template defaults and modebar attributes
1 parent dd842bd commit 3933b88

File tree

3 files changed

+74
-64
lines changed

3 files changed

+74
-64
lines changed

src/components/modebar/attributes.js

+52-56
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,58 @@
33
module.exports = {
44
editType: 'modebar',
55

6-
modebar: {
6+
orientation: {
7+
valType: 'enumerated',
8+
values: ['v', 'h'],
9+
dflt: 'h',
710
editType: 'modebar',
8-
9-
orientation: {
10-
valType: 'enumerated',
11-
values: ['v', 'h'],
12-
dflt: 'h',
13-
editType: 'modebar',
14-
description: 'Sets the orientation of the modebar.'
15-
},
16-
bgcolor: {
17-
valType: 'color',
18-
editType: 'modebar',
19-
description: 'Sets the background color of the modebar.'
20-
},
21-
color: {
22-
valType: 'color',
23-
editType: 'modebar',
24-
description: 'Sets the color of the icons in the modebar.'
25-
},
26-
activecolor: {
27-
valType: 'color',
28-
editType: 'modebar',
29-
description: 'Sets the color of the active or hovered on icons in the modebar.'
30-
},
31-
uirevision: {
32-
valType: 'any',
33-
editType: 'none',
34-
description: [
35-
'Controls persistence of user-driven changes related to the modebar,',
36-
'including `hovermode`, `dragmode`, and `showspikes` at both the',
37-
'root level and inside subplots. Defaults to `layout.uirevision`.'
38-
].join(' ')
39-
},
40-
buttonstoadd: {
41-
valType: 'flaglist',
42-
flags: [
43-
'v1hovermode',
44-
'hoverclosest',
45-
'hovercompare',
46-
'togglehover',
47-
'togglespikelines',
48-
'drawclosedpath',
49-
'drawopenpath',
50-
'drawline',
51-
'drawrect',
52-
'drawcircle',
53-
'eraseshape',
54-
],
55-
dflt: '',
56-
editType: 'modebar',
57-
description: [
58-
'Determines which predefined modebar buttons to add.',
59-
'Please note that these buttons will only be shown if they are compatible',
60-
'with all trace types used in a graph.'
61-
].join(' ')
62-
}
11+
description: 'Sets the orientation of the modebar.'
12+
},
13+
bgcolor: {
14+
valType: 'color',
15+
editType: 'modebar',
16+
description: 'Sets the background color of the modebar.'
17+
},
18+
color: {
19+
valType: 'color',
20+
editType: 'modebar',
21+
description: 'Sets the color of the icons in the modebar.'
22+
},
23+
activecolor: {
24+
valType: 'color',
25+
editType: 'modebar',
26+
description: 'Sets the color of the active or hovered on icons in the modebar.'
27+
},
28+
uirevision: {
29+
valType: 'any',
30+
editType: 'none',
31+
description: [
32+
'Controls persistence of user-driven changes related to the modebar,',
33+
'including `hovermode`, `dragmode`, and `showspikes` at both the',
34+
'root level and inside subplots. Defaults to `layout.uirevision`.'
35+
].join(' ')
36+
},
37+
buttonstoadd: {
38+
valType: 'flaglist',
39+
flags: [
40+
'v1hovermode',
41+
'hoverclosest',
42+
'hovercompare',
43+
'togglehover',
44+
'togglespikelines',
45+
'drawclosedpath',
46+
'drawopenpath',
47+
'drawline',
48+
'drawrect',
49+
'drawcircle',
50+
'eraseshape',
51+
],
52+
dflt: '',
53+
editType: 'modebar',
54+
description: [
55+
'Determines which predefined modebar buttons to add.',
56+
'Please note that these buttons will only be shown if they are compatible',
57+
'with all trace types used in a graph.'
58+
].join(' ')
6359
}
6460
};

src/components/modebar/defaults.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22

33
var Lib = require('../../lib');
44
var Color = require('../color');
5+
var Template = require('../../plot_api/plot_template');
56
var attributes = require('./attributes');
67

78
module.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {
9+
var containerIn = layoutIn.modebar || {};
10+
var containerOut = Template.newContainer(layoutOut, 'modebar');
11+
812
function coerce(attr, dflt) {
9-
return Lib.coerce(layoutIn, layoutOut, attributes, attr, dflt);
13+
return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);
1014
}
1115

12-
coerce('modebar.orientation');
13-
coerce('modebar.bgcolor', Color.addOpacity(layoutOut.paper_bgcolor, 0.5));
16+
coerce('orientation');
17+
coerce('bgcolor', Color.addOpacity(layoutOut.paper_bgcolor, 0.5));
1418
var defaultColor = Color.contrast(Color.rgb(layoutOut.modebar.bgcolor));
15-
coerce('modebar.color', Color.addOpacity(defaultColor, 0.3));
16-
coerce('modebar.activecolor', Color.addOpacity(defaultColor, 0.7));
17-
coerce('modebar.uirevision', layoutOut.uirevision);
18-
coerce('modebar.buttonstoadd');
19+
coerce('color', Color.addOpacity(defaultColor, 0.3));
20+
coerce('activecolor', Color.addOpacity(defaultColor, 0.7));
21+
coerce('uirevision', layoutOut.uirevision);
22+
coerce('buttonstoadd');
1923
};

test/jasmine/tests/modebar_test.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,7 @@ describe('ModeBar', function() {
15601560
.then(done, done.fail);
15611561
});
15621562

1563-
it('add and remove predefined shape drawing and hover buttons via layout.modebar.buttonstoadd', function(done) {
1563+
it('add and remove predefined shape drawing and hover buttons via layout.modebar.buttonstoadd and template', function(done) {
15641564
function countButtons() {
15651565
var modeBarEl = gd._fullLayout._modeBar.element;
15661566
return d3Select(modeBarEl).selectAll('a.modebar-btn').size();
@@ -1631,6 +1631,16 @@ describe('ModeBar', function() {
16311631
})
16321632
.then(function() {
16331633
expect(countButtons()).toBe(initial + 1, 'skip invalid');
1634+
1635+
return Plotly.relayout(gd, 'modebar.buttonstoadd', '');
1636+
})
1637+
.then(function() {
1638+
expect(countButtons()).toBe(initial);
1639+
1640+
return Plotly.relayout(gd, 'template.layout.modebar.buttonstoadd', 'v1hovermode');
1641+
})
1642+
.then(function() {
1643+
expect(countButtons()).toBe(initial + 2, 'via template');
16341644
})
16351645
.then(done, done.fail);
16361646
});

0 commit comments

Comments
 (0)