@@ -12,7 +12,7 @@ var createRegl = require('regl');
12
12
var createScatter = require ( 'regl-scatter2d' ) ;
13
13
var createLine = require ( 'regl-line2d' ) ;
14
14
var createError = require ( 'regl-error2d' ) ;
15
- var kdtree = require ( 'kdgrass ' ) ;
15
+ var cluster = require ( 'point-cluster ' ) ;
16
16
var rgba = require ( 'color-normalize' ) ;
17
17
var svgSdf = require ( 'svg-path-sdf' ) ;
18
18
var arrayRange = require ( 'array-range' ) ;
@@ -42,6 +42,7 @@ var SYMBOL_SVG_CIRCLE = Drawing.symbolFuncs[0](SYMBOL_SIZE * 0.05);
42
42
var TOO_MANY_POINTS = 1e5 ;
43
43
var DOT_RE = / - d o t / ;
44
44
var OPEN_RE = / - o p e n / ;
45
+ var DESELECTDIM = require ( '../../constants/interactions' ) . DESELECTDIM ;
45
46
46
47
function calc ( gd , trace ) {
47
48
var fullLayout = gd . _fullLayout ;
@@ -81,14 +82,15 @@ function calc(gd, trace) {
81
82
// and it is also
82
83
if ( xa . type !== 'log' && ya . type !== 'log' ) {
83
84
// FIXME: delegate this to webworker
84
- stash . tree = kdtree ( positions , 512 ) ;
85
+ stash . tree = cluster ( positions ) ;
85
86
} else {
86
87
var ids = stash . ids = new Array ( count ) ;
87
88
for ( i = 0 ; i < count ; i ++ ) {
88
89
ids [ i ] = i ;
89
90
}
90
91
}
91
92
93
+
92
94
// create scene options and scene
93
95
calcColorscales ( trace ) ;
94
96
var options = sceneOptions ( gd , subplot , trace , positions ) ;
@@ -114,6 +116,13 @@ function calc(gd, trace) {
114
116
if ( options . line && ! scene . line2d ) scene . line2d = true ;
115
117
if ( ( options . errorX || options . errorY ) && ! scene . error2d ) scene . error2d = true ;
116
118
119
+ // FIXME: organize it in a more appropriate manner, probably in sceneOptions
120
+ // put point-cluster instance for optimized regl calc
121
+ if ( options . marker ) {
122
+ options . marker . cluster = stash . tree ;
123
+ }
124
+
125
+
117
126
// save scene options batch
118
127
scene . lineOptions . push ( options . line ) ;
119
128
scene . errorXOptions . push ( options . errorX ) ;
@@ -176,6 +185,33 @@ function sceneOptions(gd, subplot, trace, positions) {
176
185
}
177
186
}
178
187
188
+ function makeErrorOptions ( axLetter , errorOpts , vals ) {
189
+ var options = { } ;
190
+ options . positions = positions ;
191
+
192
+ var ax = AxisIDs . getFromId ( gd , trace [ axLetter + 'axis' ] ) ;
193
+ var errors = options . errors = new Float64Array ( 4 * count ) ;
194
+ var pOffset = { x : 0 , y : 1 } [ axLetter ] ;
195
+ var eOffset = { x : [ 0 , 1 , 2 , 3 ] , y : [ 2 , 3 , 0 , 1 ] } [ axLetter ] ;
196
+
197
+ for ( var i = 0 , p = 0 ; i < count ; i ++ , p += 4 ) {
198
+ errors [ p + eOffset [ 0 ] ] = positions [ i * 2 + pOffset ] - ax . d2l ( vals [ i ] [ axLetter + 's' ] ) || 0 ;
199
+ errors [ p + eOffset [ 1 ] ] = ax . d2l ( vals [ i ] [ axLetter + 'h' ] ) - positions [ i * 2 + pOffset ] || 0 ;
200
+ errors [ p + eOffset [ 2 ] ] = 0 ;
201
+ errors [ p + eOffset [ 3 ] ] = 0 ;
202
+ }
203
+
204
+ if ( errorOpts . copy_ystyle ) {
205
+ errorOpts = trace . error_y ;
206
+ }
207
+
208
+ options . capSize = errorOpts . width * 2 ;
209
+ options . lineWidth = errorOpts . thickness ;
210
+ options . color = errorOpts . color ;
211
+
212
+ return options ;
213
+ }
214
+
179
215
if ( hasLines ) {
180
216
lineOptions = { } ;
181
217
lineOptions . thickness = trace . line . width ;
@@ -271,34 +307,9 @@ function sceneOptions(gd, subplot, trace, positions) {
271
307
markerOptions = makeMarkerOptions ( markerOpts ) ;
272
308
selectedOptions = makeSelectedOptions ( trace . selected , markerOpts ) ;
273
309
unselectedOptions = makeSelectedOptions ( trace . unselected , markerOpts ) ;
274
- markerOptions . positions = positions ;
275
- }
276
-
277
- function makeErrorOptions ( axLetter , errorOpts , vals ) {
278
- var options = { } ;
279
- options . positions = positions ;
280
-
281
- var ax = AxisIDs . getFromId ( gd , trace [ axLetter + 'axis' ] ) ;
282
- var errors = options . errors = new Float64Array ( 4 * count ) ;
283
- var pOffset = { x : 0 , y : 1 } [ axLetter ] ;
284
- var eOffset = { x : [ 0 , 1 , 2 , 3 ] , y : [ 2 , 3 , 0 , 1 ] } [ axLetter ] ;
285
-
286
- for ( var i = 0 , p = 0 ; i < count ; i ++ , p += 4 ) {
287
- errors [ p + eOffset [ 0 ] ] = positions [ i * 2 + pOffset ] - ax . d2l ( vals [ i ] [ axLetter + 's' ] ) || 0 ;
288
- errors [ p + eOffset [ 1 ] ] = ax . d2l ( vals [ i ] [ axLetter + 'h' ] ) - positions [ i * 2 + pOffset ] || 0 ;
289
- errors [ p + eOffset [ 2 ] ] = 0 ;
290
- errors [ p + eOffset [ 3 ] ] = 0 ;
291
- }
292
-
293
- if ( errorOpts . copy_ystyle ) {
294
- errorOpts = trace . error_y ;
295
- }
310
+ if ( ! trace . unselected ) unselectedOptions . opacity = DESELECTDIM ;
296
311
297
- options . capSize = errorOpts . width * 2 ;
298
- options . lineWidth = errorOpts . thickness ;
299
- options . color = errorOpts . color ;
300
-
301
- return options ;
312
+ markerOptions . positions = positions ;
302
313
}
303
314
304
315
function makeSelectedOptions ( selected , markerOpts ) {
@@ -882,8 +893,8 @@ function plot(gd, subplot, cdata) {
882
893
if ( selectMode ) {
883
894
// create select2d
884
895
if ( ! scene . select2d ) {
885
- // create scatter instance by cloning scatter2d
886
- scene . select2d = createScatter ( fullLayout . _glcanvas . data ( ) [ 1 ] . regl , { clone : scene . scatter2d } ) ;
896
+ // create select scatter instance by cloning scatter2d
897
+ scene . select2d = createScatter ( fullLayout . _glcanvas . data ( ) [ 1 ] . regl ) ;
887
898
}
888
899
889
900
if ( scene . scatter2d && scene . selectBatch && scene . selectBatch . length ) {
@@ -1126,7 +1137,6 @@ function selectPoints(searchInfo, polygon) {
1126
1137
scene . selectBatch = [ ] ;
1127
1138
scene . unselectBatch = [ ] ;
1128
1139
}
1129
-
1130
1140
if ( ! scene . selectBatch [ stash . index ] ) {
1131
1141
// enter every trace select mode
1132
1142
for ( i = 0 ; i < scene . count ; i ++ ) {
0 commit comments