@@ -96,6 +96,64 @@ describe('Test plot api', function() {
96
96
expect ( gd . calcdata ) . toBeDefined ( ) ;
97
97
} ) ;
98
98
99
+ it ( 'ignores undefined values' , function ( ) {
100
+ var gd = {
101
+ data : [ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] , type : 'scatter' } ] ,
102
+ layout : { }
103
+ } ;
104
+
105
+ mockDefaultsAndCalc ( gd ) ;
106
+
107
+ // Check to see that the color is updated:
108
+ Plotly . restyle ( gd , { 'marker.color' : 'blue' } ) ;
109
+ expect ( gd . _fullData [ 0 ] . marker . color ) . toBe ( 'blue' ) ;
110
+
111
+ // Check to see that the color is unaffected:
112
+ Plotly . restyle ( gd , { 'marker.color' : undefined } ) ;
113
+ expect ( gd . _fullData [ 0 ] . marker . color ) . toBe ( 'blue' ) ;
114
+ } ) ;
115
+
116
+ it ( 'restores null values to defaults' , function ( ) {
117
+ var gd = {
118
+ data : [ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] , type : 'scatter' } ] ,
119
+ layout : { }
120
+ } ;
121
+
122
+ mockDefaultsAndCalc ( gd ) ;
123
+ var colorDflt = gd . _fullData [ 0 ] . marker . color ;
124
+
125
+ // Check to see that the color is updated:
126
+ Plotly . restyle ( gd , { 'marker.color' : 'blue' } ) ;
127
+ expect ( gd . _fullData [ 0 ] . marker . color ) . toBe ( 'blue' ) ;
128
+
129
+ // Check to see that the color is restored to the original default:
130
+ Plotly . restyle ( gd , { 'marker.color' : null } ) ;
131
+ expect ( gd . _fullData [ 0 ] . marker . color ) . toBe ( colorDflt ) ;
132
+ } ) ;
133
+
134
+ it ( 'can target specific traces by leaving properties undefined' , function ( ) {
135
+ var gd = {
136
+ data : [
137
+ { x : [ 1 , 2 , 3 ] , y : [ 1 , 2 , 3 ] , type : 'scatter' } ,
138
+ { x : [ 1 , 2 , 3 ] , y : [ 3 , 4 , 5 ] , type : 'scatter' }
139
+ ] ,
140
+ layout : { }
141
+ } ;
142
+
143
+ mockDefaultsAndCalc ( gd ) ;
144
+ var colorDflt = [ gd . _fullData [ 0 ] . marker . color , gd . _fullData [ 1 ] . marker . color ] ;
145
+
146
+ // Check only second trace's color has been changed:
147
+ Plotly . restyle ( gd , { 'marker.color' : [ undefined , 'green' ] } ) ;
148
+ expect ( gd . _fullData [ 0 ] . marker . color ) . toBe ( colorDflt [ 0 ] ) ;
149
+ expect ( gd . _fullData [ 1 ] . marker . color ) . toBe ( 'green' ) ;
150
+
151
+ // Check both colors restored to the original default:
152
+ Plotly . restyle ( gd , { 'marker.color' : [ null , null ] } ) ;
153
+ expect ( gd . _fullData [ 0 ] . marker . color ) . toBe ( colorDflt [ 0 ] ) ;
154
+ expect ( gd . _fullData [ 1 ] . marker . color ) . toBe ( colorDflt [ 1 ] ) ;
155
+ } ) ;
156
+
99
157
} ) ;
100
158
101
159
describe ( 'Plotly.deleteTraces' , function ( ) {
0 commit comments