Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch topojson when 1+ trace(s) has locationmode #3994

Merged
merged 1 commit into from
Jun 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/plots/geo/geo.js
Original file line number Diff line number Diff line change
@@ -80,6 +80,12 @@ proto.plot = function(geoCalcData, fullLayout, promises) {
break;
}
}
for(var i = 0; i < geoCalcData.length; i++) {
if(geoCalcData[0][0].trace.locationmode) {
needsTopojson = true;
break;
}
}
if(!needsTopojson) {
return _this.update(geoCalcData, fullLayout);
}
60 changes: 50 additions & 10 deletions test/jasmine/tests/geo_test.js
Original file line number Diff line number Diff line change
@@ -1338,18 +1338,58 @@ describe('Test geo interactions', function() {
.then(done);
});

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

spyOn(d3, 'json').and.callThrough();
beforeEach(function() {
if(window.PlotlyGeoAssets && window.PlotlyGeoAssets.topojson) {
delete window.PlotlyGeoAssets.topojson.world_110m;
}
gd = createGraphDiv();
spyOn(d3, 'json').and.callThrough();
});

Plotly.plot(gd, fig)
.then(function() {
expect(d3.json).toHaveBeenCalledTimes(0);
})
.catch(failTest)
.then(done);
function _assert(cnt) {
return function() {
expect(d3.json).toHaveBeenCalledTimes(cnt);
};
}

it('- no base layers + lon/lat traces', function(done) {
var fig = Lib.extendDeep({}, require('@mocks/geo_skymap.json'));

Plotly.plot(gd, fig)
.then(_assert(0))
.then(function() { return Plotly.relayout(gd, 'geo.showcoastlines', true); })
.then(_assert(1))
.catch(failTest)
.then(done);
});

it('- no base layers + choropleth', function(done) {
Plotly.plot(gd, [{
type: 'choropleth',
locations: ['CAN'],
z: [10]
}], {
geo: {showcoastlines: false}
})
.then(_assert(1))
.catch(failTest)
.then(done);
});

it('- no base layers + location scattergeo', function(done) {
Plotly.plot(gd, [{
type: 'scattergeo',
locations: ['CAN'],
}], {
geo: {showcoastlines: false}
})
.then(_assert(1))
.catch(failTest)
.then(done);
});
});
});