1010'use strict' ;
1111
1212var Lib = require ( '../../lib' ) ;
13+ var BADNUM = require ( '../../constants/numerical' ) . BADNUM ;
1314var geoJsonUtils = require ( '../../lib/geojson_utils' ) ;
1415
16+ var Colorscale = require ( '../../components/colorscale' ) ;
17+ var makeBubbleSizeFn = require ( '../scatter/make_bubble_size_func' ) ;
1518var subTypes = require ( '../scatter/subtypes' ) ;
1619var convertTextOpts = require ( '../../plots/mapbox/convert_text_opts' ) ;
1720
@@ -43,16 +46,16 @@ module.exports = function convert(calcTrace) {
4346 } ;
4447
4548 // early return if not visible or placeholder
46- if ( ! isVisible || calcTrace [ 0 ] . placeholder ) return opts ;
49+ if ( ! isVisible ) return opts ;
4750
4851 // fill layer and line layer use the same coords
49- var coords ;
52+ var lineCoords ;
5053 if ( hasFill || hasLines ) {
51- coords = geoJsonUtils . calcTraceToLineCoords ( calcTrace ) ;
54+ lineCoords = geoJsonUtils . calcTraceToLineCoords ( calcTrace ) ;
5255 }
5356
5457 if ( hasFill ) {
55- fill . geojson = geoJsonUtils . makePolygon ( coords ) ;
58+ fill . geojson = geoJsonUtils . makePolygon ( lineCoords ) ;
5659 fill . layout . visibility = 'visible' ;
5760
5861 Lib . extendFlat ( fill . paint , {
@@ -61,7 +64,7 @@ module.exports = function convert(calcTrace) {
6164 }
6265
6366 if ( hasLines ) {
64- line . geojson = geoJsonUtils . makeLine ( coords ) ;
67+ line . geojson = geoJsonUtils . makeLine ( lineCoords ) ;
6568 line . layout . visibility = 'visible' ;
6669
6770 Lib . extendFlat ( line . paint , {
@@ -155,12 +158,30 @@ function initContainer() {
155158//
156159// The solution prove to be more robust than trying to generate
157160// `stops` arrays from scale functions.
161+ //
162+ // TODO axe this when we bump mapbox-gl and rewrite this using
163+ // "identity" property functions.
164+ // See https://github.com/plotly/plotly.js/pull/1543
165+ //
158166function makeCircleGeoJSON ( calcTrace , hash ) {
159167 var trace = calcTrace [ 0 ] . trace ;
168+ var marker = trace . marker ;
169+
170+ var colorFn ;
171+ if ( Colorscale . hasColorscale ( trace , 'marker' ) ) {
172+ colorFn = Colorscale . makeColorScaleFunc (
173+ Colorscale . extractScale ( marker . colorscale , marker . cmin , marker . cmax )
174+ ) ;
175+ } else if ( Array . isArray ( marker . color ) ) {
176+ colorFn = Lib . identity ;
177+ }
160178
161- var marker = trace . marker ,
162- hasColorArray = Array . isArray ( marker . color ) ,
163- hasSizeArray = Array . isArray ( marker . size ) ;
179+ var sizeFn ;
180+ if ( subTypes . isBubble ( trace ) ) {
181+ sizeFn = makeBubbleSizeFn ( trace ) ;
182+ } else if ( Array . isArray ( marker . size ) ) {
183+ sizeFn = Lib . identity ;
184+ }
164185
165186 // Translate vals in trace arrayOk containers
166187 // into a val-to-index hash object
@@ -174,16 +195,19 @@ function makeCircleGeoJSON(calcTrace, hash) {
174195
175196 for ( var i = 0 ; i < calcTrace . length ; i ++ ) {
176197 var calcPt = calcTrace [ i ] ;
198+ var lonlat = calcPt . lonlat ;
199+
200+ if ( isBADNUM ( lonlat ) ) continue ;
177201
178202 var props = { } ;
179- if ( hasColorArray ) translate ( props , COLOR_PROP , calcPt . mcc , i ) ;
180- if ( hasSizeArray ) translate ( props , SIZE_PROP , calcPt . mrc , i ) ;
203+ if ( colorFn ) translate ( props , COLOR_PROP , colorFn ( calcPt . mc ) , i ) ;
204+ if ( sizeFn ) translate ( props , SIZE_PROP , sizeFn ( calcPt . ms ) , i ) ;
181205
182206 features . push ( {
183207 type : 'Feature' ,
184208 geometry : {
185209 type : 'Point' ,
186- coordinates : calcPt . lonlat
210+ coordinates : lonlat
187211 } ,
188212 properties : props
189213 } ) ;
@@ -215,6 +239,8 @@ function makeSymbolGeoJSON(calcTrace) {
215239 for ( var i = 0 ; i < calcTrace . length ; i ++ ) {
216240 var calcPt = calcTrace [ i ] ;
217241
242+ if ( isBADNUM ( calcPt . lonlat ) ) continue ;
243+
218244 features . push ( {
219245 type : 'Feature' ,
220246 geometry : {
@@ -305,3 +331,8 @@ function getFillFunc(attr) {
305331}
306332
307333function blankFillFunc ( ) { return '' ; }
334+
335+ // only need to check lon (OR lat)
336+ function isBADNUM ( lonlat ) {
337+ return lonlat [ 0 ] === BADNUM ;
338+ }
0 commit comments