@@ -13,6 +13,84 @@ var customMatchers = require('../assets/custom_matchers');
13
13
describe ( 'scattermapbox defaults' , function ( ) {
14
14
'use strict' ;
15
15
16
+ function _supply ( traceIn ) {
17
+ var traceOut = { visible : true } ,
18
+ defaultColor = '#444' ,
19
+ layout = { _dataLength : 1 } ;
20
+
21
+ ScatterMapbox . supplyDefaults ( traceIn , traceOut , defaultColor , layout ) ;
22
+
23
+ return traceOut ;
24
+ }
25
+
26
+ it ( 'should truncate \'lon\' if longer than \'lat\'' , function ( ) {
27
+ var fullTrace = _supply ( {
28
+ lon : [ 1 , 2 , 3 ] ,
29
+ lat : [ 2 , 3 ]
30
+ } ) ;
31
+
32
+ expect ( fullTrace . lon ) . toEqual ( [ 1 , 2 ] ) ;
33
+ expect ( fullTrace . lat ) . toEqual ( [ 2 , 3 ] ) ;
34
+ } ) ;
35
+
36
+ it ( 'should truncate \'lat\' if longer than \'lon\'' , function ( ) {
37
+ var fullTrace = _supply ( {
38
+ lon : [ 1 , 2 , 3 ] ,
39
+ lat : [ 2 , 3 , 3 , 5 ]
40
+ } ) ;
41
+
42
+ expect ( fullTrace . lon ) . toEqual ( [ 1 , 2 , 3 ] ) ;
43
+ expect ( fullTrace . lat ) . toEqual ( [ 2 , 3 , 3 ] ) ;
44
+ } ) ;
45
+
46
+ it ( 'should set \'visible\' to false if \'lat\' and/or \'lon\' has zero length' , function ( ) {
47
+ var fullTrace = _supply ( {
48
+ lon : [ 1 , 2 , 3 ] ,
49
+ lat : [ ]
50
+ } ) ;
51
+
52
+ expect ( fullTrace . visible ) . toEqual ( false ) ;
53
+
54
+ fullTrace = _supply ( {
55
+ lon : null ,
56
+ lat : [ 1 , 2 , 3 ]
57
+ } ) ;
58
+
59
+ expect ( fullTrace . visible ) . toEqual ( false ) ;
60
+ } ) ;
61
+
62
+ it ( 'should set \'marker.color\' and \'marker.size\' to first item if symbol is set to \'circle\'' , function ( ) {
63
+ var base = {
64
+ mode : 'markers' ,
65
+ lon : [ 1 , 2 , 3 ] ,
66
+ lat : [ 2 , 3 , 3 ] ,
67
+ marker : {
68
+ color : [ 'red' , 'green' , 'blue' ] ,
69
+ size : [ 10 , 20 , 30 ]
70
+ }
71
+ } ;
72
+
73
+ var fullTrace = _supply ( Lib . extendDeep ( { } , base , {
74
+ marker : { symbol : 'monument' }
75
+ } ) ) ;
76
+
77
+ expect ( fullTrace . marker . color ) . toEqual ( 'red' ) ;
78
+ expect ( fullTrace . marker . size ) . toEqual ( 10 ) ;
79
+
80
+ fullTrace = _supply ( Lib . extendDeep ( { } , base , {
81
+ marker : { symbol : [ 'monument' , 'music' , 'harbor' ] }
82
+ } ) ) ;
83
+
84
+ expect ( fullTrace . marker . color ) . toEqual ( 'red' ) ;
85
+ expect ( fullTrace . marker . size ) . toEqual ( 10 ) ;
86
+
87
+ fullTrace = _supply ( Lib . extendDeep ( { } , base , {
88
+ marker : { symbol : 'circle' }
89
+ } ) ) ;
90
+
91
+ expect ( fullTrace . marker . color ) . toEqual ( [ 'red' , 'green' , 'blue' ] ) ;
92
+ expect ( fullTrace . marker . size ) . toEqual ( [ 10 , 20 , 30 ] ) ;
93
+ } ) ;
16
94
} ) ;
17
95
18
96
describe ( 'scattermapbox calc' , function ( ) {
@@ -187,10 +265,28 @@ describe('scattermapbox convert', function() {
187
265
188
266
expect ( opts . circle . paint [ 'circle-color' ] ) . toEqual ( {
189
267
property : 'circle-color' ,
190
- stops : [ [
191
-
192
- ] ]
268
+ stops : [
269
+ [ 0 , 'rgb(220, 220, 220)' ] , [ 1 , '#444' ] , [ 2 , 'rgb(178, 10, 28)' ]
270
+ ]
271
+ } , 'have correct circle-color stops' ) ;
272
+
273
+ expect ( opts . circle . paint [ 'circle-radius' ] ) . toEqual ( {
274
+ property : 'circle-radius' ,
275
+ stops : [ [ 0 , 5 ] , [ 1 , 10 ] , [ 2 , 0 ] ]
276
+ } , 'have correct circle-radius stops' ) ;
277
+
278
+ var circleProps = opts . circle . geojson . features . map ( function ( f ) {
279
+ return f . properties ;
193
280
} ) ;
281
+
282
+ // N.B repeated values have same geojson props
283
+ expect ( circleProps ) . toEqual ( [
284
+ { 'circle-color' : 0 , 'circle-radius' : 0 } ,
285
+ { 'circle-color' : 1 , 'circle-radius' : 1 } ,
286
+ { 'circle-color' : 2 , 'circle-radius' : 2 } ,
287
+ { 'circle-color' : 1 , 'circle-radius' : 2 } ,
288
+ { 'circle-color' : 1 , 'circle-radius' : 2 }
289
+ ] , 'have correct geojson feature properties' ) ;
194
290
} ) ;
195
291
196
292
it ( 'fill + markers + lines traces, should' , function ( ) {
@@ -211,7 +307,13 @@ describe('scattermapbox convert', function() {
211
307
expect ( opts . fill . geojson . coordinates ) . toEqual ( lineCoords , 'have correct fill coords' ) ;
212
308
expect ( opts . line . geojson . coordinates ) . toEqual ( lineCoords , 'have correct line coords' ) ;
213
309
310
+ var circleCoords = opts . circle . geojson . features . map ( function ( f ) {
311
+ return f . geometry . coordinates ;
312
+ } ) ;
214
313
314
+ expect ( circleCoords ) . toEqual ( [
315
+ [ 10 , 20 ] , [ 20 , 20 ] , [ 30 , 10 ] , [ 20 , 10 ] , [ 10 , 20 ]
316
+ ] , 'have correct circle coords' ) ;
215
317
} ) ;
216
318
217
319
it ( 'for markers + non-circle traces, should' , function ( ) {
@@ -221,12 +323,23 @@ describe('scattermapbox convert', function() {
221
323
} ) ) ;
222
324
223
325
assertVisibility ( opts , [ 'none' , 'none' , 'none' , 'visible' ] ) ;
326
+
327
+ var symbolProps = opts . symbol . geojson . features . map ( function ( f ) {
328
+ return [ f . properties . symbol , f . properties . text ] ;
329
+ } ) ;
330
+
331
+ var expected = opts . symbol . geojson . features . map ( function ( ) {
332
+ return [ 'monument' , '' ] ;
333
+ } ) ;
334
+
335
+ expect ( symbolProps ) . toEqual ( expected , 'have correct geojson properties' ) ;
224
336
} ) ;
225
337
226
338
it ( 'for text + lines traces, should' , function ( ) {
227
339
var opts = _convert ( Lib . extendFlat ( { } , base , {
228
340
mode : 'lines+text' ,
229
- connectgaps : true
341
+ connectgaps : true ,
342
+ text : [ 'A' , 'B' , 'C' , 'D' , 'E' , 'F' ]
230
343
} ) ) ;
231
344
232
345
assertVisibility ( opts , [ 'none' , 'visible' , 'none' , 'visible' ] ) ;
@@ -236,6 +349,42 @@ describe('scattermapbox convert', function() {
236
349
] ] ;
237
350
238
351
expect ( opts . line . geojson . coordinates ) . toEqual ( lineCoords , 'have correct line coords' ) ;
352
+
353
+ var actualText = opts . symbol . geojson . features . map ( function ( f ) {
354
+ return f . properties . text ;
355
+ } ) ;
356
+
357
+ expect ( actualText ) . toEqual ( [ 'A' , 'B' , 'C' , 'F' , '' ] ) ;
358
+ } ) ;
359
+
360
+ it ( 'should correctly convert \'textposition\' to \'text-anchor\' and \'text-offset\'' , function ( ) {
361
+ var specs = {
362
+ 'top left' : [ 'top-right' , [ - 1.5 , - 2.5 ] ] ,
363
+ 'top center' : [ 'top' , [ 0 , - 2.5 ] ] ,
364
+ 'top right' : [ 'top-left' , [ 1.5 , - 2.5 ] ] ,
365
+ 'middle left' : [ 'right' , [ - 1.5 , 0 ] ] ,
366
+ 'middle center' : [ 'center' , [ 0 , 0 ] ] ,
367
+ 'middle right' : [ 'left' , [ 1.5 , 0 ] ] ,
368
+ 'bottom left' : [ 'bottom-right' , [ - 1.5 , 2.5 ] ] ,
369
+ 'bottom center' : [ 'bottom' , [ 0 , 2.5 ] ] ,
370
+ 'bottom right' : [ 'bottom-left' , [ 1.5 , 2.5 ] ]
371
+ } ;
372
+
373
+ Object . keys ( specs ) . forEach ( function ( k ) {
374
+ var spec = specs [ k ] ;
375
+
376
+ var opts = _convert ( Lib . extendFlat ( { } , base , {
377
+ textposition : k ,
378
+ mode : 'text+markers' ,
379
+ marker : { size : 15 } ,
380
+ text : [ 'A' , 'B' , 'C' ]
381
+ } ) ) ;
382
+
383
+ expect ( [
384
+ opts . symbol . layout [ 'text-anchor' ] ,
385
+ opts . symbol . layout [ 'text-offset' ]
386
+ ] ) . toEqual ( spec , '(case ' + k + ')' ) ;
387
+ } ) ;
239
388
} ) ;
240
389
241
390
function assertVisibility ( opts , expectations ) {
@@ -249,12 +398,6 @@ describe('scattermapbox convert', function() {
249
398
}
250
399
} ) ;
251
400
252
- describe ( 'scattermapbox plot' , function ( ) {
253
- 'use strict' ;
254
-
255
-
256
- } ) ;
257
-
258
401
describe ( 'scattermapbox hover' , function ( ) {
259
402
'use strict' ;
260
403
0 commit comments