-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathaxis_defaults.js
72 lines (53 loc) · 2.02 KB
/
axis_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
/**
* 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 constants = require('../../../constants/geo_constants');
var axisAttributes = require('./axis_attributes');
module.exports = function supplyGeoAxisLayoutDefaults(geoLayoutIn, geoLayoutOut) {
var axesNames = constants.axesNames;
var axisIn, axisOut;
function coerce(attr, dflt) {
return Lib.coerce(axisIn, axisOut, axisAttributes, attr, dflt);
}
function getRangeDflt(axisName) {
var scope = geoLayoutOut.scope;
var projLayout, projType, projRotation, rotateAngle, dfltSpans, halfSpan;
if(scope === 'world') {
projLayout = geoLayoutOut.projection;
projType = projLayout.type;
projRotation = projLayout.rotation;
dfltSpans = constants[axisName + 'Span'];
halfSpan = dfltSpans[projType]!==undefined ?
dfltSpans[projType] / 2 :
dfltSpans['*'] / 2;
rotateAngle = axisName==='lonaxis' ?
projRotation.lon :
projRotation.lat;
return [rotateAngle - halfSpan, rotateAngle + halfSpan];
}
else return constants.scopeDefaults[scope][axisName + 'Range'];
}
for(var i = 0; i < axesNames.length; i++) {
var axisName = axesNames[i];
axisIn = geoLayoutIn[axisName] || {};
axisOut = {};
var rangeDflt = getRangeDflt(axisName);
var range = coerce('range', rangeDflt);
Lib.noneOrAll(axisIn.range, axisOut.range, [0, 1]);
coerce('tick0', range[0]);
coerce('dtick', axisName==='lonaxis' ? 30 : 10);
var show = coerce('showgrid');
if(show) {
coerce('gridcolor');
coerce('gridwidth');
}
geoLayoutOut[axisName] = axisOut;
geoLayoutOut[axisName]._fullRange = rangeDflt;
}
};