Skip to content

scattergeo skip over non-numeric data #964

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

Closed
wants to merge 2 commits into from
Closed
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
28 changes: 19 additions & 9 deletions src/traces/scattergeo/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'use strict';

var d3 = require('d3');
var isNumeric = require('fast-isnumeric');

var Fx = require('../../plots/cartesian/graph_interact');
var Axes = require('../../plots/cartesian/axes');
Expand Down Expand Up @@ -40,22 +41,18 @@ plotScatterGeo.calcGeoJSON = function(trace, topojson) {
getLonLat = function(trace, i) {
var feature = locationToFeature(trace.locationmode, locations[i], features);

return (feature !== undefined) ?
feature.properties.ct :
undefined;
return feature ? feature.properties.ct : null;
};
}
else {
len = trace.lon.length;
getLonLat = function(trace, i) {
return [trace.lon[i], trace.lat[i]];
};
getLonLat = cleanLonLat;
}

for(var i = 0; i < len; i++) {
var lonlat = getLonLat(trace, i);

if(!lonlat) continue; // filter the blank points here
if(!lonlat) continue;

var calcItem = {
lon: lonlat[0],
Expand All @@ -73,6 +70,15 @@ plotScatterGeo.calcGeoJSON = function(trace, topojson) {
return cdi;
};

function cleanLonLat(trace, i) {
var lon = trace.lon[i],
lat = trace.lat[i];

if(!isNumeric(lon) || !isNumeric(lat)) return null;

return [+lon, +lat];
}

// similar Scatter.arraysToCalcdata but inside a filter loop
function arrayItemToCalcdata(trace, calcItem, i) {
var marker = trace.marker;
Expand Down Expand Up @@ -102,10 +108,14 @@ function arrayItemToCalcdata(trace, calcItem, i) {

function makeLineGeoJSON(trace) {
var N = trace.lon.length,
coordinates = new Array(N);
coordinates = [];

for(var i = 0; i < N; i++) {
coordinates[i] = [trace.lon[i], trace.lat[i]];
var lonlat = cleanLonLat(trace, i);

if(!lonlat) continue;

coordinates.push([lonlat[0], lonlat[1]]);
}

return {
Expand Down
Binary file added test/image/baselines/geo_connectgaps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions test/image/mocks/geo_connectgaps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"data": [
{
"lon": [
-50,
-50,
null,
50,
50
],
"lat": [
-50,
50,
null,
-50,
50
],
"connectgaps": true,
"type": "scattergeo",
"mode": "lines+markers",
"line": {
"color": "rgba(31,119,180,1)"
}
}
],
"layout": {
"geo": {},
"height": 450,
"width": 1100,
"autosize": true
}
}