9
9
10
10
'use strict' ;
11
11
12
- var Lib = require ( '../../../lib' ) ;
13
12
var handleSubplotDefaults = require ( '../../subplot_defaults' ) ;
14
13
var constants = require ( '../constants' ) ;
15
14
var layoutAttributes = require ( './layout_attributes' ) ;
16
15
16
+ var axesNames = constants . axesNames ;
17
+
17
18
module . exports = function supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) {
18
19
handleSubplotDefaults ( layoutIn , layoutOut , fullData , {
19
20
type : 'geo' ,
@@ -28,21 +29,62 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce) {
28
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
34
var projType = coerce ( 'projection.type' , scopeParams . projType ) ;
35
- var isAlbersUsa = projType === 'albers usa' ;
36
- var isConic = projType . indexOf ( 'conic' ) !== - 1 ;
35
+ var isAlbersUsa = geoLayoutOut . _isAlbersUsa = projType === 'albers usa' ;
37
36
38
- if ( isConic ) {
39
- var dfltProjParallels = scopeParams . projParallels || [ 0 , 60 ] ;
40
- coerce ( 'projection.parallels' , dfltProjParallels ) ;
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
+ }
60
+
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
+ }
41
71
}
42
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
+
43
84
if ( ! isAlbersUsa ) {
44
- var dfltProjRotate = scopeParams . projRotate || [ 0 , 0 , 0 ] ;
45
- coerce ( 'projection.rotation.lon' , dfltProjRotate [ 0 ] ) ;
85
+ var dfltProjRotate = isScoped ? scopeParams . projRotate : [ centerLon , 0 , 0 ] ;
86
+
87
+ projLon = coerce ( 'projection.rotation.lon' , dfltProjRotate [ 0 ] ) ;
46
88
coerce ( 'projection.rotation.lat' , dfltProjRotate [ 1 ] ) ;
47
89
coerce ( 'projection.rotation.roll' , dfltProjRotate [ 2 ] ) ;
48
90
@@ -54,19 +96,17 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce) {
54
96
55
97
show = coerce ( 'showocean' ) ;
56
98
if ( show ) coerce ( 'oceancolor' ) ;
57
- } else {
58
- geoLayoutOut . scope = 'usa' ;
59
99
}
60
100
61
- coerce ( 'projection.scale' ) ;
62
-
63
- geoAxisDefaults ( geoLayoutIn , geoLayoutOut ) ;
101
+ coerce ( 'center.lon' , isScoped ? centerLon : projLon ) ;
102
+ coerce ( 'center.lat' , latRange [ 0 ] + ( latRange [ 1 ] - latRange [ 0 ] ) / 2 ) ;
64
103
65
- var lonRange = geoLayoutOut . lonaxis . range ;
66
- coerce ( 'center.lon' , lonRange [ 0 ] + ( lonRange [ 1 ] - lonRange [ 0 ] ) / 2 ) ;
104
+ if ( isConic ) {
105
+ var dfltProjParallels = scopeParams . projParallels || [ 0 , 60 ] ;
106
+ coerce ( 'projection.parallels' , dfltProjParallels ) ;
107
+ }
67
108
68
- var latRange = geoLayoutOut . lataxis . range ;
69
- coerce ( 'center.lat' , latRange [ 0 ] + ( latRange [ 1 ] - latRange [ 0 ] ) / 2 ) ;
109
+ coerce ( 'projection.scale' ) ;
70
110
71
111
show = coerce ( 'showland' ) ;
72
112
if ( show ) coerce ( 'landcolor' ) ;
@@ -105,64 +145,4 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce) {
105
145
}
106
146
107
147
coerce ( 'bgcolor' ) ;
108
-
109
- // bind a few helper field that are used downstream
110
- geoLayoutOut . _isClipped = ! ! constants . lonaxisSpan [ projType ] ;
111
- geoLayoutOut . _isScoped = isScoped ;
112
- geoLayoutOut . _isConic = isConic ;
113
- }
114
-
115
- function geoAxisDefaults ( geoLayoutIn , geoLayoutOut ) {
116
- var axesNames = constants . axesNames ;
117
- var axisName , axisIn , axisOut ;
118
-
119
- function coerce ( attr , dflt ) {
120
- return Lib . coerce ( axisIn , axisOut , layoutAttributes [ axisName ] , attr , dflt ) ;
121
- }
122
-
123
- function getRangeDflt ( ) {
124
- var scope = geoLayoutOut . scope ;
125
-
126
- if ( scope === 'world' ) {
127
- var projLayout = geoLayoutOut . projection ;
128
- var projType = projLayout . type ;
129
- var projRotation = projLayout . rotation ;
130
- var dfltSpans = constants [ axisName + 'Span' ] ;
131
-
132
- var halfSpan = dfltSpans [ projType ] !== undefined ?
133
- dfltSpans [ projType ] / 2 :
134
- dfltSpans [ '*' ] / 2 ;
135
-
136
- var rotateAngle = axisName === 'lonaxis' ?
137
- projRotation . lon :
138
- projRotation . lat ;
139
-
140
- return [ rotateAngle - halfSpan , rotateAngle + halfSpan ] ;
141
- } else {
142
- return constants . scopeDefaults [ scope ] [ axisName + 'Range' ] ;
143
- }
144
- }
145
-
146
- for ( var i = 0 ; i < axesNames . length ; i ++ ) {
147
- axisName = axesNames [ i ] ;
148
- axisIn = geoLayoutIn [ axisName ] || { } ;
149
- axisOut = { } ;
150
-
151
- var rangeDflt = getRangeDflt ( ) ;
152
- var range = coerce ( 'range' , rangeDflt ) ;
153
-
154
- Lib . noneOrAll ( axisIn . range , axisOut . range , [ 0 , 1 ] ) ;
155
-
156
- coerce ( 'tick0' , range [ 0 ] ) ;
157
- coerce ( 'dtick' , axisName === 'lonaxis' ? 30 : 10 ) ;
158
-
159
- var show = coerce ( 'showgrid' ) ;
160
- if ( show ) {
161
- coerce ( 'gridcolor' ) ;
162
- coerce ( 'gridwidth' ) ;
163
- }
164
-
165
- geoLayoutOut [ axisName ] = axisOut ;
166
- geoLayoutOut [ axisName ] . _fullRange = rangeDflt ;
167
- }
168
148
}
0 commit comments