@@ -190,18 +190,76 @@ describe('Test axes', function() {
190190 } ) ;
191191
192192 describe ( 'autotype' , function ( ) {
193- function fullTrace ( mods ) {
194- return Lib . extendDeep (
193+ function supplyWithTrace ( trace ) {
194+ var fullTrace = Lib . extendDeep (
195195 { type : 'scatter' , xaxis : 'x' , yaxis : 'y' } ,
196- mods
196+ trace
197197 ) ;
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 ) ;
198205 }
206+
199207 it ( 'treats booleans as categories' , function ( ) {
200- fullData = [ fullTrace ( { x : [ 0 , 1 , 2 ] , y : [ true , false , true ] } ) ] ;
201- layoutIn = { xaxis : { } , yaxis : { } } ;
202- supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
203- expect ( layoutOut . xaxis . type ) . toBe ( 'linear' ) ;
204- expect ( layoutOut . yaxis . type ) . toBe ( 'category' ) ;
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' ) ;
205263 } ) ;
206264 } ) ;
207265
0 commit comments