@@ -8,17 +8,29 @@ describe('Test Geo layout defaults', function() {
8
8
var supplyLayoutDefaults = Geo . supplyLayoutDefaults ;
9
9
10
10
describe ( 'supplyLayoutDefaults' , function ( ) {
11
- var layoutIn , layoutOut ;
12
-
13
- var fullData = [ {
14
- type : 'scattergeo' ,
15
- geo : 'geo'
16
- } ] ;
11
+ var layoutIn , layoutOut , fullData ;
17
12
18
13
beforeEach ( function ( ) {
19
- layoutOut = { } ;
14
+ // if hasGeo is not at this stage, the default step is skipped
15
+ layoutOut = { _hasGeo : true } ;
16
+
17
+ // needs a geo-ref in a trace in order to be detected
18
+ fullData = [ { type : 'scattergeo' , geo : 'geo' } ] ;
20
19
} ) ;
21
20
21
+ var seaFields = [
22
+ 'showcoastlines' , 'coastlinecolor' , 'coastlinewidth' ,
23
+ 'showocean' , 'oceancolor'
24
+ ] ;
25
+
26
+ var subunitFields = [
27
+ 'showsubunits' , 'subunitcolor' , 'subunitwidth'
28
+ ] ;
29
+
30
+ var frameFields = [
31
+ 'showframe' , 'framecolor' , 'framewidth'
32
+ ] ;
33
+
22
34
it ( 'should not coerce projection.rotation if type is albers usa' , function ( ) {
23
35
layoutIn = {
24
36
geo : {
@@ -34,19 +46,25 @@ describe('Test Geo layout defaults', function() {
34
46
35
47
supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
36
48
expect ( layoutOut . geo . projection . rotation ) . toBeUndefined ( ) ;
49
+ } ) ;
50
+
51
+ it ( 'should not coerce projection.rotation if type is albers usa (converse)' , function ( ) {
52
+ layoutIn = {
53
+ geo : {
54
+ projection : {
55
+ rotation : {
56
+ lon : 10 ,
57
+ lat : 10
58
+ }
59
+ }
60
+ }
61
+ } ;
37
62
38
- delete layoutIn . geo . projection . type ;
39
- layoutOut = { } ;
40
63
supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
41
64
expect ( layoutOut . geo . projection . rotation ) . toBeDefined ( ) ;
42
65
} ) ;
43
66
44
67
it ( 'should not coerce coastlines and ocean if type is albers usa' , function ( ) {
45
- var fields = [
46
- 'showcoastlines' , 'coastlinecolor' , 'coastlinewidth' ,
47
- 'showocean' , 'oceancolor'
48
- ] ;
49
-
50
68
layoutIn = {
51
69
geo : {
52
70
projection : {
@@ -58,14 +76,21 @@ describe('Test Geo layout defaults', function() {
58
76
} ;
59
77
60
78
supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
61
- fields . forEach ( function ( field ) {
79
+ seaFields . forEach ( function ( field ) {
62
80
expect ( layoutOut . geo [ field ] ) . toBeUndefined ( ) ;
63
81
} ) ;
82
+ } ) ;
83
+
84
+ it ( 'should not coerce coastlines and ocean if type is albers usa (converse)' , function ( ) {
85
+ layoutIn = {
86
+ geo : {
87
+ showcoastlines : true ,
88
+ showocean : true
89
+ }
90
+ } ;
64
91
65
- delete layoutIn . geo . projection . type ;
66
- layoutOut = { } ;
67
92
supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
68
- fields . forEach ( function ( field ) {
93
+ seaFields . forEach ( function ( field ) {
69
94
expect ( layoutOut . geo [ field ] ) . toBeDefined ( ) ;
70
95
} ) ;
71
96
} ) ;
@@ -82,101 +107,124 @@ describe('Test Geo layout defaults', function() {
82
107
}
83
108
}
84
109
} ;
85
- layoutOut = { } ;
110
+
86
111
supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
87
112
}
88
113
89
114
projTypes . forEach ( function ( projType ) {
90
115
testOne ( projType ) ;
91
116
if ( projType . indexOf ( 'conic' ) !== - 1 ) {
92
117
expect ( layoutOut . geo . projection . parallels ) . toBeDefined ( ) ;
93
- } else {
118
+ }
119
+ else {
94
120
expect ( layoutOut . geo . projection . parallels ) . toBeUndefined ( ) ;
95
121
}
96
122
} ) ;
97
123
} ) ;
98
124
99
- it ( 'should coerce subunits only when available ' , function ( ) {
100
- var fields = [
101
- 'showsubunits' , 'subunitcolor' , 'subunitwidth'
102
- ] ;
103
-
125
+ it ( 'should coerce subunits only when available (usa case)' , function ( ) {
104
126
layoutIn = {
105
127
geo : { scope : 'usa' }
106
128
} ;
107
- layoutOut = { } ;
129
+
108
130
supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
109
- fields . forEach ( function ( field ) {
131
+ subunitFields . forEach ( function ( field ) {
110
132
expect ( layoutOut . geo [ field ] ) . toBeDefined ( ) ;
111
133
} ) ;
134
+ } ) ;
135
+
136
+ it ( 'should coerce subunits only when available (default case)' , function ( ) {
137
+ layoutIn = { geo : { } } ;
112
138
113
- delete layoutIn . geo . scope ;
114
- layoutOut = { } ;
115
139
supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
116
- fields . forEach ( function ( field ) {
140
+ subunitFields . forEach ( function ( field ) {
117
141
expect ( layoutOut . geo [ field ] ) . toBeUndefined ( ) ;
118
142
} ) ;
143
+ } ) ;
119
144
145
+ it ( 'should coerce subunits only when available (NA case)' , function ( ) {
120
146
layoutIn = {
121
147
geo : {
122
148
scope : 'north america' ,
123
149
resolution : 50
124
150
}
125
151
} ;
126
- layoutOut = { } ;
152
+
127
153
supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
128
- fields . forEach ( function ( field ) {
154
+ subunitFields . forEach ( function ( field ) {
129
155
expect ( layoutOut . geo [ field ] ) . toBeDefined ( ) ;
130
156
} ) ;
157
+ } ) ;
131
158
159
+ it ( 'should coerce subunits only when available (NA case 2)' , function ( ) {
132
160
layoutIn = {
133
161
geo : {
134
162
scope : 'north america' ,
135
163
resolution : '50'
136
164
}
137
165
} ;
138
- layoutOut = { } ;
166
+
139
167
supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
140
- fields . forEach ( function ( field ) {
168
+ subunitFields . forEach ( function ( field ) {
141
169
expect ( layoutOut . geo [ field ] ) . toBeDefined ( ) ;
142
170
} ) ;
171
+ } ) ;
172
+
173
+ it ( 'should coerce subunits only when available (NA case 2)' , function ( ) {
174
+ layoutIn = {
175
+ geo : {
176
+ scope : 'north america'
177
+ }
178
+ } ;
143
179
144
- delete layoutIn . geo . resolution ;
145
- layoutOut = { } ;
146
180
supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
147
- fields . forEach ( function ( field ) {
181
+ subunitFields . forEach ( function ( field ) {
148
182
expect ( layoutOut . geo [ field ] ) . toBeUndefined ( ) ;
149
183
} ) ;
150
184
} ) ;
151
185
152
186
it ( 'should not coerce frame unless for world scope' , function ( ) {
153
- var fields = [
154
- 'showframe' , 'framecolor' , 'framewidth'
155
- ] ,
156
- scopes = layoutAttributes . scope . values ;
187
+ var scopes = layoutAttributes . scope . values ;
157
188
158
189
function testOne ( scope ) {
159
190
layoutIn = {
160
191
geo : { scope : scope }
161
192
} ;
162
- layoutOut = { } ;
193
+
163
194
supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
164
195
}
165
196
166
197
scopes . forEach ( function ( scope ) {
167
198
testOne ( scope ) ;
168
199
if ( scope === 'world' ) {
169
- fields . forEach ( function ( field ) {
200
+ frameFields . forEach ( function ( field ) {
170
201
expect ( layoutOut . geo [ field ] ) . toBeDefined ( ) ;
171
202
} ) ;
172
- } else {
173
- fields . forEach ( function ( field ) {
203
+ }
204
+ else {
205
+ frameFields . forEach ( function ( field ) {
174
206
expect ( layoutOut . geo [ field ] ) . toBeUndefined ( ) ;
175
207
} ) ;
176
208
}
177
209
} ) ;
178
210
} ) ;
179
211
212
+ it ( 'should add geo data-only geos into layoutIn' , function ( ) {
213
+ layoutIn = { } ;
214
+ fullData = [ { type : 'scattergeo' , geo : 'geo' } ] ;
215
+
216
+ supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
217
+ expect ( layoutIn . geo ) . toEqual ( { } ) ;
218
+ } ) ;
219
+
220
+ it ( 'should add geo data-only geos into layoutIn (converse)' , function ( ) {
221
+ layoutIn = { } ;
222
+ fullData = [ { type : 'scatter' } ] ;
223
+
224
+ supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
225
+ expect ( layoutIn . geo ) . toBe ( undefined ) ;
226
+ } ) ;
227
+
180
228
} ) ;
181
229
182
230
} ) ;
0 commit comments