@@ -10,31 +10,79 @@ var customMatchers = require('../assets/custom_matchers');
10
10
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
11
11
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
12
12
13
+
13
14
describe ( 'Test annotations' , function ( ) {
14
15
'use strict' ;
15
16
16
17
describe ( 'supplyLayoutDefaults' , function ( ) {
18
+
19
+ function _supply ( layoutIn , layoutOut ) {
20
+ layoutOut = layoutOut || { } ;
21
+ layoutOut . _has = Plots . _hasPlotType . bind ( layoutOut ) ;
22
+
23
+ Annotations . supplyLayoutDefaults ( layoutIn , layoutOut ) ;
24
+
25
+ return layoutOut . annotations ;
26
+ }
27
+
28
+ it ( 'should skip non-array containers' , function ( ) {
29
+ [ null , undefined , { } , 'str' , 0 , false , true ] . forEach ( function ( cont ) {
30
+ var msg = '- ' + JSON . stringify ( cont ) ;
31
+ var layoutIn = { annotations : cont } ;
32
+ var out = _supply ( layoutIn ) ;
33
+
34
+ expect ( layoutIn . annotations ) . toBe ( cont , msg ) ;
35
+ expect ( out ) . toEqual ( [ ] , msg ) ;
36
+ } ) ;
37
+ } ) ;
38
+
39
+ it ( 'should make non-object item visible: false' , function ( ) {
40
+ var annotations = [ null , undefined , [ ] , 'str' , 0 , false , true ] ;
41
+ var layoutIn = { annotations : annotations } ;
42
+ var out = _supply ( layoutIn ) ;
43
+
44
+ expect ( layoutIn . annotations ) . toEqual ( annotations ) ;
45
+
46
+ out . forEach ( function ( item , i ) {
47
+ expect ( item ) . toEqual ( {
48
+ visible : false ,
49
+ _input : { } ,
50
+ _index : i
51
+ } ) ;
52
+ } ) ;
53
+ } ) ;
54
+
17
55
it ( 'should default to pixel for axref/ayref' , function ( ) {
18
- var annotationDefaults = { } ;
19
- annotationDefaults . _has = Plots . _hasPlotType . bind ( annotationDefaults ) ;
56
+ var layoutIn = {
57
+ annotations : [ { showarrow : true , arrowhead : 2 } ]
58
+ } ;
20
59
21
- Annotations . supplyLayoutDefaults ( { annotations : [ { showarrow : true , arrowhead : 2 } ] } , annotationDefaults ) ;
60
+ var out = _supply ( layoutIn ) ;
22
61
23
- expect ( annotationDefaults . annotations [ 0 ] . axref ) . toEqual ( 'pixel' ) ;
24
- expect ( annotationDefaults . annotations [ 0 ] . ayref ) . toEqual ( 'pixel' ) ;
62
+ expect ( out [ 0 ] . axref ) . toEqual ( 'pixel' ) ;
63
+ expect ( out [ 0 ] . ayref ) . toEqual ( 'pixel' ) ;
25
64
} ) ;
26
65
27
66
it ( 'should convert ax/ay date coordinates to milliseconds if tail is in axis terms and axis is a date' , function ( ) {
28
- var annotationOut = { xaxis : { type : 'date' , range : [ '2000-01-01' , '2016-01-01' ] } } ;
29
- annotationOut . _has = Plots . _hasPlotType . bind ( annotationOut ) ;
67
+ var layoutIn = {
68
+ annotations : [ {
69
+ showarrow : true ,
70
+ axref : 'x' ,
71
+ ayref : 'y' ,
72
+ x : '2008-07-01' ,
73
+ ax : '2004-07-01' ,
74
+ y : 0 ,
75
+ ay : 50
76
+ } ]
77
+ } ;
30
78
31
- var annotationIn = {
32
- annotations : [ { showarrow : true , axref : 'x ', ayref : 'y' , x : '2008-07 -01', ax : '2004-07 -01', y : 0 , ay : 50 } ]
79
+ var layoutOut = {
80
+ xaxis : { type : 'date ', range : [ '2000-01 -01', '2016-01 -01'] }
33
81
} ;
34
82
35
- Annotations . supplyLayoutDefaults ( annotationIn , annotationOut ) ;
83
+ _supply ( layoutIn , layoutOut ) ;
36
84
37
- expect ( annotationIn . annotations [ 0 ] . ax ) . toEqual ( Dates . dateTime2ms ( '2004-07-01' ) ) ;
85
+ expect ( layoutIn . annotations [ 0 ] . ax ) . toEqual ( Dates . dateTime2ms ( '2004-07-01' ) ) ;
38
86
} ) ;
39
87
} ) ;
40
88
} ) ;
0 commit comments