Skip to content

Miscellaneous geo fixes #3856

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

Merged
merged 15 commits into from
May 22, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion dist/topojson/africa_110m.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/topojson/africa_50m.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/topojson/asia_110m.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/topojson/asia_50m.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/topojson/europe_110m.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/topojson/europe_50m.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/topojson/north-america_110m.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/topojson/north-america_50m.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/topojson/south-america_110m.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/topojson/south-america_50m.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/topojson/usa_110m.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/topojson/usa_50m.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/topojson/world_110m.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/topojson/world_50m.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"regl-splom": "^1.0.6",
"right-now": "^1.0.0",
"robust-orientation": "^1.1.3",
"sane-topojson": "^2.0.0",
"sane-topojson": "^3.0.1",
"strongly-connected-components": "^1.0.1",
"superscript-text": "^1.0.0",
"svg-path-sdf": "^1.1.3",
Expand Down
64 changes: 40 additions & 24 deletions src/lib/geo_location_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
* LICENSE file in the root directory of this source tree.
*/


'use strict';

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


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

Expand All @@ -22,16 +20,48 @@ var locationmodeToIdFinder = {
'country names': countryNameToISO3
};

exports.locationToFeature = function(locationmode, location, features) {
function countryNameToISO3(countryName) {
for(var i = 0; i < countryIds.length; i++) {
var iso3 = countryIds[i];
var regex = new RegExp(countryRegex[iso3]);

if(regex.test(countryName.trim().toLowerCase())) return iso3;
}

Lib.log('Unrecognized country name: ' + countryName + '.');

return false;
}

function locationToFeature(locationmode, location, features) {
if(!location || typeof location !== 'string') return false;

var locationId = getLocationId(locationmode, location);
var locationId = locationmodeToIdFinder[locationmode](location);
var filteredFeatures;
var f, i;

if(locationId) {
for(var i = 0; i < features.length; i++) {
var feature = features[i];
if(locationmode === 'USA-states') {
// Filter out features out in USA
//
// This is important as the Natural Earth files
// include state/provinces from USA, Canada, Australia and Brazil
// which have some overlay in their two-letter ids. For example,
// 'WA' is used for both Washington state and Western Australia.
filteredFeatures = [];
for(i = 0; i < features.length; i++) {
f = features[i];
if(f.properties && f.properties.gu && f.properties.gu === 'USA') {
filteredFeatures.push(f);
}
}
} else {
filteredFeatures = features;
}

if(feature.id === locationId) return feature;
for(i = 0; i < filteredFeatures.length; i++) {
f = filteredFeatures[i];
if(f.id === locationId) return f;
}

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

return false;
};

function getLocationId(locationmode, location) {
var idFinder = locationmodeToIdFinder[locationmode];
return idFinder(location);
}

function countryNameToISO3(countryName) {
for(var i = 0; i < countryIds.length; i++) {
var iso3 = countryIds[i];
var regex = new RegExp(countryRegex[iso3]);

if(regex.test(countryName.trim().toLowerCase())) return iso3;
}

Lib.log('Unrecognized country name: ' + countryName + '.');

return false;
}
module.exports = {
locationToFeature: locationToFeature
};
16 changes: 15 additions & 1 deletion src/plots/geo/geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function Geo(opts) {
this.topojson = null;

this.projection = null;
this.scope = null;
this.viewInitial = null;
this.fitScale = null;
this.bounds = null;
Expand Down Expand Up @@ -71,6 +72,18 @@ module.exports = function createGeo(opts) {
proto.plot = function(geoCalcData, fullLayout, promises) {
var _this = this;
var geoLayout = fullLayout[this.id];

var needsTopojson = false;
for(var k in constants.layerNameToAdjective) {
if(k !== 'frame' && geoLayout['show' + k]) {
needsTopojson = true;
break;
}
}
if(!needsTopojson) {
return _this.update(geoCalcData, fullLayout);
}

var topojsonNameNew = topojsonUtils.getTopojsonName(geoLayout);

if(_this.topojson === null || topojsonNameNew !== _this.topojsonName) {
Expand Down Expand Up @@ -133,9 +146,10 @@ proto.update = function(geoCalcData, fullLayout) {
}
}

if(!this.viewInitial) {
if(!this.viewInitial || this.scope !== geoLayout.scope) {
this.saveViewInitial(geoLayout);
}
this.scope = geoLayout.scope;

this.updateBaseLayers(fullLayout, geoLayout);
this.updateDims(fullLayout, geoLayout);
Expand Down
17 changes: 14 additions & 3 deletions tasks/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@ var pathToImageTest = path.join(pathToRoot, 'test/image');
var pathToDist = path.join(pathToRoot, 'dist/');
var pathToBuild = path.join(pathToRoot, 'build/');

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

var partialBundleNames = [
'basic', 'cartesian', 'geo', 'gl3d', 'gl2d', 'mapbox', 'finance'
Expand Down
Binary file removed test/image/baselines/geo_canadian-cites.png
Binary file not shown.
Binary file added test/image/baselines/geo_canadian-cities.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/geo_choropleth-text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/geo_country-names.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/geo_custom-colorscale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/geo_europe-bubbles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/geo_first.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/geo_orthographic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/geo_point-selection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/geo_scattergeo-out-of-usa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/geo_second.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/image/baselines/geo_skymap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/geo_stereographic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading