Skip to content

Commit 93af5d6

Browse files
authored
Merge pull request #3856 from plotly/misc-geo-fixes
Miscellaneous geo fixes
2 parents 5ce2a83 + 10912bd commit 93af5d6

38 files changed

+5303
-51
lines changed

Diff for: dist/topojson/africa_110m.json

+1-1
Large diffs are not rendered by default.

Diff for: dist/topojson/africa_50m.json

+1-1
Large diffs are not rendered by default.

Diff for: dist/topojson/asia_110m.json

+1-1
Large diffs are not rendered by default.

Diff for: dist/topojson/asia_50m.json

+1-1
Large diffs are not rendered by default.

Diff for: dist/topojson/europe_110m.json

+1-1
Large diffs are not rendered by default.

Diff for: dist/topojson/europe_50m.json

+1-1
Large diffs are not rendered by default.

Diff for: dist/topojson/north-america_110m.json

+1-1
Large diffs are not rendered by default.

Diff for: dist/topojson/north-america_50m.json

+1-1
Large diffs are not rendered by default.

Diff for: dist/topojson/south-america_110m.json

+1-1
Large diffs are not rendered by default.

Diff for: dist/topojson/south-america_50m.json

+1-1
Large diffs are not rendered by default.

Diff for: dist/topojson/usa_110m.json

+1-1
Large diffs are not rendered by default.

Diff for: dist/topojson/usa_50m.json

+1-1
Large diffs are not rendered by default.

Diff for: dist/topojson/world_110m.json

+1-1
Large diffs are not rendered by default.

Diff for: dist/topojson/world_50m.json

+1-1
Large diffs are not rendered by default.

Diff for: package-lock.json

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"regl-splom": "^1.0.6",
108108
"right-now": "^1.0.0",
109109
"robust-orientation": "^1.1.3",
110-
"sane-topojson": "^2.0.0",
110+
"sane-topojson": "^3.0.1",
111111
"strongly-connected-components": "^1.0.1",
112112
"superscript-text": "^1.0.0",
113113
"svg-path-sdf": "^1.1.3",

Diff for: src/lib/geo_location_utils.js

+40-24
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var countryRegex = require('country-regex');
1312
var Lib = require('../lib');
1413

15-
1614
// make list of all country iso3 ids from at runtime
1715
var countryIds = Object.keys(countryRegex);
1816

@@ -22,16 +20,48 @@ var locationmodeToIdFinder = {
2220
'country names': countryNameToISO3
2321
};
2422

