Skip to content

Commit d096307

Browse files
authored
Merge pull request #3994 from plotly/geo-locations-but-no-base-layer-fix
Fetch topojson when 1+ trace(s) has `locationmode`
2 parents 3d383b7 + b7dac75 commit d096307

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

src/plots/geo/geo.js

+6
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ proto.plot = function(geoCalcData, fullLayout, promises) {
8080
break;
8181
}
8282
}
83+
for(var i = 0; i < geoCalcData.length; i++) {
84+
if(geoCalcData[0][0].trace.locationmode) {
85+
needsTopojson = true;
86+
break;
87+
}
88+
}
8389
if(!needsTopojson) {
8490
return _this.update(geoCalcData, fullLayout);
8591
}

test/jasmine/tests/geo_test.js

+50-10
Original file line numberDiff line numberDiff line change
@@ -1338,18 +1338,58 @@ describe('Test geo interactions', function() {
13381338
.then(done);
13391339
});
13401340

1341-
it('should not make request for topojson when not needed', function(done) {
1342-
var gd = createGraphDiv();
1343-
var fig = Lib.extendDeep({}, require('@mocks/geo_skymap.json'));
1341+
describe('should not make request for topojson when not needed', function() {
1342+
var gd;
13441343

1345-
spyOn(d3, 'json').and.callThrough();
1344+
beforeEach(function() {
1345+
if(window.PlotlyGeoAssets && window.PlotlyGeoAssets.topojson) {
1346+
delete window.PlotlyGeoAssets.topojson.world_110m;
1347+
}
1348+
gd = createGraphDiv();
1349+
spyOn(d3, 'json').and.callThrough();
1350+
});
13461351

1347-
Plotly.plot(gd, fig)
1348-
.then(function() {
1349-
expect(d3.json).toHaveBeenCalledTimes(0);
1350-
})
1351-
.catch(failTest)
1352-
.then(done);
1352+
function _assert(cnt) {
1353+
return function() {
1354+
expect(d3.json).toHaveBeenCalledTimes(cnt);
1355+
};
1356+
}
1357+
1358+
it('- no base layers + lon/lat traces', function(done) {
1359+
var fig = Lib.extendDeep({}, require('@mocks/geo_skymap.json'));
1360+
1361+
Plotly.plot(gd, fig)
1362+
.then(_assert(0))
1363+
.then(function() { return Plotly.relayout(gd, 'geo.showcoastlines', true); })
1364+
.then(_assert(1))
1365+
.catch(failTest)
1366+
.then(done);
1367+
});
1368+
1369+
it('- no base layers + choropleth', function(done) {
1370+
Plotly.plot(gd, [{
1371+
type: 'choropleth',
1372+
locations: ['CAN'],
1373+
z: [10]
1374+
}], {
1375+
geo: {showcoastlines: false}
1376+
})
1377+
.then(_assert(1))
1378+
.catch(failTest)
1379+
.then(done);
1380+
});
1381+
1382+
it('- no base layers + location scattergeo', function(done) {
1383+
Plotly.plot(gd, [{
1384+
type: 'scattergeo',
1385+
locations: ['CAN'],
1386+
}], {
1387+
geo: {showcoastlines: false}
1388+
})
1389+
.then(_assert(1))
1390+
.catch(failTest)
1391+
.then(done);
1392+
});
13531393
});
13541394
});
13551395

0 commit comments

Comments
 (0)