Skip to content

Commit

Permalink
scattergeo: add proper calc step
Browse files Browse the repository at this point in the history
- which skips and cast lon/lat values
- fixes #963
- note that 'locations[i]' -> feature must still be
  done at the plot (after the topojson is loaded)
  • Loading branch information
etpinard committed Oct 4, 2016
1 parent 4448eaa commit 52c1b89
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions src/traces/scattergeo/calc.js
Expand Up @@ -9,13 +9,47 @@

'use strict';

var calcColorscale = require('../scatter/colorscale_calc');
var isNumeric = require('fast-isnumeric');

var calcMarkerColorscale = require('../scatter/colorscale_calc');


module.exports = function calc(gd, trace) {
var cd = [{x: false, y: false, trace: trace, t: {}}];
var hasLocationData = Array.isArray(trace.locations),
len = hasLocationData ? trace.locations.length : trace.lon.length;

var calcTrace = [],
cnt = 0;

for(var i = 0; i < len; i++) {
var calcPt = {},
skip;

if(hasLocationData) {
var loc = trace.locations[i];

calcPt.loc = loc;
skip = (typeof loc !== 'string');
}
else {
var lon = trace.lon[i],
lat = trace.lat[i];

calcPt.lonlat = [+lon, +lat];
skip = (!isNumeric(lon) || !isNumeric(lat));
}

if(skip) {
if(cnt > 0) calcTrace[cnt - 1].gapAfter = true;
continue;
}

cnt++;

calcTrace.push(calcPt);
}

calcColorscale(trace);
calcMarkerColorscale(trace);

return cd;
return calcTrace;
};

0 comments on commit 52c1b89

Please sign in to comment.