25-
exports.locationToFeature = function(locationmode, location, features) {
23+
function countryNameToISO3(countryName) {
24+
for(var i = 0; i < countryIds.length; i++) {
25+
var iso3 = countryIds[i];
26+
var regex = new RegExp(countryRegex[iso3]);
27+
28+
if(regex.test(countryName.trim().toLowerCase())) return iso3;
29+
}
30+
31+
Lib.log('Unrecognized country name: ' + countryName + '.');
32+
33+
return false;
34+
}
35+
36+
function locationToFeature(locationmode, location, features) {
2637
if(!location || typeof location !== 'string') return false;
2738

28-
var locationId = getLocationId(locationmode, location);
39+
var locationId = locationmodeToIdFinder[locationmode](location);
40+
var filteredFeatures;
41+
var f, i;
2942

3043
if(locationId) {
31-
for(var i = 0; i < features.length; i++) {
32-
var feature = features[i];
44+
if(locationmode === 'USA-states') {
45+
// Filter out features out in USA
46+
//
47+
// This is important as the Natural Earth files
48+
// include state/provinces from USA, Canada, Australia and Brazil
49+
// which have some overlay in their two-letter ids. For example,
50+
// 'WA' is used for both Washington state and Western Australia.
51+
filteredFeatures = [];
52+
for(i = 0; i < features.length; i++) {
53+
f = features[i];
54+
if(f.properties && f.properties.gu && f.properties.gu === 'USA') {
55+
filteredFeatures.push(f);
56+
}
57+
}
58+
} else {
59+
filteredFeatures = features;
60+
}
3361

34-
if(feature.id === locationId) return feature;
62+
for(i = 0; i < filteredFeatures.length; i++) {
63+
f = filteredFeatures[i];
64+
if(f.id === locationId) return f;
3565
}
3666

3767
Lib.log([
@@ -41,22 +71,8 @@ exports.locationToFeature = function(locationmode, location, features) {
4171
}
4272

4373
return false;
44-
};
45-
46-
function getLocationId(locationmode, location) {
47-
var idFinder = locationmodeToIdFinder[locationmode];
48-
return idFinder(location);
4974
}
5075

51-
function countryNameToISO3(countryName) {
52-
for(var i = 0; i < countryIds.length; i++) {
53-
var iso3 = countryIds[i];
54-
var regex = new RegExp(countryRegex[iso3]);
55-
56-
if(regex.test(countryName.trim().toLowerCase())) return iso3;
57-
}
58-
59-
Lib.log('Unrecognized country name: ' + countryName + '.');
60-
61-
return false;
62-
}
76+
module.exports = {
77+
locationToFeature: locationToFeature
78+
};

Diff for: src/plots/geo/geo.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function Geo(opts) {
4242
this.topojson = null;
4343

4444
this.projection = null;
45+
this.scope = null;
4546
this.viewInitial = null;
4647
this.fitScale = null;
4748
this.bounds = null;
@@ -71,6 +72,18 @@ module.exports = function createGeo(opts) {
7172
proto.plot = function(geoCalcData, fullLayout, promises) {
7273
var _this = this;
7374
var geoLayout = fullLayout[this.id];
75+
76+
var needsTopojson = false;
77+
for(var k in constants.layerNameToAdjective) {
78+
if(k !== 'frame' && geoLayout['show' + k]) {
79+
needsTopojson = true;
80+
break;
81+
}
82+
}
83+
if(!needsTopojson) {
84+
return _this.update(geoCalcData, fullLayout);
85+
}
86+
7487
var topojsonNameNew = topojsonUtils.getTopojsonName(geoLayout);
7588

7689
if(_this.topojson === null || topojsonNameNew !== _this.topojsonName) {
@@ -133,9 +146,10 @@ proto.update = function(geoCalcData, fullLayout) {
133146
}
134147
}
135148

136-
if(!this.viewInitial) {
149+
if(!this.viewInitial || this.scope !== geoLayout.scope) {
137150
this.saveViewInitial(geoLayout);
138151
}
152+
this.scope = geoLayout.scope;
139153

140154
this.updateBaseLayers(fullLayout, geoLayout);
141155
this.updateDims(fullLayout, geoLayout);

Diff for: tasks/util/constants.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,20 @@ var pathToImageTest = path.join(pathToRoot, 'test/image');
88
var pathToDist = path.join(pathToRoot, 'dist/');
99
var pathToBuild = path.join(pathToRoot, 'build/');
1010

11-
var pathToTopojsonSrc = path.join(
12-
path.dirname(require.resolve('sane-topojson')), 'dist/'
13-
);
11+
var pathToTopojsonSrc;
12+
try {
13+
pathToTopojsonSrc = path.join(path.dirname(require.resolve('sane-topojson')), 'dist/');
14+
} catch(e) {
15+
console.log([
16+
'',
17+
'WARN: Cannot resolve path to *sane-topojson* package.',
18+
' This can happen when one `npm link sane-topojson`',
19+
' and runs a command in a Docker container.',
20+
' There is nothing to worry, if you see this warning while running',
21+
' `npm run test-image`, `npm run test-export` or `npm run baseline` ;)',
22+
''
23+
].join('\n'));
24+
}
1425

1526
var partialBundleNames = [
1627
'basic', 'cartesian', 'geo', 'gl3d', 'gl2d', 'mapbox', 'finance'

Diff for: test/image/baselines/geo_canadian-cites.png

-144 KB
Binary file not shown.

Diff for: test/image/baselines/geo_canadian-cities.png

142 KB
Loading

Diff for: test/image/baselines/geo_choropleth-text.png

81 Bytes
Loading

Diff for: test/image/baselines/geo_country-names.png

40 Bytes
Loading

Diff for: test/image/baselines/geo_custom-colorscale.png

-11 Bytes
Loading

Diff for: test/image/baselines/geo_europe-bubbles.png

-7 Bytes
Loading

Diff for: test/image/baselines/geo_first.png

14 Bytes
Loading

Diff for: test/image/baselines/geo_orthographic.png

148 Bytes
Loading

Diff for: test/image/baselines/geo_point-selection.png

35 Bytes
Loading

Diff for: test/image/baselines/geo_scattergeo-out-of-usa.png

-508 Bytes
Loading

Diff for: test/image/baselines/geo_second.png

13 Bytes
Loading

Diff for: test/image/baselines/geo_skymap.png

156 KB
Loading

Diff for: test/image/baselines/geo_stereographic.png

13 Bytes
Loading
49 KB
Loading
File renamed without changes.

0 commit comments

Comments
 (0)