@@ -4,6 +4,18 @@ var Plots = require('@src/plots/plots');
44var Heatmap = require ( '@src/traces/heatmap' ) ;
55var Scatter = require ( '@src/traces/scatter' ) ;
66
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+ }
719
820describe ( 'Test colorscale:' , function ( ) {
921 'use strict' ;
@@ -296,41 +308,6 @@ describe('Test colorscale:', function() {
296308 handleDefaults ( traceIn , traceOut , layout , coerce , opts ) ;
297309 expect ( traceOut . showscale ) . toBe ( false ) ;
298310 } ) ;
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- } ) ;
334311 } ) ;
335312
336313 describe ( 'handleDefaults (scatter-like version)' , function ( ) {
@@ -384,61 +361,28 @@ describe('Test colorscale:', function() {
384361 expect ( traceOut . marker . showscale ) . toBe ( true ) ;
385362 } ) ;
386363
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- } ) ;
421364 } ) ;
422365
423366 describe ( 'calc' , function ( ) {
424367 var calcColorscale = Colorscale . calc ;
425368 var trace , z ;
369+ var gd ;
426370
427371 beforeEach ( function ( ) {
428372 trace = { } ;
429373 z = { } ;
374+ gd = { } ;
430375 } ) ;
431376
432377 it ( 'should be RdBuNeg when autocolorscale and z <= 0' , function ( ) {
433378 trace = {
434379 type : 'heatmap' ,
435- z : [ [ 0 , - 1.5 ] , [ - 2 , - 10 ] ] ,
380+ z : [ [ - 0 , - 1.5 ] , [ - 2 , - 10 ] ] ,
436381 autocolorscale : true ,
437382 _input : { autocolorscale : true }
438383 } ;
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' } ) ;
442386 expect ( trace . autocolorscale ) . toBe ( true ) ;
443387 expect ( trace . colorscale [ 5 ] ) . toEqual ( [ 1 , 'rgb(220,220,220)' ] ) ;
444388 } ) ;
@@ -452,8 +396,8 @@ describe('Test colorscale:', function() {
452396 autocolorscale : true ,
453397 _input : { }
454398 } ;
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' } ) ;
457401 expect ( trace . autocolorscale ) . toBe ( false ) ;
458402 expect ( trace . colorscale [ 5 ] ) . toEqual ( [ 1 , 'rgb(220,220,220)' ] ) ;
459403 } ) ;
@@ -466,7 +410,8 @@ describe('Test colorscale:', function() {
466410 _input : { autocolorscale : true }
467411 } ;
468412 z = [ [ undefined , undefined ] , [ - 0.5 , undefined ] ] ;
469- calcColorscale ( trace , z , '' , 'z' ) ;
413+ gd = _supply ( trace ) ;
414+ calcColorscale ( gd , trace , { vals : z , containerStr : '' , cLetter : 'z' } ) ;
470415 expect ( trace . autocolorscale ) . toBe ( true ) ;
471416 expect ( trace . colorscale [ 5 ] ) . toEqual ( [ 1 , 'rgb(220,220,220)' ] ) ;
472417 } ) ;
@@ -479,7 +424,8 @@ describe('Test colorscale:', function() {
479424 _input : { autocolorscale : true }
480425 } ;
481426 z = [ [ undefined , undefined ] , [ 0.5 , undefined ] ] ;
482- calcColorscale ( trace , z , '' , 'z' ) ;
427+ gd = _supply ( trace ) ;
428+ calcColorscale ( gd , trace , { vals : z , containerStr : '' , cLetter : 'z' } ) ;
483429 expect ( trace . autocolorscale ) . toBe ( true ) ;
484430 expect ( trace . colorscale [ 0 ] ) . toEqual ( [ 0 , 'rgb(220,220,220)' ] ) ;
485431 } ) ;
@@ -493,7 +439,8 @@ describe('Test colorscale:', function() {
493439 _input : { autocolorscale : true }
494440 } ;
495441 z = [ [ undefined , undefined ] , [ 0.5 , undefined ] ] ;
496- calcColorscale ( trace , z , '' , 'z' ) ;
442+ gd = _supply ( trace ) ;
443+ calcColorscale ( gd , trace , { vals : z , containerStr : '' , cLetter : 'z' } ) ;
497444 expect ( trace . autocolorscale ) . toBe ( true ) ;
498445 expect ( trace . colorscale [ trace . colorscale . length - 1 ] )
499446 . toEqual ( [ 1 , 'rgb(220,220,220)' ] ) ;
0 commit comments