Skip to content

Commit a74b0f7

Browse files
authored
Merge pull request #1046 from plotly/scattergeo-country-name-fix
Scattergeo unfound country name fix
2 parents 4bbf4a3 + 3e4c57c commit a74b0f7

File tree

6 files changed

+394
-349
lines changed

6 files changed

+394
-349
lines changed

src/lib/geo_location_utils.js

+15-12
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,21 @@ var locationmodeToIdFinder = {
2424

2525
exports.locationToFeature = function(locationmode, location, features) {
2626
var locationId = getLocationId(locationmode, location);
27-
var feature;
2827

29-
for(var i = 0; i < features.length; i++) {
30-
feature = features[i];
28+
if(locationId) {
29+
for(var i = 0; i < features.length; i++) {
30+
var feature = features[i];
3131

32-
if(feature.id === locationId) return feature;
32+
if(feature.id === locationId) return feature;
33+
}
34+
35+
Lib.warn([
36+
'Location with id', locationId,
37+
'does not have a matching topojson feature at this resolution.'
38+
].join(' '));
3339
}
3440

35-
Lib.warn([
36-
'Location with id', locationId,
37-
'does not have a matching topojson feature at this resolution.'
38-
].join(' '));
41+
return false;
3942
};
4043

4144
function getLocationId(locationmode, location) {
@@ -44,14 +47,14 @@ function getLocationId(locationmode, location) {
4447
}
4548

4649
function countryNameToISO3(countryName) {
47-
var iso3, regex;
48-
4950
for(var i = 0; i < countryIds.length; i++) {
50-
iso3 = countryIds[i];
51-
regex = new RegExp(countryRegex[iso3]);
51+
var iso3 = countryIds[i],
52+
regex = new RegExp(countryRegex[iso3]);
5253

5354
if(regex.test(countryName.toLowerCase())) return iso3;
5455
}
5556

5657
Lib.warn('Unrecognized country name: ' + countryName + '.');
58+
59+
return false;
5760
}

src/plots/geo/geo.js

+4
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ proto.plot = function(geoCalcData, fullLayout, promises) {
111111
Fx.hover(_this.graphDiv, evt, _this.id);
112112
});
113113

114+
_this.framework.on('mouseout', function() {
115+
Fx.loneUnhover(fullLayout._toppaper);
116+
});
117+
114118
_this.framework.on('click', function() {
115119
Fx.click(_this.graphDiv, { target: true });
116120
});

src/traces/choropleth/plot.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ plotChoropleth.calcGeoJSON = function(trace, topojson) {
4040
for(var i = 0; i < len; i++) {
4141
feature = locationToFeature(trace.locationmode, locations[i], features);
4242

43-
if(feature === undefined) continue; // filter the blank features here
43+
if(!feature) continue; // filter the blank features here
4444

4545
// 'data_array' attributes
4646
feature.z = trace.z[i];

0 commit comments

Comments
 (0)