@@ -79,16 +79,23 @@ describe('Plots.computeAPICommandBindings', function() {
79
79
} ) ;
80
80
81
81
describe ( 'restyle' , function ( ) {
82
- describe ( 'astr + val notation' , function ( ) {
83
- describe ( 'with a single attribute' , function ( ) {
82
+ describe ( 'with invalid notation' , function ( ) {
83
+ it ( 'with a scalar value' , function ( ) {
84
+ var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ [ 'x' ] ] ) ;
85
+ expect ( result ) . toEqual ( [ ] ) ;
86
+ } ) ;
87
+ } ) ;
88
+
89
+ describe ( 'with astr + val notation' , function ( ) {
90
+ describe ( 'and a single attribute' , function ( ) {
84
91
it ( 'with a scalar value' , function ( ) {
85
92
var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ 'marker.size' , 7 ] ) ;
86
93
expect ( result ) . toEqual ( [ 'data[0].marker.size' , 'data[1].marker.size' ] ) ;
87
94
} ) ;
88
95
89
96
it ( 'with an array value and no trace specified' , function ( ) {
90
97
var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ 'marker.size' , [ 7 ] ] ) ;
91
- expect ( result ) . toEqual ( [ 'data[0].marker.size' , 'data[1].marker.size' ] ) ;
98
+ expect ( result ) . toEqual ( [ 'data[0].marker.size' ] ) ;
92
99
} ) ;
93
100
94
101
it ( 'with trace specified' , function ( ) {
@@ -97,12 +104,12 @@ describe('Plots.computeAPICommandBindings', function() {
97
104
} ) ;
98
105
99
106
it ( 'with a different trace specified' , function ( ) {
100
- var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ 'marker.size' , 7 , [ 1 ] ] ) ;
101
- expect ( result ) . toEqual ( [ 'data[1 ].marker.size' ] ) ;
107
+ var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ 'marker.size' , 7 , [ 0 ] ] ) ;
108
+ expect ( result ) . toEqual ( [ 'data[0 ].marker.size' ] ) ;
102
109
} ) ;
103
110
104
111
it ( 'with an array value' , function ( ) {
105
- var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ 'marker.size' , [ 7 ] , [ 0 ] ] ) ;
112
+ var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ 'marker.size' , [ 7 ] , [ 1 ] ] ) ;
106
113
expect ( result ) . toEqual ( [ 'data[1].marker.size' ] ) ;
107
114
} ) ;
108
115
@@ -128,8 +135,8 @@ describe('Plots.computeAPICommandBindings', function() {
128
135
} ) ;
129
136
} ) ;
130
137
131
- describe ( 'aobj notation' , function ( ) {
132
- describe ( 'with a single attribute' , function ( ) {
138
+ describe ( 'with aobj notation' , function ( ) {
139
+ describe ( 'and a single attribute' , function ( ) {
133
140
it ( 'with a scalar value' , function ( ) {
134
141
var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ { 'marker.size' : 7 } ] ) ;
135
142
expect ( result ) . toEqual ( [ 'data[0].marker.size' , 'data[1].marker.size' ] ) ;
@@ -146,7 +153,7 @@ describe('Plots.computeAPICommandBindings', function() {
146
153
} ) ;
147
154
148
155
it ( 'with an array value' , function ( ) {
149
- var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ { 'marker.size' : [ 7 ] } , [ 0 ] ] ) ;
156
+ var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ { 'marker.size' : [ 7 ] } , [ 1 ] ] ) ;
150
157
expect ( result ) . toEqual ( [ 'data[1].marker.size' ] ) ;
151
158
} ) ;
152
159
@@ -171,12 +178,123 @@ describe('Plots.computeAPICommandBindings', function() {
171
178
} ) ;
172
179
} ) ;
173
180
174
- describe ( 'with multiple attributes' , function ( ) {
181
+ describe ( 'and multiple attributes' , function ( ) {
175
182
it ( 'with a scalar value' , function ( ) {
176
183
var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ { 'marker.size' : 7 , 'text.color' : 'blue' } ] ) ;
177
184
expect ( result ) . toEqual ( [ 'data[0].marker.size' , 'data[1].marker.size' , 'data[0].text.color' , 'data[1].text.color' ] ) ;
178
185
} ) ;
179
186
} ) ;
180
187
} ) ;
188
+
189
+ describe ( 'with mixed notation' , function ( ) {
190
+ it ( 'and nested object and nested attr' , function ( ) {
191
+ var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ {
192
+ y : [ [ 3 , 4 , 5 ] ] ,
193
+ 'marker.size' : [ 10 , 20 , 25 ] ,
194
+ 'line.color' : 'red' ,
195
+ line : {
196
+ width : [ 2 , 8 ]
197
+ }
198
+ } ] ) ;
199
+
200
+ // The results are definitely not completely intuitive, so this
201
+ // is based upon empirical results with a codepen example:
202
+ expect ( result ) . toEqual ( [
203
+ 'data[0].y' ,
204
+ 'data[0].marker.size' ,
205
+ 'data[1].marker.size' ,
206
+ 'data[0].line.color' ,
207
+ 'data[1].line.color' ,
208
+ 'data[0].line.width' ,
209
+ 'data[1].line.width' ,
210
+ ] ) ;
211
+ } ) ;
212
+
213
+ it ( 'and traces specified' , function ( ) {
214
+ var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ {
215
+ y : [ [ 3 , 4 , 5 ] ] ,
216
+ 'marker.size' : [ 10 , 20 , 25 ] ,
217
+ 'line.color' : 'red' ,
218
+ line : {
219
+ width : [ 2 , 8 ]
220
+ }
221
+ } , [ 1 , 0 ] ] ) ;
222
+
223
+ // The results are definitely not completely intuitive, so this
224
+ // is based upon empirical results with a codepen example:
225
+ expect ( result ) . toEqual ( [
226
+ 'data[1].y' ,
227
+ 'data[1].marker.size' ,
228
+ 'data[0].marker.size' ,
229
+ 'data[1].line.color' ,
230
+ 'data[0].line.color' ,
231
+ 'data[1].line.width' ,
232
+ 'data[0].line.width' ,
233
+ ] ) ;
234
+ } ) ;
235
+
236
+ it ( 'and more data than traces' , function ( ) {
237
+ var result = Plots . computeAPICommandBindings ( gd , 'restyle' , [ {
238
+ y : [ [ 3 , 4 , 5 ] ] ,
239
+ 'marker.size' : [ 10 , 20 , 25 ] ,
240
+ 'line.color' : 'red' ,
241
+ line : {
242
+ width : [ 2 , 8 ]
243
+ }
244
+ } , [ 1 ] ] ) ;
245
+
246
+ // The results are definitely not completely intuitive, so this
247
+ // is based upon empirical results with a codepen example:
248
+ expect ( result ) . toEqual ( [
249
+ 'data[1].y' ,
250
+ 'data[1].marker.size' ,
251
+ 'data[1].line.color' ,
252
+ 'data[1].line.width' ,
253
+ ] ) ;
254
+ } ) ;
255
+ } ) ;
256
+ } ) ;
257
+
258
+ describe ( 'relayout' , function ( ) {
259
+ describe ( 'with invalid notation' , function ( ) {
260
+ it ( 'and a scalar value' , function ( ) {
261
+ var result = Plots . computeAPICommandBindings ( gd , 'relayout' , [ [ 'x' ] ] ) ;
262
+ expect ( result ) . toEqual ( [ ] ) ;
263
+ } ) ;
264
+ } ) ;
265
+
266
+ describe ( 'with aobj notation' , function ( ) {
267
+ it ( 'and a single attribute' , function ( ) {
268
+ var result = Plots . computeAPICommandBindings ( gd , 'relayout' , [ { height : 500 } ] ) ;
269
+ expect ( result ) . toEqual ( [ 'layout.height' ] ) ;
270
+ } ) ;
271
+
272
+ it ( 'and two attributes' , function ( ) {
273
+ var result = Plots . computeAPICommandBindings ( gd , 'relayout' , [ { height : 500 , width : 100 } ] ) ;
274
+ expect ( result ) . toEqual ( [ 'layout.height' , 'layout.width' ] ) ;
275
+ } ) ;
276
+ } ) ;
277
+
278
+ describe ( 'with astr + val notation' , function ( ) {
279
+ it ( 'and an attribute' , function ( ) {
280
+ var result = Plots . computeAPICommandBindings ( gd , 'relayout' , [ 'width' , 100 ] ) ;
281
+ expect ( result ) . toEqual ( [ 'layout.width' ] ) ;
282
+ } ) ;
283
+
284
+ it ( 'and nested atributes' , function ( ) {
285
+ var result = Plots . computeAPICommandBindings ( gd , 'relayout' , [ 'margin.l' , 10 ] ) ;
286
+ expect ( result ) . toEqual ( [ 'layout.margin.l' ] ) ;
287
+ } ) ;
288
+ } ) ;
289
+
290
+ describe ( 'with mixed notation' , function ( ) {
291
+ it ( 'containing aob + astr' , function ( ) {
292
+ var result = Plots . computeAPICommandBindings ( gd , 'relayout' , [ {
293
+ 'width' : 100 ,
294
+ 'margin.l' : 10
295
+ } ] ) ;
296
+ expect ( result ) . toEqual ( [ 'layout.width' , 'layout.margin.l' ] ) ;
297
+ } ) ;
298
+ } ) ;
181
299
} ) ;
182
300
} ) ;
0 commit comments