@@ -34,11 +34,12 @@ module.exports = function convert(gd, calcTrace) {
34
34
var hasText = subTypes . hasText ( trace ) ;
35
35
var hasCircles = ( hasMarkers && trace . marker . symbol === 'circle' ) ;
36
36
var hasSymbols = ( hasMarkers && trace . marker . symbol !== 'circle' ) ;
37
+ var hasCluster = trace . cluster . enabled ;
37
38
38
- var fill = initContainer ( ) ;
39
- var line = initContainer ( ) ;
40
- var circle = initContainer ( ) ;
41
- var symbol = initContainer ( ) ;
39
+ var fill = initContainer ( 'fill' ) ;
40
+ var line = initContainer ( 'line' ) ;
41
+ var circle = initContainer ( 'circle' ) ;
42
+ var symbol = initContainer ( 'symbol' ) ;
42
43
43
44
var opts = {
44
45
fill : fill ,
@@ -82,6 +83,29 @@ module.exports = function convert(gd, calcTrace) {
82
83
var circleOpts = makeCircleOpts ( calcTrace ) ;
83
84
circle . geojson = circleOpts . geojson ;
84
85
circle . layout . visibility = 'visible' ;
86
+ if ( hasCluster ) {
87
+ circle . filter = [ '!' , [ 'has' , 'point_count' ] ] ;
88
+ opts . cluster = {
89
+ type : 'circle' ,
90
+ filter : [ 'has' , 'point_count' ] ,
91
+ layout : { visibility : 'visible' } ,
92
+ paint : {
93
+ 'circle-color' : arrayifyAttribute ( trace . cluster . color , trace . cluster . step ) ,
94
+ 'circle-radius' : arrayifyAttribute ( trace . cluster . size , trace . cluster . step ) ,
95
+ 'circle-opacity' : arrayifyAttribute ( trace . cluster . opacity , trace . cluster . step ) ,
96
+ } ,
97
+ } ;
98
+ opts . clusterCount = {
99
+ type : 'symbol' ,
100
+ filter : [ 'has' , 'point_count' ] ,
101
+ paint : { } ,
102
+ layout : {
103
+ 'text-field' : '{point_count_abbreviated}' ,
104
+ 'text-font' : [ 'Open Sans Regular' , 'Arial Unicode MS Regular' ] ,
105
+ 'text-size' : 12
106
+ }
107
+ } ;
108
+ }
85
109
86
110
Lib . extendFlat ( circle . paint , {
87
111
'circle-color' : circleOpts . mcc ,
@@ -90,6 +114,10 @@ module.exports = function convert(gd, calcTrace) {
90
114
} ) ;
91
115
}
92
116
117
+ if ( hasCircles && hasCluster ) {
118
+ circle . filter = [ '!' , [ 'has' , 'point_count' ] ] ;
119
+ }
120
+
93
121
if ( hasSymbols || hasText ) {
94
122
symbol . geojson = makeSymbolGeoJSON ( calcTrace , gd ) ;
95
123
@@ -150,10 +178,12 @@ module.exports = function convert(gd, calcTrace) {
150
178
return opts ;
151
179
} ;
152
180
153
- function initContainer ( ) {
181
+ function initContainer ( type ) {
154
182
return {
183
+ type : type ,
155
184
geojson : geoJsonUtils . makeBlank ( ) ,
156
185
layout : { visibility : 'none' } ,
186
+ filter : null ,
157
187
paint : { }
158
188
} ;
159
189
}
@@ -208,7 +238,8 @@ function makeCircleOpts(calcTrace) {
208
238
209
239
features . push ( {
210
240
type : 'Feature' ,
211
- geometry : { type : 'Point' , coordinates : lonlat } ,
241
+ id : i + 1 ,
242
+ geometry : { type : 'Point' , coordinates : lonlat } ,
212
243
properties : props
213
244
} ) ;
214
245
}
@@ -331,3 +362,16 @@ function blankFillFunc() { return ''; }
331
362
function isBADNUM ( lonlat ) {
332
363
return lonlat [ 0 ] === BADNUM ;
333
364
}
365
+
366
+ function arrayifyAttribute ( attribute , step ) {
367
+ var newAttribute ;
368
+ if ( Lib . isArrayOrTypedArray ( attribute ) && Lib . isArrayOrTypedArray ( step ) ) {
369
+ newAttribute = [ 'step' , [ 'get' , 'point_count' ] , attribute [ 0 ] ] ;
370
+ for ( var idx = 1 ; idx < attribute . length ; idx ++ ) {
371
+ newAttribute . push ( step [ idx - 1 ] , attribute [ idx ] ) ;
372
+ }
373
+ } else {
374
+ newAttribute = attribute ;
375
+ }
376
+ return newAttribute ;
377
+ }
0 commit comments