Skip to content

Commit 0601640

Browse files
committed
test: merge geo test suites into 1
1 parent 6b2c16a commit 0601640

File tree

3 files changed

+328
-336
lines changed

3 files changed

+328
-336
lines changed

test/jasmine/tests/geo_interact_test.js renamed to test/jasmine/tests/geo_test.js

+328-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,341 @@
1-
var d3 = require('d3');
2-
31
var Plotly = require('@lib/index');
42
var Lib = require('@src/lib');
53

4+
var Geo = require('@src/plots/geo');
5+
var params = require('@src/plots/geo/constants');
6+
var supplyLayoutDefaults = require('@src/plots/geo/layout/axis_defaults');
7+
8+
var d3 = require('d3');
69
var createGraphDiv = require('../assets/create_graph_div');
710
var destroyGraphDiv = require('../assets/destroy_graph_div');
811
var mouseEvent = require('../assets/mouse_event');
912

1013
var HOVERMINTIME = require('@src/plots/cartesian/constants').HOVERMINTIME;
1114

1215

16+
describe('Test geoaxes', function() {
17+
'use strict';
18+
19+
describe('supplyLayoutDefaults', function() {
20+
var geoLayoutIn,
21+
geoLayoutOut;
22+
23+
beforeEach(function() {
24+
geoLayoutOut = {};
25+
});
26+
27+
it('should default to lon(lat)range to params non-world scopes', function() {
28+
var scopeDefaults = params.scopeDefaults,
29+
scopes = Object.keys(scopeDefaults),
30+
customLonaxisRange = [-42.21313312, 40.321321],
31+
customLataxisRange = [-42.21313312, 40.321321];
32+
33+
var dfltLonaxisRange, dfltLataxisRange;
34+
35+
scopes.forEach(function(scope) {
36+
if(scope === 'world') return;
37+
38+
dfltLonaxisRange = scopeDefaults[scope].lonaxisRange;
39+
dfltLataxisRange = scopeDefaults[scope].lataxisRange;
40+
41+
geoLayoutIn = {};
42+
geoLayoutOut = {scope: scope};
43+
44+
supplyLayoutDefaults(geoLayoutIn, geoLayoutOut);
45+
expect(geoLayoutOut.lonaxis.range).toEqual(dfltLonaxisRange);
46+
expect(geoLayoutOut.lataxis.range).toEqual(dfltLataxisRange);
47+
expect(geoLayoutOut.lonaxis.tick0).toEqual(dfltLonaxisRange[0]);
48+
expect(geoLayoutOut.lataxis.tick0).toEqual(dfltLataxisRange[0]);
49+
50+
geoLayoutIn = {
51+
lonaxis: {range: customLonaxisRange},
52+
lataxis: {range: customLataxisRange}
53+
};
54+
geoLayoutOut = {scope: scope};
55+
56+
supplyLayoutDefaults(geoLayoutIn, geoLayoutOut);
57+
expect(geoLayoutOut.lonaxis.range).toEqual(customLonaxisRange);
58+
expect(geoLayoutOut.lataxis.range).toEqual(customLataxisRange);
59+
expect(geoLayoutOut.lonaxis.tick0).toEqual(customLonaxisRange[0]);
60+
expect(geoLayoutOut.lataxis.tick0).toEqual(customLataxisRange[0]);
61+
});
62+
});
63+
64+
it('should adjust default lon(lat)range to projection.rotation in world scopes', function() {
65+
var expectedLonaxisRange, expectedLataxisRange;
66+
67+
function testOne() {
68+
supplyLayoutDefaults(geoLayoutIn, geoLayoutOut);
69+
expect(geoLayoutOut.lonaxis.range).toEqual(expectedLonaxisRange);
70+
expect(geoLayoutOut.lataxis.range).toEqual(expectedLataxisRange);
71+
}
72+
73+
geoLayoutIn = {};
74+
geoLayoutOut = {
75+
scope: 'world',
76+
projection: {
77+
type: 'equirectangular',
78+
rotation: {
79+
lon: -75,
80+
lat: 45
81+
}
82+
}
83+
};
84+
expectedLonaxisRange = [-255, 105]; // => -75 +/- 180
85+
expectedLataxisRange = [-45, 135]; // => 45 +/- 90
86+
testOne();
87+
88+
geoLayoutIn = {};
89+
geoLayoutOut = {
90+
scope: 'world',
91+
projection: {
92+
type: 'orthographic',
93+
rotation: {
94+
lon: -75,
95+
lat: 45
96+
}
97+
}
98+
};
99+
expectedLonaxisRange = [-165, 15]; // => -75 +/- 90
100+
expectedLataxisRange = [-45, 135]; // => 45 +/- 90
101+
testOne();
102+
103+
geoLayoutIn = {
104+
lonaxis: {range: [-42.21313312, 40.321321]},
105+
lataxis: {range: [-42.21313312, 40.321321]}
106+
};
107+
expectedLonaxisRange = [-42.21313312, 40.321321];
108+
expectedLataxisRange = [-42.21313312, 40.321321];
109+
testOne();
110+
});
111+
});
112+
});
113+
114+
describe('Test Geo layout defaults', function() {
115+
'use strict';
116+
117+
var layoutAttributes = Geo.layoutAttributes;
118+
var supplyLayoutDefaults = Geo.supplyLayoutDefaults;
119+
120+
describe('supplyLayoutDefaults', function() {
121+
var layoutIn, layoutOut, fullData;
122+
123+
beforeEach(function() {
124+
layoutOut = {};
125+
126+
// needs a geo-ref in a trace in order to be detected
127+
fullData = [{ type: 'scattergeo', geo: 'geo' }];
128+
});
129+
130+
var seaFields = [
131+
'showcoastlines', 'coastlinecolor', 'coastlinewidth',
132+
'showocean', 'oceancolor'
133+
];
134+
135+
var subunitFields = [
136+
'showsubunits', 'subunitcolor', 'subunitwidth'
137+
];
138+
139+
var frameFields = [
140+
'showframe', 'framecolor', 'framewidth'
141+
];
142+
143+
it('should not coerce projection.rotation if type is albers usa', function() {
144+
layoutIn = {
145+
geo: {
146+
projection: {
147+
type: 'albers usa',
148+
rotation: {
149+
lon: 10,
150+
lat: 10
151+
}
152+
}
153+
}
154+
};
155+
156+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
157+
expect(layoutOut.geo.projection.rotation).toBeUndefined();
158+
});
159+
160+
it('should not coerce projection.rotation if type is albers usa (converse)', function() {
161+
layoutIn = {
162+
geo: {
163+
projection: {
164+
rotation: {
165+
lon: 10,
166+
lat: 10
167+
}
168+
}
169+
}
170+
};
171+
172+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
173+
expect(layoutOut.geo.projection.rotation).toBeDefined();
174+
});
175+
176+
it('should not coerce coastlines and ocean if type is albers usa', function() {
177+
layoutIn = {
178+
geo: {
179+
projection: {
180+
type: 'albers usa'
181+
},
182+
showcoastlines: true,
183+
showocean: true
184+
}
185+
};
186+
187+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
188+
seaFields.forEach(function(field) {
189+
expect(layoutOut.geo[field]).toBeUndefined();
190+
});
191+
});
192+
193+
it('should not coerce coastlines and ocean if type is albers usa (converse)', function() {
194+
layoutIn = {
195+
geo: {
196+
showcoastlines: true,
197+
showocean: true
198+
}
199+
};
200+
201+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
202+
seaFields.forEach(function(field) {
203+
expect(layoutOut.geo[field]).toBeDefined();
204+
});
205+
});
206+
207+
it('should not coerce projection.parallels if type is conic', function() {
208+
var projTypes = layoutAttributes.projection.type.values;
209+
210+
function testOne(projType) {
211+
layoutIn = {
212+
geo: {
213+
projection: {
214+
type: projType,
215+
parallels: [10, 10]
216+
}
217+
}
218+
};
219+
220+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
221+
}
222+
223+
projTypes.forEach(function(projType) {
224+
testOne(projType);
225+
if(projType.indexOf('conic') !== -1) {
226+
expect(layoutOut.geo.projection.parallels).toBeDefined();
227+
}
228+
else {
229+
expect(layoutOut.geo.projection.parallels).toBeUndefined();
230+
}
231+
});
232+
});
233+
234+
it('should coerce subunits only when available (usa case)', function() {
235+
layoutIn = {
236+
geo: { scope: 'usa' }
237+
};
238+
239+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
240+
subunitFields.forEach(function(field) {
241+
expect(layoutOut.geo[field]).toBeDefined();
242+
});
243+
});
244+
245+
it('should coerce subunits only when available (default case)', function() {
246+
layoutIn = { geo: {} };
247+
248+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
249+
subunitFields.forEach(function(field) {
250+
expect(layoutOut.geo[field]).toBeUndefined();
251+
});
252+
});
253+
254+
it('should coerce subunits only when available (NA case)', function() {
255+
layoutIn = {
256+
geo: {
257+
scope: 'north america',
258+
resolution: 50
259+
}
260+
};
261+
262+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
263+
subunitFields.forEach(function(field) {
264+
expect(layoutOut.geo[field]).toBeDefined();
265+
});
266+
});
267+
268+
it('should coerce subunits only when available (NA case 2)', function() {
269+
layoutIn = {
270+
geo: {
271+
scope: 'north america',
272+
resolution: '50'
273+
}
274+
};
275+
276+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
277+
subunitFields.forEach(function(field) {
278+
expect(layoutOut.geo[field]).toBeDefined();
279+
});
280+
});
281+
282+
it('should coerce subunits only when available (NA case 2)', function() {
283+
layoutIn = {
284+
geo: {
285+
scope: 'north america'
286+
}
287+
};
288+
289+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
290+
subunitFields.forEach(function(field) {
291+
expect(layoutOut.geo[field]).toBeUndefined();
292+
});
293+
});
294+
295+
it('should not coerce frame unless for world scope', function() {
296+
var scopes = layoutAttributes.scope.values;
297+
298+
function testOne(scope) {
299+
layoutIn = {
300+
geo: { scope: scope }
301+
};
302+
303+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
304+
}
305+
306+
scopes.forEach(function(scope) {
307+
testOne(scope);
308+
if(scope === 'world') {
309+
frameFields.forEach(function(field) {
310+
expect(layoutOut.geo[field]).toBeDefined();
311+
});
312+
}
313+
else {
314+
frameFields.forEach(function(field) {
315+
expect(layoutOut.geo[field]).toBeUndefined();
316+
});
317+
}
318+
});
319+
});
320+
321+
it('should add geo data-only geos into layoutIn', function() {
322+
layoutIn = {};
323+
fullData = [{ type: 'scattergeo', geo: 'geo' }];
324+
325+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
326+
expect(layoutIn.geo).toEqual({});
327+
});
328+
329+
it('should add geo data-only geos into layoutIn (converse)', function() {
330+
layoutIn = {};
331+
fullData = [{ type: 'scatter' }];
332+
333+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
334+
expect(layoutIn.geo).toBe(undefined);
335+
});
336+
});
337+
});
338+
13339
describe('Test geo interactions', function() {
14340
'use strict';
15341

0 commit comments

Comments
 (0)