@@ -8,17 +8,29 @@ describe('Test Geo layout defaults', function() {
88 var supplyLayoutDefaults = Geo . supplyLayoutDefaults ;
99
1010 describe ( 'supplyLayoutDefaults' , function ( ) {
11- var layoutIn , layoutOut ;
12-
13- var fullData = [ {
14- type : 'scattergeo' ,
15- geo : 'geo'
16- } ] ;
11+ var layoutIn , layoutOut , fullData ;
1712
1813 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' } ] ;
2019 } ) ;
2120
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+
2234 it ( 'should not coerce projection.rotation if type is albers usa' , function ( ) {
2335 layoutIn = {
2436 geo : {
@@ -34,19 +46,25 @@ describe('Test Geo layout defaults', function() {
3446
3547 supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
3648 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+ } ;
3762
38- delete layoutIn . geo . projection . type ;
39- layoutOut = { } ;
4063 supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
4164 expect ( layoutOut . geo . projection . rotation ) . toBeDefined ( ) ;
4265 } ) ;
4366
4467 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-
5068 layoutIn = {
5169 geo : {
5270 projection : {
@@ -58,14 +76,21 @@ describe('Test Geo layout defaults', function() {
5876 } ;
5977
6078 supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
61- fields . forEach ( function ( field ) {
79+ seaFields . forEach ( function ( field ) {
6280 expect ( layoutOut . geo [ field ] ) . toBeUndefined ( ) ;
6381 } ) ;
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+ } ;
6491
65- delete layoutIn . geo . projection . type ;
66- layoutOut = { } ;
6792 supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
68- fields . forEach ( function ( field ) {
93+ seaFields . forEach ( function ( field ) {
6994 expect ( layoutOut . geo [ field ] ) . toBeDefined ( ) ;
7095 } ) ;
7196 } ) ;
@@ -82,101 +107,124 @@ describe('Test Geo layout defaults', function() {
82107 }
83108 }
84109 } ;
85- layoutOut = { } ;
110+
86111 supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
87112 }
88113
89114 projTypes . forEach ( function ( projType ) {
90115 testOne ( projType ) ;
91116 if ( projType . indexOf ( 'conic' ) !== - 1 ) {
92117 expect ( layoutOut . geo . projection . parallels ) . toBeDefined ( ) ;
93- } else {
118+ }
119+ else {
94120 expect ( layoutOut . geo . projection . parallels ) . toBeUndefined ( ) ;
95121 }
96122 } ) ;
97123 } ) ;
98124
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 ( ) {
104126 layoutIn = {
105127 geo : { scope : 'usa' }
106128 } ;
107- layoutOut = { } ;
129+
108130 supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
109- fields . forEach ( function ( field ) {
131+ subunitFields . forEach ( function ( field ) {
110132 expect ( layoutOut . geo [ field ] ) . toBeDefined ( ) ;
111133 } ) ;
134+ } ) ;
135+
136+ it ( 'should coerce subunits only when available (default case)' , function ( ) {
137+ layoutIn = { geo : { } } ;
112138
113- delete layoutIn . geo . scope ;
114- layoutOut = { } ;
115139 supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
116- fields . forEach ( function ( field ) {
140+ subunitFields . forEach ( function ( field ) {
117141 expect ( layoutOut . geo [ field ] ) . toBeUndefined ( ) ;
118142 } ) ;
143+ } ) ;
119144
145+ it ( 'should coerce subunits only when available (NA case)' , function ( ) {
120146 layoutIn = {
121147 geo : {
122148 scope : 'north america' ,
123149 resolution : 50
124150 }
125151 } ;
126- layoutOut = { } ;
152+
127153 supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
128- fields . forEach ( function ( field ) {
154+ subunitFields . forEach ( function ( field ) {
129155 expect ( layoutOut . geo [ field ] ) . toBeDefined ( ) ;
130156 } ) ;
157+ } ) ;
131158
159+ it ( 'should coerce subunits only when available (NA case 2)' , function ( ) {
132160 layoutIn = {
133161 geo : {
134162 scope : 'north america' ,
135163 resolution : '50'
136164 }
137165 } ;
138- layoutOut = { } ;
166+
139167 supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
140- fields . forEach ( function ( field ) {
168+ subunitFields . forEach ( function ( field ) {
141169 expect ( layoutOut . geo [ field ] ) . toBeDefined ( ) ;
142170 } ) ;
171+ } ) ;
172+
173+ it ( 'should coerce subunits only when available (NA case 2)' , function ( ) {
174+ layoutIn = {
175+ geo : {
176+ scope : 'north america'
177+ }
178+ } ;
143179
144- delete layoutIn . geo . resolution ;
145- layoutOut = { } ;
146180 supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
147- fields . forEach ( function ( field ) {
181+ subunitFields . forEach ( function ( field ) {
148182 expect ( layoutOut . geo [ field ] ) . toBeUndefined ( ) ;
149183 } ) ;
150184 } ) ;
151185
152186 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 ;
157188
158189 function testOne ( scope ) {
159190 layoutIn = {
160191 geo : { scope : scope }
161192 } ;
162- layoutOut = { } ;
193+
163194 supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
164195 }
165196
166197 scopes . forEach ( function ( scope ) {
167198 testOne ( scope ) ;
168199 if ( scope === 'world' ) {
169- fields . forEach ( function ( field ) {
200+ frameFields . forEach ( function ( field ) {
170201 expect ( layoutOut . geo [ field ] ) . toBeDefined ( ) ;
171202 } ) ;
172- } else {
173- fields . forEach ( function ( field ) {
203+ }
204+ else {
205+ frameFields . forEach ( function ( field ) {
174206 expect ( layoutOut . geo [ field ] ) . toBeUndefined ( ) ;
175207 } ) ;
176208 }
177209 } ) ;
178210 } ) ;
179211
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+
180228 } ) ;
181229
182230} ) ;
0 commit comments