-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathshape_defaults.js
74 lines (55 loc) · 1.9 KB
/
shape_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
var Lib = require('../../lib');
var Axes = require('../../plots/cartesian/axes');
var attributes = require('./attributes');
var helpers = require('./helpers');
module.exports = function handleShapeDefaults(shapeIn, shapeOut, fullLayout, opts) {
opts = opts || {};
function coerce(attr, dflt) {
return Lib.coerce(shapeIn, shapeOut, attributes, attr, dflt);
}
var visible = coerce('visible', !opts.itemIsNotPlainObject);
if(!visible) return shapeOut;
coerce('layer');
coerce('opacity');
coerce('fillcolor');
coerce('line.color');
coerce('line.width');
coerce('line.dash');
var dfltType = shapeIn.path ? 'path' : 'rect',
shapeType = coerce('type', dfltType);
// positioning
var axLetters = ['x', 'y'];
for(var i = 0; i < 2; i++) {
var axLetter = axLetters[i],
tdMock = {_fullLayout: fullLayout};
// xref, yref
var axRef = Axes.coerceRef(shapeIn, shapeOut, tdMock, axLetter);
if(shapeType !== 'path') {
var dflt0 = 0.25,
dflt1 = 0.75;
if(axRef !== 'paper') {
var ax = Axes.getFromId(tdMock, axRef),
convertFn = helpers.linearToData(ax);
dflt0 = convertFn(ax.range[0] + dflt0 * (ax.range[1] - ax.range[0]));
dflt1 = convertFn(ax.range[0] + dflt1 * (ax.range[1] - ax.range[0]));
}
// x0, x1 (and y0, y1)
coerce(axLetter + '0', dflt0);
coerce(axLetter + '1', dflt1);
}
}
if(shapeType === 'path') {
coerce('path');
} else {
Lib.noneOrAll(shapeIn, shapeOut, ['x0', 'x1', 'y0', 'y1']);
}
return shapeOut;
};