diff --git a/src/traces/scattergeo/plot.js b/src/traces/scattergeo/plot.js index 921dce93b84..9cdb687cab3 100644 --- a/src/traces/scattergeo/plot.js +++ b/src/traces/scattergeo/plot.js @@ -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'); @@ -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], @@ -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; @@ -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 { diff --git a/test/image/baselines/geo_connectgaps.png b/test/image/baselines/geo_connectgaps.png new file mode 100644 index 00000000000..cd57186e7d1 Binary files /dev/null and b/test/image/baselines/geo_connectgaps.png differ diff --git a/test/image/mocks/geo_connectgaps.json b/test/image/mocks/geo_connectgaps.json new file mode 100644 index 00000000000..21ea5fba183 --- /dev/null +++ b/test/image/mocks/geo_connectgaps.json @@ -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 + } +}