-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathdefaults.js
43 lines (37 loc) · 1.71 KB
/
defaults.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
var Color = require('../../color');
var Lib = require('../../../lib');
function dfltLabelYanchor(isLine, labelTextPosition) {
// If shape is a line, default y-anchor is 'bottom' (so that text is above line by default)
// Otherwise, default y-anchor is equal to y-component of `textposition`
// (so that text is positioned inside shape bounding box by default)
return isLine ? 'bottom' :
labelTextPosition.indexOf('top') !== -1 ? 'top' :
labelTextPosition.indexOf('bottom') !== -1 ? 'bottom' : 'middle';
}
module.exports = function supplyDrawNewShapeDefaults(layoutIn, layoutOut, coerce) {
coerce('newshape.drawdirection');
coerce('newshape.layer');
coerce('newshape.fillcolor');
coerce('newshape.fillrule');
coerce('newshape.opacity');
var newshapeLineWidth = coerce('newshape.line.width');
if(newshapeLineWidth) {
var bgcolor = (layoutIn || {}).plot_bgcolor || '#FFF';
coerce('newshape.line.color', Color.contrast(bgcolor));
coerce('newshape.line.dash');
}
var isLine = layoutIn.dragmode === 'drawline';
var labelText = coerce('newshape.label.text');
var labelTextTemplate = coerce('newshape.label.texttemplate');
if(labelText || labelTextTemplate) {
coerce('newshape.label.textangle');
var labelTextPosition = coerce('newshape.label.textposition', isLine ? 'middle' : 'middle center');
coerce('newshape.label.xanchor');
coerce('newshape.label.yanchor', dfltLabelYanchor(isLine, labelTextPosition));
coerce('newshape.label.padding');
Lib.coerceFont(coerce, 'newshape.label.font', layoutOut.font);
}
coerce('activeshape.fillcolor');
coerce('activeshape.opacity');
};