-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathdefaults.js
More file actions
57 lines (51 loc) · 2.14 KB
/
defaults.js
File metadata and controls
57 lines (51 loc) · 2.14 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'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.visible');
coerce('newshape.name');
coerce('newshape.showlegend');
coerce('newshape.legend');
coerce('newshape.legendwidth');
coerce('newshape.legendgroup');
coerce('newshape.legendgrouptitle.text');
Lib.coerceFont(coerce, 'newshape.legendgrouptitle.font');
coerce('newshape.legendrank');
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');
coerce('newshape.label.texttemplatefallback');
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');
};