@@ -189,6 +189,80 @@ describe('Test axes', function() {
189
189
fullData = [ ] ;
190
190
} ) ;
191
191
192
+ describe ( 'autotype' , function ( ) {
193
+ function supplyWithTrace ( trace ) {
194
+ var fullTrace = Lib . extendDeep (
195
+ { type : 'scatter' , xaxis : 'x' , yaxis : 'y' } ,
196
+ trace
197
+ ) ;
198
+ layoutIn = { xaxis : { } , yaxis : { } } ;
199
+ supplyLayoutDefaults ( layoutIn , layoutOut , [ fullTrace ] ) ;
200
+ }
201
+
202
+ function checkTypes ( xType , yType , msg ) {
203
+ expect ( layoutOut . xaxis . type ) . toBe ( xType , msg ) ;
204
+ expect ( layoutOut . yaxis . type ) . toBe ( yType , msg ) ;
205
+ }
206
+
207
+ it ( 'treats booleans as categories' , function ( ) {
208
+ supplyWithTrace ( { x : [ 0 , 1 , 2 ] , y : [ true , false , true ] } ) ;
209
+ checkTypes ( 'linear' , 'category' ) ;
210
+ } ) ;
211
+
212
+ it ( 'sees a single "None" or "" as a category' , function ( ) {
213
+ supplyWithTrace ( { x : [ 'None' ] , y : [ '' ] } ) ;
214
+ checkTypes ( 'category' , 'category' ) ;
215
+ } ) ;
216
+
217
+ it ( 'lets a single number beat up to two distinct categories' , function ( ) {
218
+ supplyWithTrace ( {
219
+ x : [ '2.1' , 'N/A' , '' , 'N/A' , '' , 'N/A' , 'N/A' , '' , '' , '' ] ,
220
+ y : [ 0 , 'None' , true , 'None' , 'None' , 'None' , 'None' , 'None' ]
221
+ } ) ;
222
+ checkTypes ( 'linear' , 'linear' ) ;
223
+ } ) ;
224
+
225
+ it ( 'turns back to category with >2 per distinct number' , function ( ) {
226
+ supplyWithTrace ( {
227
+ x : [ 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 'Yes' , 'No' , 'Maybe' ] ,
228
+ y : [ 1 , 2 , 1 , 2 , 1 , 2 , true , false , '' , 'None' , 'nan' ]
229
+ } ) ;
230
+ checkTypes ( 'category' , 'category' ) ;
231
+ } ) ;
232
+
233
+ it ( 'works with world calendars' , function ( ) {
234
+ // these are only valid dates in chinese
235
+ var intercalary = [ '1995-08i-01' , '1995-08i-29' , '1984-10i-15' ] ;
236
+ supplyWithTrace ( {
237
+ x : intercalary , xcalendar : 'chinese' ,
238
+ y : intercalary , ycalendar : 'gregorian'
239
+ } ) ;
240
+ checkTypes ( 'date' , 'category' ) ;
241
+ } ) ;
242
+
243
+ it ( 'requires >twice as many distinct dates as numbers' , function ( ) {
244
+ supplyWithTrace ( {
245
+ x : [ '2000-01-01' , '2000-01-02' , '2000-01-03' , 1 , 1.2 ] ,
246
+ y : [ '2000-01' , '2000-02' , '2000-03' , '2000-04' , 1.1 ]
247
+ } ) ;
248
+ checkTypes ( 'linear' , 'date' ) ;
249
+
250
+ supplyWithTrace ( {
251
+ x : [ '2000-01-01' , '2000-01-02' , '2000-01-03' , 1 , 1 ] ,
252
+ y : [ '2000-01' , '2000-01' , '2000-01' , '2000-01' , 1.1 ]
253
+ } ) ;
254
+ checkTypes ( 'date' , 'linear' ) ;
255
+ } ) ;
256
+
257
+ it ( 'counts ambiguous dates as both dates and numbers' , function ( ) {
258
+ supplyWithTrace ( {
259
+ x : [ '2000' , '2000-01' , '2000-02' ] , // 3 dates, 1 number
260
+ y : [ '2000' , '2001' , '2000-01' ] // 3 dates, 2 numbers
261
+ } ) ;
262
+ checkTypes ( 'date' , 'linear' ) ;
263
+ } ) ;
264
+ } ) ;
265
+
192
266
it ( 'should set undefined linewidth/linecolor if linewidth, linecolor or showline is not supplied' , function ( ) {
193
267
layoutIn = {
194
268
xaxis : { } ,
0 commit comments