@@ -26,11 +26,12 @@ module.exports = function convert(gd, calcTrace) {
26
26
var hasText = subTypes . hasText ( trace ) ;
27
27
var hasCircles = ( hasMarkers && trace . marker . symbol === 'circle' ) ;
28
28
var hasSymbols = ( hasMarkers && trace . marker . symbol !== 'circle' ) ;
29
+ var hasCluster = trace . cluster && trace . cluster . enabled ;
29
30
30
- var fill = initContainer ( ) ;
31
- var line = initContainer ( ) ;
32
- var circle = initContainer ( ) ;
33
- var symbol = initContainer ( ) ;
31
+ var fill = initContainer ( 'fill' ) ;
32
+ var line = initContainer ( 'line' ) ;
33
+ var circle = initContainer ( 'circle' ) ;
34
+ var symbol = initContainer ( 'symbol' ) ;
34
35
35
36
var opts = {
36
37
fill : fill ,
@@ -74,6 +75,29 @@ module.exports = function convert(gd, calcTrace) {
74
75
var circleOpts = makeCircleOpts ( calcTrace ) ;
75
76
circle . geojson = circleOpts . geojson ;
76
77
circle . layout . visibility = 'visible' ;
78
+ if ( hasCluster ) {
79
+ circle . filter = [ '!' , [ 'has' , 'point_count' ] ] ;
80
+ opts . cluster = {
81
+ type : 'circle' ,
82
+ filter : [ 'has' , 'point_count' ] ,
83
+ layout : { visibility : 'visible' } ,
84
+ paint : {
85
+ 'circle-color' : arrayifyAttribute ( trace . cluster . color , trace . cluster . step ) ,
86
+ 'circle-radius' : arrayifyAttribute ( trace . cluster . size , trace . cluster . step ) ,
87
+ 'circle-opacity' : arrayifyAttribute ( trace . cluster . opacity , trace . cluster . step ) ,
88
+ } ,
89
+ } ;
90
+ opts . clusterCount = {
91
+ type : 'symbol' ,
92
+ filter : [ 'has' , 'point_count' ] ,
93
+ paint : { } ,
94
+ layout : {
95
+ 'text-field' : '{point_count_abbreviated}' ,
96
+ 'text-font' : [ 'Open Sans Regular' , 'Arial Unicode MS Regular' ] ,
97
+ 'text-size' : 12
98
+ }
99
+ } ;
100
+ }
77
101
78
102
Lib . extendFlat ( circle . paint , {
79
103
'circle-color' : circleOpts . mcc ,
@@ -82,6 +106,10 @@ module.exports = function convert(gd, calcTrace) {
82
106
} ) ;
83
107
}
84
108
109
+ if ( hasCircles && hasCluster ) {
110
+ circle . filter = [ '!' , [ 'has' , 'point_count' ] ] ;
111
+ }
112
+
85
113
if ( hasSymbols || hasText ) {
86
114
symbol . geojson = makeSymbolGeoJSON ( calcTrace , gd ) ;
87
115
@@ -142,10 +170,12 @@ module.exports = function convert(gd, calcTrace) {
142
170
return opts ;
143
171
} ;
144
172
145
- function initContainer ( ) {
173
+ function initContainer ( type ) {
146
174
return {
175
+ type : type ,
147
176
geojson : geoJsonUtils . makeBlank ( ) ,
148
177
layout : { visibility : 'none' } ,
178
+ filter : null ,
149
179
paint : { }
150
180
} ;
151
181
}
@@ -200,7 +230,8 @@ function makeCircleOpts(calcTrace) {
200
230
201
231
features . push ( {
202
232
type : 'Feature' ,
203
- geometry : { type : 'Point' , coordinates : lonlat } ,
233
+ id : i + 1 ,
234
+ geometry : { type : 'Point' , coordinates : lonlat } ,
204
235
properties : props
205
236
} ) ;
206
237
}
@@ -323,3 +354,17 @@ function blankFillFunc() { return ''; }
323
354
function isBADNUM ( lonlat ) {
324
355
return lonlat [ 0 ] === BADNUM ;
325
356
}
357
+
358
+ function arrayifyAttribute ( values , step ) {
359
+ var newAttribute ;
360
+ if ( Lib . isArrayOrTypedArray ( values ) && Lib . isArrayOrTypedArray ( step ) ) {
361
+ newAttribute = [ 'step' , [ 'get' , 'point_count' ] , values [ 0 ] ] ;
362
+
363
+ for ( var idx = 1 ; idx < values . length ; idx ++ ) {
364
+ newAttribute . push ( step [ idx - 1 ] , values [ idx ] ) ;
365
+ }
366
+ } else {
367
+ newAttribute = values ;
368
+ }
369
+ return newAttribute ;
370
+ }
0 commit comments