@@ -4,6 +4,18 @@ var Plots = require('@src/plots/plots');
4
4
var Heatmap = require ( '@src/traces/heatmap' ) ;
5
5
var Scatter = require ( '@src/traces/scatter' ) ;
6
6
7
+ var supplyAllDefaults = require ( '../assets/supply_defaults' ) ;
8
+
9
+ function _supply ( trace , layout ) {
10
+ var gd = {
11
+ data : [ trace ] ,
12
+ layout : layout || { }
13
+ } ;
14
+
15
+ supplyAllDefaults ( gd ) ;
16
+
17
+ return gd ;
18
+ }
7
19
8
20
describe ( 'Test colorscale:' , function ( ) {
9
21
'use strict' ;
@@ -296,41 +308,6 @@ describe('Test colorscale:', function() {
296
308
handleDefaults ( traceIn , traceOut , layout , coerce , opts ) ;
297
309
expect ( traceOut . showscale ) . toBe ( false ) ;
298
310
} ) ;
299
-
300
- it ( 'should use global colorscale.diverging if no colorscale is specified' , function ( ) {
301
- traceIn = {
302
- zmin : - 10 ,
303
- zmax : 10
304
- } ;
305
- var divergingScale = [ [ 0 , 'rgb(0,0,0)' ] , [ 1 , 'rgb(255,255,255)' ] ] ;
306
- var layout2 = {
307
- colorscale : {
308
- diverging : divergingScale
309
- } ,
310
- _dfltTitle : { colorbar : 'cb' }
311
- } ;
312
- handleDefaults ( traceIn , traceOut , layout2 , coerce , opts ) ;
313
- expect ( traceOut . colorscale ) . toBe ( divergingScale ) ;
314
- } ) ;
315
-
316
- it ( 'should not use layout colorscale.diverging if colorscale is specified' , function ( ) {
317
- var divergingScale = [ [ 0 , 'rgb(0,0,0)' ] , [ 1 , 'rgb(255,255,255)' ] ] ;
318
- var traceColorscale = [ [ 0 , 'rgb(128,128,128)' ] , [ 1 , 'rgb(255,255,255)' ] ] ;
319
- traceIn = {
320
- zmin : - 10 ,
321
- zmax : 10 ,
322
- colorscale : traceColorscale
323
- } ;
324
-
325
- var layout2 = {
326
- colorscale : {
327
- diverging : divergingScale
328
- } ,
329
- _dfltTitle : { colorbar : 'cb' }
330
- } ;
331
- handleDefaults ( traceIn , traceOut , layout2 , coerce , opts ) ;
332
- expect ( traceOut . colorscale ) . toBe ( traceColorscale ) ;
333
- } ) ;
334
311
} ) ;
335
312
336
313
describe ( 'handleDefaults (scatter-like version)' , function ( ) {
@@ -384,61 +361,28 @@ describe('Test colorscale:', function() {
384
361
expect ( traceOut . marker . showscale ) . toBe ( true ) ;
385
362
} ) ;
386
363
387
- it ( 'should use layout colorscale.diverging if no colorscale is specified' , function ( ) {
388
- traceIn = {
389
- zmin : - 10 ,
390
- zmax : 10
391
- } ;
392
- var divergingScale = [ [ 0 , 'rgb(0,0,0)' ] , [ 1 , 'rgb(255,255,255)' ] ] ;
393
- var layout2 = {
394
- colorscale : {
395
- diverging : divergingScale
396
- } ,
397
- _dfltTitle : { colorbar : 'cb' }
398
- } ;
399
- handleDefaults ( traceIn , traceOut , layout2 , coerce , opts ) ;
400
- expect ( traceOut . marker . colorscale ) . toBe ( divergingScale ) ;
401
- } ) ;
402
-
403
- it ( 'should not use layout colorscale.diverging if colorscale is specified' , function ( ) {
404
- var divergingScale = [ [ 0 , 'rgb(0,0,0)' ] , [ 1 , 'rgb(255,255,255)' ] ] ;
405
- var traceColorscale = [ [ 0 , 'rgb(128,128,128)' ] , [ 1 , 'rgb(255,255,255)' ] ] ;
406
- traceIn = {
407
- marker : {
408
- colorscale : traceColorscale
409
- }
410
- } ;
411
-
412
- var layout2 = {
413
- colorscale : {
414
- diverging : divergingScale
415
- } ,
416
- _dfltTitle : { colorbar : 'cb' }
417
- } ;
418
- handleDefaults ( traceIn , traceOut , layout2 , coerce , opts ) ;
419
- expect ( traceOut . marker . colorscale ) . toBe ( traceColorscale ) ;
420
- } ) ;
421
364
} ) ;
422
365
423
366
describe ( 'calc' , function ( ) {
424
367
var calcColorscale = Colorscale . calc ;
425
368
var trace , z ;
369
+ var gd ;
426
370
427
371
beforeEach ( function ( ) {
428
372
trace = { } ;
429
373
z = { } ;
374
+ gd = { } ;
430
375
} ) ;
431
376
432
377
it ( 'should be RdBuNeg when autocolorscale and z <= 0' , function ( ) {
433
378
trace = {
434
379
type : 'heatmap' ,
435
- z : [ [ 0 , - 1.5 ] , [ - 2 , - 10 ] ] ,
380
+ z : [ [ - 0 , - 1.5 ] , [ - 2 , - 10 ] ] ,
436
381
autocolorscale : true ,
437
382
_input : { autocolorscale : true }
438
383
} ;
439
-
440
- z = [ [ 0 , - 1.5 ] , [ - 2 , - 10 ] ] ;
441
- calcColorscale ( trace , z , '' , 'z' ) ;
384
+ gd = _supply ( trace ) ;
385
+ calcColorscale ( gd , trace , { vals : trace . z , containerStr : '' , cLetter : 'z' } ) ;
442
386
expect ( trace . autocolorscale ) . toBe ( true ) ;
443
387
expect ( trace . colorscale [ 5 ] ) . toEqual ( [ 1 , 'rgb(220,220,220)' ] ) ;
444
388
} ) ;
@@ -452,8 +396,8 @@ describe('Test colorscale:', function() {
452
396
autocolorscale : true ,
453
397
_input : { }
454
398
} ;
455
- z = [ [ 0 , - 1.5 ] , [ - 2 , - 10 ] ] ;
456
- calcColorscale ( trace , z , '' , 'z' ) ;
399
+ gd = _supply ( trace ) ;
400
+ calcColorscale ( gd , trace , { vals : trace . z , containerStr : '' , cLetter : 'z' } ) ;
457
401
expect ( trace . autocolorscale ) . toBe ( false ) ;
458
402
expect ( trace . colorscale [ 5 ] ) . toEqual ( [ 1 , 'rgb(220,220,220)' ] ) ;
459
403
} ) ;
@@ -466,7 +410,8 @@ describe('Test colorscale:', function() {
466
410
_input : { autocolorscale : true }
467
411
} ;
468
412
z = [ [ undefined , undefined ] , [ - 0.5 , undefined ] ] ;
469
- calcColorscale ( trace , z , '' , 'z' ) ;
413
+ gd = _supply ( trace ) ;
414
+ calcColorscale ( gd , trace , { vals : z , containerStr : '' , cLetter : 'z' } ) ;
470
415
expect ( trace . autocolorscale ) . toBe ( true ) ;
471
416
expect ( trace . colorscale [ 5 ] ) . toEqual ( [ 1 , 'rgb(220,220,220)' ] ) ;
472
417
} ) ;
@@ -479,7 +424,8 @@ describe('Test colorscale:', function() {
479
424
_input : { autocolorscale : true }
480
425
} ;
481
426
z = [ [ undefined , undefined ] , [ 0.5 , undefined ] ] ;
482
- calcColorscale ( trace , z , '' , 'z' ) ;
427
+ gd = _supply ( trace ) ;
428
+ calcColorscale ( gd , trace , { vals : z , containerStr : '' , cLetter : 'z' } ) ;
483
429
expect ( trace . autocolorscale ) . toBe ( true ) ;
484
430
expect ( trace . colorscale [ 0 ] ) . toEqual ( [ 0 , 'rgb(220,220,220)' ] ) ;
485
431
} ) ;
@@ -493,7 +439,8 @@ describe('Test colorscale:', function() {
493
439
_input : { autocolorscale : true }
494
440
} ;
495
441
z = [ [ undefined , undefined ] , [ 0.5 , undefined ] ] ;
496
- calcColorscale ( trace , z , '' , 'z' ) ;
442
+ gd = _supply ( trace ) ;
443
+ calcColorscale ( gd , trace , { vals : z , containerStr : '' , cLetter : 'z' } ) ;
497
444
expect ( trace . autocolorscale ) . toBe ( true ) ;
498
445
expect ( trace . colorscale [ trace . colorscale . length - 1 ] )
499
446
. toEqual ( [ 1 , 'rgb(220,220,220)' ] ) ;
0 commit comments