@@ -42,6 +42,23 @@ describe('select box and lasso', function() {
42
42
expect ( actual . y ) . toBeCloseToArray ( expected . y , PRECISION ) ;
43
43
}
44
44
45
+ function assertEventData ( actual , expected , msg ) {
46
+ expect ( actual . length ) . toBe ( expected . length , msg + ' same number of pts' ) ;
47
+
48
+ expected . forEach ( function ( e , i ) {
49
+ var a = actual [ i ] ;
50
+ var m = msg + ' (pt ' + i + ')' ;
51
+
52
+ expect ( a . data ) . toBeDefined ( m + ' has data ref' ) ;
53
+ expect ( a . fullData ) . toBeDefined ( m + ' has fullData ref' ) ;
54
+ expect ( Object . keys ( a ) . length - 2 ) . toBe ( Object . keys ( e ) . length , m + ' has correct number of keys' ) ;
55
+
56
+ Object . keys ( e ) . forEach ( function ( k ) {
57
+ expect ( a [ k ] ) . toBe ( e [ k ] , m + ' ' + k ) ;
58
+ } ) ;
59
+ } ) ;
60
+ }
61
+
45
62
describe ( 'select elements' , function ( ) {
46
63
var mockCopy = Lib . extendDeep ( { } , mock ) ;
47
64
mockCopy . layout . dragmode = 'select' ;
@@ -143,6 +160,10 @@ describe('select box and lasso', function() {
143
160
describe ( 'select events' , function ( ) {
144
161
var mockCopy = Lib . extendDeep ( { } , mock ) ;
145
162
mockCopy . layout . dragmode = 'select' ;
163
+ mockCopy . data [ 0 ] . ids = mockCopy . data [ 0 ] . x
164
+ . map ( function ( v ) { return 'id-' + v ; } ) ;
165
+ mockCopy . data [ 0 ] . customdata = mockCopy . data [ 0 ] . y
166
+ . map ( function ( v ) { return 'customdata-' + v ; } ) ;
146
167
147
168
var gd ;
148
169
beforeEach ( function ( done ) {
@@ -175,38 +196,41 @@ describe('select box and lasso', function() {
175
196
drag ( selectPath ) ;
176
197
177
198
expect ( selectingCnt ) . toEqual ( 1 , 'with the correct selecting count' ) ;
178
- expect ( selectingData . points ) . toEqual ( [ {
199
+ assertEventData ( selectingData . points , [ {
179
200
curveNumber : 0 ,
180
201
pointNumber : 0 ,
181
202
x : 0.002 ,
182
203
y : 16.25 ,
183
- id : undefined
204
+ id : 'id-0.002' ,
205
+ customdata : 'customdata-16.25'
184
206
} , {
185
207
curveNumber : 0 ,
186
208
pointNumber : 1 ,
187
209
x : 0.004 ,
188
210
y : 12.5 ,
189
- id : undefined
190
- } ] , 'with the correct selecting points' ) ;
211
+ id : 'id-0.004' ,
212
+ customdata : 'customdata-12.5'
213
+ } ] , 'with the correct selecting points (1)' ) ;
191
214
assertRange ( selectingData . range , {
192
215
x : [ 0.002000 , 0.0046236 ] ,
193
216
y : [ 0.10209191961595454 , 24.512223978291406 ]
194
217
} , 'with the correct selecting range' ) ;
195
-
196
218
expect ( selectedCnt ) . toEqual ( 1 , 'with the correct selected count' ) ;
197
- expect ( selectedData . points ) . toEqual ( [ {
219
+ assertEventData ( selectedData . points , [ {
198
220
curveNumber : 0 ,
199
221
pointNumber : 0 ,
200
222
x : 0.002 ,
201
223
y : 16.25 ,
202
- id : undefined
224
+ id : 'id-0.002' ,
225
+ customdata : 'customdata-16.25'
203
226
} , {
204
227
curveNumber : 0 ,
205
228
pointNumber : 1 ,
206
229
x : 0.004 ,
207
230
y : 12.5 ,
208
- id : undefined
209
- } ] , 'with the correct selected points' ) ;
231
+ id : 'id-0.004' ,
232
+ customdata : 'customdata-12.5'
233
+ } ] , 'with the correct selected points (2)' ) ;
210
234
assertRange ( selectedData . range , {
211
235
x : [ 0.002000 , 0.0046236 ] ,
212
236
y : [ 0.10209191961595454 , 24.512223978291406 ]
@@ -255,22 +279,20 @@ describe('select box and lasso', function() {
255
279
drag ( lassoPath ) ;
256
280
257
281
expect ( selectingCnt ) . toEqual ( 3 , 'with the correct selecting count' ) ;
258
- expect ( selectingData . points ) . toEqual ( [ {
282
+ assertEventData ( selectingData . points , [ {
259
283
curveNumber : 0 ,
260
284
pointNumber : 10 ,
261
285
x : 0.099 ,
262
- y : 2.75 ,
263
- id : undefined
264
- } ] , 'with the correct selecting points' ) ;
286
+ y : 2.75
287
+ } ] , 'with the correct selecting points (1)' ) ;
265
288
266
289
expect ( selectedCnt ) . toEqual ( 1 , 'with the correct selected count' ) ;
267
- expect ( selectedData . points ) . toEqual ( [ {
290
+ assertEventData ( selectedData . points , [ {
268
291
curveNumber : 0 ,
269
292
pointNumber : 10 ,
270
293
x : 0.099 ,
271
294
y : 2.75 ,
272
- id : undefined
273
- } ] , 'with the correct selected points' ) ;
295
+ } ] , 'with the correct selected points (2)' ) ;
274
296
275
297
doubleClick ( 250 , 200 ) . then ( function ( ) {
276
298
expect ( doubleClickData ) . toBe ( null , 'with the correct deselect data' ) ;
0 commit comments