Skip to content

Commit 117e39c

Browse files
committed
organize modebar attributes and defaults and register it
1 parent 97254b3 commit 117e39c

File tree

6 files changed

+74
-42
lines changed

6 files changed

+74
-42
lines changed

src/components/modebar/attributes.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
module.exports = {
4+
editType: 'modebar',
5+
6+
modebar: {
7+
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+
}
41+
};

src/components/modebar/defaults.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
var Lib = require('../../lib');
4+
var Color = require('../color');
5+
var attributes = require('./attributes');
6+
7+
module.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {
8+
function coerce(attr, dflt) {
9+
return Lib.coerce(layoutIn, layoutOut, attributes, attr, dflt);
10+
}
11+
12+
coerce('modebar.orientation');
13+
coerce('modebar.bgcolor', Color.addOpacity(layoutOut.paper_bgcolor, 0.5));
14+
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+
};

src/components/modebar/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
'use strict';
22

3-
exports.manage = require('./manage');
3+
module.exports = {
4+
moduleType: 'component',
5+
name: 'modebar',
6+
7+
layoutAttributes: require('./attributes'),
8+
supplyLayoutDefaults: require('./defaults'),
9+
10+
manage: require('./manage')
11+
};

src/core.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ register([
4444
require('./components/grid'),
4545
require('./components/errorbars'),
4646
require('./components/colorscale'),
47-
require('./components/colorbar')
47+
require('./components/colorbar'),
48+
require('./components/modebar')
4849
]);
4950

5051
// locales en and en-US are required for default behavior

src/plots/layout_attributes.js

-34
Original file line numberDiff line numberDiff line change
@@ -388,40 +388,6 @@ module.exports = {
388388
'make an item with matching `templateitemname` and `visible: false`.'
389389
].join(' ')
390390
},
391-
modebar: {
392-
orientation: {
393-
valType: 'enumerated',
394-
values: ['v', 'h'],
395-
dflt: 'h',
396-
editType: 'modebar',
397-
description: 'Sets the orientation of the modebar.'
398-
},
399-
bgcolor: {
400-
valType: 'color',
401-
editType: 'modebar',
402-
description: 'Sets the background color of the modebar.'
403-
},
404-
color: {
405-
valType: 'color',
406-
editType: 'modebar',
407-
description: 'Sets the color of the icons in the modebar.'
408-
},
409-
activecolor: {
410-
valType: 'color',
411-
editType: 'modebar',
412-
description: 'Sets the color of the active or hovered on icons in the modebar.'
413-
},
414-
uirevision: {
415-
valType: 'any',
416-
editType: 'none',
417-
description: [
418-
'Controls persistence of user-driven changes related to the modebar,',
419-
'including `hovermode`, `dragmode`, and `showspikes` at both the',
420-
'root level and inside subplots. Defaults to `layout.uirevision`.'
421-
].join(' ')
422-
},
423-
editType: 'modebar'
424-
},
425391

426392
newshape: drawNewShapeAttrs.newshape,
427393
activeshape: drawNewShapeAttrs.activeshape,

src/plots/plots.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1517,12 +1517,10 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut, formatObj) {
15171517
coerce('editrevision', uirevision);
15181518
coerce('selectionrevision', uirevision);
15191519

1520-
coerce('modebar.orientation');
1521-
coerce('modebar.bgcolor', Color.addOpacity(layoutOut.paper_bgcolor, 0.5));
1522-
var modebarDefaultColor = Color.contrast(Color.rgb(layoutOut.modebar.bgcolor));
1523-
coerce('modebar.color', Color.addOpacity(modebarDefaultColor, 0.3));
1524-
coerce('modebar.activecolor', Color.addOpacity(modebarDefaultColor, 0.7));
1525-
coerce('modebar.uirevision', uirevision);
1520+
Registry.getComponentMethod(
1521+
'modebar',
1522+
'supplyLayoutDefaults'
1523+
)(layoutIn, layoutOut);
15261524

15271525
Registry.getComponentMethod(
15281526
'shapes',

0 commit comments

Comments
 (0)