Skip to content

Commit 295659e

Browse files
committed
add fx supplyDefaults method
- to coerce hoverlabel container in a DRY way
1 parent 3ac4c07 commit 295659e

File tree

5 files changed

+84
-3
lines changed

5 files changed

+84
-3
lines changed

src/components/fx/attributes.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var extendFlat = require('../../lib/extend').extendFlat;
12+
var fontAttrs = require('../../plots/font_attributes');
13+
14+
module.exports = {
15+
hoverlabel: {
16+
bgcolor: {
17+
valType: 'color',
18+
role: 'style',
19+
arrayOk: true,
20+
description: [
21+
'Sets the background color of the hover labels for this trace'
22+
].join(' ')
23+
},
24+
bordercolor: {
25+
valType: 'color',
26+
role: 'style',
27+
arrayOk: true,
28+
description: [
29+
'Sets the border color of the hover labels for this trace.'
30+
].join(' ')
31+
},
32+
font: {
33+
family: extendFlat({}, fontAttrs.family, { arrayOk: true }),
34+
size: extendFlat({}, fontAttrs.size, { arrayOk: true }),
35+
color: extendFlat({}, fontAttrs.color, { arrayOk: true })
36+
}
37+
}
38+
};

src/components/fx/defaults.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Lib = require('../../lib');
12+
var attributes = require('./attributes');
13+
var handleHoverLabelDefaults = require('./hoverlabel_defaults');
14+
15+
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
16+
function coerce(attr, dflt) {
17+
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
18+
}
19+
20+
handleHoverLabelDefaults(traceIn, traceOut, coerce, layout.hoverlabel);
21+
};
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Lib = require('../../lib');
12+
13+
module.exports = function handleHoverLabelDefaults(contIn, contOut, coerce, opts) {
14+
opts = opts || {};
15+
16+
coerce('hoverlabel.bgcolor', opts.bgcolor);
17+
coerce('hoverlabel.bordercolor', opts.bordercolor);
18+
Lib.coerceFont(coerce, 'hoverlabel.font', opts.font);
19+
};

src/components/fx/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ module.exports = {
2323
layout: layoutAttributes
2424
},
2525

26+
attributes: require('./attributes'),
2627
layoutAttributes: layoutAttributes,
28+
supplyDefaults: require('./defaults'),
2729
supplyLayoutDefaults: require('./layout_defaults'),
2830

2931
calc: require('./calc'),

src/plots/plots.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -846,9 +846,10 @@ plots.supplyTraceDefaults = function(traceIn, traceOutIndex, layout, traceInInde
846846
coerce('legendgroup');
847847
}
848848

849-
coerce('hoverlabel.bgcolor');
850-
coerce('hoverlabel.bordercolor');
851-
Lib.coerceFont(coerce, 'hoverlabel.font');
849+
Registry.getComponentMethod(
850+
'fx',
851+
'supplyDefaults'
852+
)(traceIn, traceOut, defaultColor, layout);
852853

853854
// TODO add per-base-plot-module trace defaults step
854855

0 commit comments

Comments
 (0)