10
10
'use strict' ;
11
11
12
12
var Lib = require ( '../../lib' ) ;
13
+ var BADNUM = require ( '../../constants/numerical' ) . BADNUM ;
13
14
var geoJsonUtils = require ( '../../lib/geojson_utils' ) ;
14
15
16
+ var Colorscale = require ( '../../components/colorscale' ) ;
17
+ var makeBubbleSizeFn = require ( '../scatter/make_bubble_size_func' ) ;
15
18
var subTypes = require ( '../scatter/subtypes' ) ;
16
19
var convertTextOpts = require ( '../../plots/mapbox/convert_text_opts' ) ;
17
20
@@ -43,16 +46,16 @@ module.exports = function convert(calcTrace) {
43
46
} ;
44
47
45
48
// early return if not visible or placeholder
46
- if ( ! isVisible || calcTrace [ 0 ] . placeholder ) return opts ;
49
+ if ( ! isVisible ) return opts ;
47
50
48
51
// fill layer and line layer use the same coords
49
- var coords ;
52
+ var lineCoords ;
50
53
if ( hasFill || hasLines ) {
51
- coords = geoJsonUtils . calcTraceToLineCoords ( calcTrace ) ;
54
+ lineCoords = geoJsonUtils . calcTraceToLineCoords ( calcTrace ) ;
52
55
}
53
56
54
57
if ( hasFill ) {
55
- fill . geojson = geoJsonUtils . makePolygon ( coords ) ;
58
+ fill . geojson = geoJsonUtils . makePolygon ( lineCoords ) ;
56
59
fill . layout . visibility = 'visible' ;
57
60
58
61
Lib . extendFlat ( fill . paint , {
@@ -61,7 +64,7 @@ module.exports = function convert(calcTrace) {
61
64
}
62
65
63
66
if ( hasLines ) {
64
- line . geojson = geoJsonUtils . makeLine ( coords ) ;
67
+ line . geojson = geoJsonUtils . makeLine ( lineCoords ) ;
65
68
line . layout . visibility = 'visible' ;
66
69
67
70
Lib . extendFlat ( line . paint , {
@@ -155,12 +158,30 @@ function initContainer() {
155
158
//
156
159
// The solution prove to be more robust than trying to generate
157
160
// `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
+ //
158
166
function makeCircleGeoJSON ( calcTrace , hash ) {
159
167
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
+ }
160
178
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
+ }
164
185
165
186
// Translate vals in trace arrayOk containers
166
187
// into a val-to-index hash object
@@ -174,16 +195,19 @@ function makeCircleGeoJSON(calcTrace, hash) {
174
195
175
196
for ( var i = 0 ; i < calcTrace . length ; i ++ ) {
176
197
var calcPt = calcTrace [ i ] ;
198
+ var lonlat = calcPt . lonlat ;
199
+
200
+ if ( isBADNUM ( lonlat ) ) continue ;
177
201
178
202
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 ) ;
181
205
182
206
features . push ( {
183
207
type : 'Feature' ,
184
208
geometry : {
185
209
type : 'Point' ,
186
- coordinates : calcPt . lonlat
210
+ coordinates : lonlat
187
211
} ,
188
212
properties : props
189
213
} ) ;
@@ -215,6 +239,8 @@ function makeSymbolGeoJSON(calcTrace) {
215
239
for ( var i = 0 ; i < calcTrace . length ; i ++ ) {
216
240
var calcPt = calcTrace [ i ] ;
217
241
242
+ if ( isBADNUM ( calcPt . lonlat ) ) continue ;
243
+
218
244
features . push ( {
219
245
type : 'Feature' ,
220
246
geometry : {
@@ -305,3 +331,8 @@ function getFillFunc(attr) {
305
331
}
306
332
307
333
function blankFillFunc ( ) { return '' ; }
334
+
335
+ // only need to check lon (OR lat)
336
+ function isBADNUM ( lonlat ) {
337
+ return lonlat [ 0 ] === BADNUM ;
338
+ }
0 commit comments