@@ -48,6 +48,40 @@ describe('Test plot api', function() {
48
48
} )
49
49
. then ( done ) ;
50
50
} ) ;
51
+
52
+ it ( 'sets null values to their default' , function ( done ) {
53
+ var defaultWidth ;
54
+ Plotly . plot ( gd , [ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] } ] )
55
+ . then ( function ( ) {
56
+ defaultWidth = gd . _fullLayout . width ;
57
+ return Plotly . relayout ( gd , { width : defaultWidth - 25 } ) ;
58
+ } )
59
+ . then ( function ( ) {
60
+ expect ( gd . _fullLayout . width ) . toBe ( defaultWidth - 25 ) ;
61
+ return Plotly . relayout ( gd , { width : null } ) ;
62
+ } )
63
+ . then ( function ( ) {
64
+ expect ( gd . _fullLayout . width ) . toBe ( defaultWidth ) ;
65
+ } )
66
+ . then ( done ) ;
67
+ } ) ;
68
+
69
+ it ( 'ignores undefined values' , function ( done ) {
70
+ var defaultWidth ;
71
+ Plotly . plot ( gd , [ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] } ] )
72
+ . then ( function ( ) {
73
+ defaultWidth = gd . _fullLayout . width ;
74
+ return Plotly . relayout ( gd , { width : defaultWidth - 25 } ) ;
75
+ } )
76
+ . then ( function ( ) {
77
+ expect ( gd . _fullLayout . width ) . toBe ( defaultWidth - 25 ) ;
78
+ return Plotly . relayout ( gd , { width : undefined } ) ;
79
+ } )
80
+ . then ( function ( ) {
81
+ expect ( gd . _fullLayout . width ) . toBe ( defaultWidth - 25 ) ;
82
+ } )
83
+ . then ( done ) ;
84
+ } ) ;
51
85
} ) ;
52
86
53
87
describe ( 'Plotly.restyle' , function ( ) {
@@ -96,6 +130,64 @@ describe('Test plot api', function() {
96
130
expect ( gd . calcdata ) . toBeDefined ( ) ;
97
131
} ) ;
98
132
133
+ it ( 'ignores undefined values' , function ( ) {
134
+ var gd = {
135
+ data : [ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] , type : 'scatter' } ] ,
136
+ layout : { }
137
+ } ;
138
+
139
+ mockDefaultsAndCalc ( gd ) ;
140
+
141
+ // Check to see that the color is updated:
142
+ Plotly . restyle ( gd , { 'marker.color' : 'blue' } ) ;
143
+ expect ( gd . _fullData [ 0 ] . marker . color ) . toBe ( 'blue' ) ;
144
+
145
+ // Check to see that the color is unaffected:
146
+ Plotly . restyle ( gd , { 'marker.color' : undefined } ) ;
147
+ expect ( gd . _fullData [ 0 ] . marker . color ) . toBe ( 'blue' ) ;
148
+ } ) ;
149
+
150
+ it ( 'restores null values to defaults' , function ( ) {
151
+ var gd = {
152
+ data : [ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] , type : 'scatter' } ] ,
153
+ layout : { }
154
+ } ;
155
+
156
+ mockDefaultsAndCalc ( gd ) ;
157
+ var colorDflt = gd . _fullData [ 0 ] . marker . color ;
158
+
159
+ // Check to see that the color is updated:
160
+ Plotly . restyle ( gd , { 'marker.color' : 'blue' } ) ;
161
+ expect ( gd . _fullData [ 0 ] . marker . color ) . toBe ( 'blue' ) ;
162
+
163
+ // Check to see that the color is restored to the original default:
164
+ Plotly . restyle ( gd , { 'marker.color' : null } ) ;
165
+ expect ( gd . _fullData [ 0 ] . marker . color ) . toBe ( colorDflt ) ;
166
+ } ) ;
167
+
168
+ it ( 'can target specific traces by leaving properties undefined' , function ( ) {
169
+ var gd = {
170
+ data : [
171
+ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] , type : 'scatter' } ,
172
+ { x : [ 1 , 2 , 3 ] , y : [ 3 , 4 , 5 ] , type : 'scatter' }
173
+ ] ,
174
+ layout : { }
175
+ } ;
176
+
177
+ mockDefaultsAndCalc ( gd ) ;
178
+ var colorDflt = [ gd . _fullData [ 0 ] . marker . color , gd . _fullData [ 1 ] . marker . color ] ;
179
+
180
+ // Check only second trace's color has been changed:
181
+ Plotly . restyle ( gd , { 'marker.color' : [ undefined , 'green' ] } ) ;
182
+ expect ( gd . _fullData [ 0 ] . marker . color ) . toBe ( colorDflt [ 0 ] ) ;
183
+ expect ( gd . _fullData [ 1 ] . marker . color ) . toBe ( 'green' ) ;
184
+
185
+ // Check both colors restored to the original default:
186
+ Plotly . restyle ( gd , { 'marker.color' : [ null , null ] } ) ;
187
+ expect ( gd . _fullData [ 0 ] . marker . color ) . toBe ( colorDflt [ 0 ] ) ;
188
+ expect ( gd . _fullData [ 1 ] . marker . color ) . toBe ( colorDflt [ 1 ] ) ;
189
+ } ) ;
190
+
99
191
} ) ;
100
192
101
193
describe ( 'Plotly.deleteTraces' , function ( ) {
0 commit comments