@@ -8,8 +8,8 @@ var tinycolor = require('tinycolor2');
88var handleTickValueDefaults = require ( '@src/plots/cartesian/tick_value_defaults' ) ;
99var Axes = PlotlyInternal . Axes ;
1010
11- var createGraph = require ( '../assets/create_graph_div' ) ;
12- var destroyGraph = require ( '../assets/destroy_graph_div' ) ;
11+ var createGraphDiv = require ( '../assets/create_graph_div' ) ;
12+ var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
1313
1414
1515describe ( 'Test axes' , function ( ) {
@@ -384,15 +384,137 @@ describe('Test axes', function() {
384384 } ) ;
385385 } ) ;
386386
387+ describe ( 'categorymode' , function ( ) {
388+
389+ var gd ;
390+
391+ beforeEach ( function ( ) {
392+ gd = createGraphDiv ( ) ;
393+ } ) ;
394+
395+ afterEach ( destroyGraphDiv ) ;
396+
397+ describe ( 'setting, or not setting categorymode if it is not explicitly declared' , function ( ) {
398+
399+ it ( 'should set categorymode to default if categorymode and categorylist are not supplied' , function ( ) {
400+ PlotlyInternal . plot ( gd , [ { x : [ 'c' , 'a' , 'e' , 'b' , 'd' ] , y : [ 15 , 11 , 12 , 13 , 14 ] } ] , { xaxis : { type : 'category' } } ) ;
401+ expect ( gd . _fullLayout . xaxis . categorymode ) . toBe ( 'trace' ) ;
402+ } ) ;
403+
404+ it ( 'should set categorymode to default even if type is not set to category explicitly' , function ( ) {
405+ PlotlyInternal . plot ( gd , [ { x : [ 'c' , 'a' , 'e' , 'b' , 'd' ] , y : [ 15 , 11 , 12 , 13 , 14 ] } ] ) ;
406+ expect ( gd . _fullLayout . xaxis . categorymode ) . toBe ( 'trace' ) ;
407+ } ) ;
408+
409+ it ( 'should NOT set categorymode to default if type is not category' , function ( ) {
410+ PlotlyInternal . plot ( gd , [ { x : [ 'c' , 'a' , 'e' , 'b' , 'd' ] , y : [ 15 , 11 , 12 , 13 , 14 ] } ] ) ;
411+ expect ( gd . _fullLayout . yaxis . categorymode ) . toBe ( undefined ) ;
412+ } ) ;
413+
414+ it ( 'should set categorymode to default if type is overridden to be category' , function ( ) {
415+ PlotlyInternal . plot ( gd , [ { x : [ 1 , 2 , 3 , 4 , 5 ] , y : [ 15 , 11 , 12 , 13 , 14 ] } ] , { yaxis : { type : 'category' } } ) ;
416+ expect ( gd . _fullLayout . xaxis . categorymode ) . toBe ( undefined ) ;
417+ expect ( gd . _fullLayout . yaxis . categorymode ) . toBe ( 'trace' ) ;
418+ } ) ;
419+
420+ } ) ;
421+
422+ describe ( 'setting categorymode to "array"' , function ( ) {
423+
424+ it ( 'should leave categorymode on "array" if it is supplied' , function ( ) {
425+ PlotlyInternal . plot ( gd , [ { x : [ 'c' , 'a' , 'e' , 'b' , 'd' ] , y : [ 15 , 11 , 12 , 13 , 14 ] } ] , {
426+ xaxis : { type : 'category' , categorymode : 'array' , categorylist : [ 'b' , 'a' , 'd' , 'e' , 'c' ] }
427+ } ) ;
428+ expect ( gd . _fullLayout . xaxis . categorymode ) . toBe ( 'array' ) ;
429+ } ) ;
430+
431+ it ( 'should switch categorymode on "array" if it is not supplied but categorylist is supplied' , function ( ) {
432+ PlotlyInternal . plot ( gd , [ { x : [ 'c' , 'a' , 'e' , 'b' , 'd' ] , y : [ 15 , 11 , 12 , 13 , 14 ] } ] , {
433+ xaxis : { type : 'category' , categorylist : [ 'b' , 'a' , 'd' , 'e' , 'c' ] }
434+ } ) ;
435+ expect ( gd . _fullLayout . xaxis . categorymode ) . toBe ( 'array' ) ;
436+ } ) ;
437+
438+ it ( 'should revert categorymode to "trace" if "array" is supplied but there is no list' , function ( ) {
439+ PlotlyInternal . plot ( gd , [ { x : [ 'c' , 'a' , 'e' , 'b' , 'd' ] , y : [ 15 , 11 , 12 , 13 , 14 ] } ] , {
440+ xaxis : { type : 'category' , categorymode : 'array' }
441+ } ) ;
442+ expect ( gd . _fullLayout . xaxis . categorymode ) . toBe ( 'trace' ) ;
443+ } ) ;
444+
445+ } ) ;
446+
447+ describe ( 'do not set categorymode to "array" if list exists but empty' , function ( ) {
448+
449+ it ( 'should switch categorymode to default if list is not supplied' , function ( ) {
450+ PlotlyInternal . plot ( gd , [ { x : [ 'c' , 'a' , 'e' , 'b' , 'd' ] , y : [ 15 , 11 , 12 , 13 , 14 ] } ] , {
451+ xaxis : { type : 'category' , categorymode : 'array' , categorylist : [ ] }
452+ } ) ;
453+ expect ( gd . _fullLayout . xaxis . categorymode ) . toBe ( 'trace' ) ;
454+ } ) ;
455+
456+ it ( 'should not switch categorymode on "array" if categorylist is supplied but empty' , function ( ) {
457+ PlotlyInternal . plot ( gd , [ { x : [ 'c' , 'a' , 'e' , 'b' , 'd' ] , y : [ 15 , 11 , 12 , 13 , 14 ] } ] , {
458+ xaxis : { type : 'category' , categorylist : [ ] }
459+ } ) ;
460+ expect ( gd . _fullLayout . xaxis . categorymode ) . toBe ( 'trace' ) ;
461+ } ) ;
462+ } ) ;
463+
464+ describe ( 'do NOT set categorymode to "array" if it has some other proper value' , function ( ) {
465+
466+ it ( 'should use specified categorymode if it is supplied even if categorylist exists' , function ( ) {
467+ PlotlyInternal . plot ( gd , [ { x : [ 'c' , 'a' , 'e' , 'b' , 'd' ] , y : [ 15 , 11 , 12 , 13 , 14 ] } ] , {
468+ xaxis : { type : 'category' , categorymode : 'trace' , categorylist : [ 'b' , 'a' , 'd' , 'e' , 'c' ] }
469+ } ) ;
470+ expect ( gd . _fullLayout . xaxis . categorymode ) . toBe ( 'trace' ) ;
471+ } ) ;
472+
473+ it ( 'should use specified categorymode if it is supplied even if categorylist exists' , function ( ) {
474+ PlotlyInternal . plot ( gd , [ { x : [ 'c' , 'a' , 'e' , 'b' , 'd' ] , y : [ 15 , 11 , 12 , 13 , 14 ] } ] , {
475+ xaxis : { type : 'category' , categorymode : 'category ascending' , categorylist : [ 'b' , 'a' , 'd' , 'e' , 'c' ] }
476+ } ) ;
477+ expect ( gd . _fullLayout . xaxis . categorymode ) . toBe ( 'category ascending' ) ;
478+ } ) ;
479+
480+ it ( 'should use specified categorymode if it is supplied even if categorylist exists' , function ( ) {
481+ PlotlyInternal . plot ( gd , [ { x : [ 'c' , 'a' , 'e' , 'b' , 'd' ] , y : [ 15 , 11 , 12 , 13 , 14 ] } ] , {
482+ xaxis : { type : 'category' , categorymode : 'category descending' , categorylist : [ 'b' , 'a' , 'd' , 'e' , 'c' ] }
483+ } ) ;
484+ expect ( gd . _fullLayout . xaxis . categorymode ) . toBe ( 'category descending' ) ;
485+ } ) ;
486+
487+ } ) ;
488+
489+ describe ( 'setting categorymode to the default if the value is unexpected' , function ( ) {
490+
491+ it ( 'should switch categorymode to "trace" if mode is supplied but invalid' , function ( ) {
492+ PlotlyInternal . plot ( gd , [ { x : [ 'c' , 'a' , 'e' , 'b' , 'd' ] , y : [ 15 , 11 , 12 , 13 , 14 ] } ] , {
493+ xaxis : { type : 'category' , categorymode : 'invalid value' }
494+ } ) ;
495+ expect ( gd . _fullLayout . xaxis . categorymode ) . toBe ( 'trace' ) ;
496+ } ) ;
497+
498+ it ( 'should switch categorymode to "array" if mode is supplied but invalid and list is supplied' , function ( ) {
499+ PlotlyInternal . plot ( gd , [ { x : [ 'c' , 'a' , 'e' , 'b' , 'd' ] , y : [ 15 , 11 , 12 , 13 , 14 ] } ] , {
500+ xaxis : { type : 'category' , categorymode : 'invalid value' , categorylist : [ 'b' , 'a' , 'd' , 'e' , 'c' ] }
501+ } ) ;
502+ expect ( gd . _fullLayout . xaxis . categorymode ) . toBe ( 'array' ) ;
503+ } ) ;
504+
505+ } ) ;
506+
507+ } ) ;
508+
387509 describe ( 'handleTickDefaults' , function ( ) {
388510 var data = [ { x : [ 1 , 2 , 3 ] , y : [ 3 , 4 , 5 ] } ] ,
389511 gd ;
390512
391513 beforeEach ( function ( ) {
392- gd = createGraph ( ) ;
514+ gd = createGraphDiv ( ) ;
393515 } ) ;
394516
395- afterEach ( destroyGraph ) ;
517+ afterEach ( destroyGraphDiv ) ;
396518
397519 it ( 'should set defaults on bad inputs' , function ( ) {
398520 var layout = {
0 commit comments