12
12
var handleSubplotDefaults = require ( '../../subplot_defaults' ) ;
13
13
var constants = require ( '../constants' ) ;
14
14
var layoutAttributes = require ( './layout_attributes' ) ;
15
- var supplyGeoAxisLayoutDefaults = require ( './axis_defaults' ) ;
16
15
16
+ var axesNames = constants . axesNames ;
17
17
18
18
module . exports = function supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) {
19
19
handleSubplotDefaults ( layoutIn , layoutOut , fullData , {
@@ -27,24 +27,64 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
27
27
function handleGeoDefaults ( geoLayoutIn , geoLayoutOut , coerce ) {
28
28
var show ;
29
29
30
+ var resolution = coerce ( 'resolution' ) ;
30
31
var scope = coerce ( 'scope' ) ;
31
- var isScoped = ( scope !== 'world' ) ;
32
32
var scopeParams = constants . scopeDefaults [ scope ] ;
33
33
34
- var resolution = coerce ( 'resolution' ) ;
35
-
36
34
var projType = coerce ( 'projection.type' , scopeParams . projType ) ;
37
- var isAlbersUsa = projType === 'albers usa' ;
38
- var isConic = projType . indexOf ( 'conic' ) !== - 1 ;
35
+ var isAlbersUsa = geoLayoutOut . _isAlbersUsa = projType === 'albers usa' ;
36
+
37
+ // no other scopes are allowed for 'albers usa' projection
38
+ if ( isAlbersUsa ) scope = geoLayoutOut . scope = 'usa' ;
39
+
40
+ var isScoped = geoLayoutOut . _isScoped = ( scope !== 'world' ) ;
41
+ var isConic = geoLayoutOut . _isConic = projType . indexOf ( 'conic' ) !== - 1 ;
42
+ geoLayoutOut . _isClipped = ! ! constants . lonaxisSpan [ projType ] ;
43
+
44
+ for ( var i = 0 ; i < axesNames . length ; i ++ ) {
45
+ var axisName = axesNames [ i ] ;
46
+ var dtickDflt = [ 30 , 10 ] [ i ] ;
47
+ var rangeDflt ;
48
+
49
+ if ( isScoped ) {
50
+ rangeDflt = scopeParams [ axisName + 'Range' ] ;
51
+ } else {
52
+ var dfltSpans = constants [ axisName + 'Span' ] ;
53
+ var hSpan = ( dfltSpans [ projType ] || dfltSpans [ '*' ] ) / 2 ;
54
+ var rot = coerce (
55
+ 'projection.rotation.' + axisName . substr ( 0 , 3 ) ,
56
+ scopeParams . projRotate [ i ]
57
+ ) ;
58
+ rangeDflt = [ rot - hSpan , rot + hSpan ] ;
59
+ }
39
60
40
- if ( isConic ) {
41
- var dfltProjParallels = scopeParams . projParallels || [ 0 , 60 ] ;
42
- coerce ( 'projection.parallels' , dfltProjParallels ) ;
61
+ var range = coerce ( axisName + '.range' , rangeDflt ) ;
62
+
63
+ coerce ( axisName + '.tick0' , range [ 0 ] ) ;
64
+ coerce ( axisName + '.dtick' , dtickDflt ) ;
65
+
66
+ show = coerce ( axisName + '.showgrid' ) ;
67
+ if ( show ) {
68
+ coerce ( axisName + '.gridcolor' ) ;
69
+ coerce ( axisName + '.gridwidth' ) ;
70
+ }
43
71
}
44
72
73
+ var lonRange = geoLayoutOut . lonaxis . range ;
74
+ var latRange = geoLayoutOut . lataxis . range ;
75
+
76
+ // to cross antimeridian w/o ambiguity
77
+ var lon0 = lonRange [ 0 ] ;
78
+ var lon1 = lonRange [ 1 ] ;
79
+ if ( lon0 > 0 && lon1 < 0 ) lon1 += 360 ;
80
+
81
+ var centerLon = lon0 + ( lon1 - lon0 ) / 2 ;
82
+ var projLon ;
83
+
45
84
if ( ! isAlbersUsa ) {
46
- var dfltProjRotate = scopeParams . projRotate || [ 0 , 0 , 0 ] ;
47
- coerce ( 'projection.rotation.lon' , dfltProjRotate [ 0 ] ) ;
85
+ var dfltProjRotate = isScoped ? scopeParams . projRotate : [ centerLon , 0 , 0 ] ;
86
+
87
+ projLon = coerce ( 'projection.rotation.lon' , dfltProjRotate [ 0 ] ) ;
48
88
coerce ( 'projection.rotation.lat' , dfltProjRotate [ 1 ] ) ;
49
89
coerce ( 'projection.rotation.roll' , dfltProjRotate [ 2 ] ) ;
50
90
@@ -57,7 +97,28 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce) {
57
97
show = coerce ( 'showocean' ) ;
58
98
if ( show ) coerce ( 'oceancolor' ) ;
59
99
}
60
- else geoLayoutOut . scope = 'usa' ;
100
+
101
+ var centerLonDflt ;
102
+ var centerLatDflt ;
103
+
104
+ if ( isAlbersUsa ) {
105
+ // 'albers usa' does not have a 'center',
106
+ // these values were found using via:
107
+ // projection.invert([geoLayout.center.lon, geoLayoutIn.center.lat])
108
+ centerLonDflt = - 96.6 ;
109
+ centerLatDflt = 38.7 ;
110
+ } else {
111
+ centerLonDflt = isScoped ? centerLon : projLon ;
112
+ centerLatDflt = latRange [ 0 ] + ( latRange [ 1 ] - latRange [ 0 ] ) / 2 ;
113
+ }
114
+
115
+ coerce ( 'center.lon' , centerLonDflt ) ;
116
+ coerce ( 'center.lat' , centerLatDflt ) ;
117
+
118
+ if ( isConic ) {
119
+ var dfltProjParallels = scopeParams . projParallels || [ 0 , 60 ] ;
120
+ coerce ( 'projection.parallels' , dfltProjParallels ) ;
121
+ }
61
122
62
123
coerce ( 'projection.scale' ) ;
63
124
@@ -98,20 +159,4 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce) {
98
159
}
99
160
100
161
coerce ( 'bgcolor' ) ;
101
-
102
- supplyGeoAxisLayoutDefaults ( geoLayoutIn , geoLayoutOut ) ;
103
-
104
- // bind a few helper variables
105
- geoLayoutOut . _isHighRes = resolution === 50 ;
106
- geoLayoutOut . _clipAngle = constants . lonaxisSpan [ projType ] / 2 ;
107
- geoLayoutOut . _isAlbersUsa = isAlbersUsa ;
108
- geoLayoutOut . _isConic = isConic ;
109
- geoLayoutOut . _isScoped = isScoped ;
110
-
111
- var rotation = geoLayoutOut . projection . rotation || { } ;
112
- geoLayoutOut . projection . _rotate = [
113
- - rotation . lon || 0 ,
114
- - rotation . lat || 0 ,
115
- rotation . roll || 0
116
- ] ;
117
162
}
0 commit comments