@@ -1135,6 +1135,99 @@ describe('Test axes', function() {
11351135 expect ( layoutOut . xaxis2 . rangebreaks [ 0 ] . pattern ) . toBe ( 'day of week' , 'coerced' ) ;
11361136 expect ( layoutOut . xaxis3 . rangebreaks [ 0 ] . pattern ) . toBe ( undefined , 'not coerce, using *values*' ) ;
11371137 } ) ;
1138+
1139+ it ( 'should auto default rangebreaks.pattern to *day of week* when *bounds* include a weekday string and convert bounds to integer days' , function ( ) {
1140+ layoutIn = {
1141+ xaxis : { type : 'date' , rangebreaks : [
1142+ { bounds : [ 'Saturday' , 'Monday' ] }
1143+ ] } ,
1144+ xaxis2 : { type : 'date' , rangebreaks : [
1145+ { bounds : [ 'sun' , 'thu' ] } ,
1146+ { bounds : [ 'mon' , 'fri' ] } ,
1147+ { bounds : [ 'tue' , 'sat' ] } ,
1148+ { bounds : [ 'wed' , '-1' ] }
1149+ ] }
1150+ } ;
1151+ layoutOut . _subplots . xaxis . push ( 'x2' ) ;
1152+ supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
1153+
1154+ expect ( layoutOut . xaxis . rangebreaks [ 0 ] . pattern ) . toBe ( 'day of week' , 'complete Capital' ) ;
1155+ expect ( layoutOut . xaxis2 . rangebreaks [ 0 ] . pattern ) . toBe ( 'day of week' , '3-letter case' ) ;
1156+ expect ( layoutOut . xaxis2 . rangebreaks [ 0 ] . bounds [ 0 ] ) . toBe ( 0 , 'convert sun' ) ;
1157+ expect ( layoutOut . xaxis2 . rangebreaks [ 1 ] . bounds [ 0 ] ) . toBe ( 1 , 'convert mon' ) ;
1158+ expect ( layoutOut . xaxis2 . rangebreaks [ 2 ] . bounds [ 0 ] ) . toBe ( 2 , 'convert tue' ) ;
1159+ expect ( layoutOut . xaxis2 . rangebreaks [ 3 ] . bounds [ 0 ] ) . toBe ( 3 , 'convert wed' ) ;
1160+ expect ( layoutOut . xaxis2 . rangebreaks [ 0 ] . bounds [ 1 ] ) . toBe ( 4 , 'convert thu' ) ;
1161+ expect ( layoutOut . xaxis2 . rangebreaks [ 1 ] . bounds [ 1 ] ) . toBe ( 5 , 'convert fri' ) ;
1162+ expect ( layoutOut . xaxis2 . rangebreaks [ 2 ] . bounds [ 1 ] ) . toBe ( 6 , 'convert sat' ) ;
1163+ expect ( layoutOut . xaxis2 . rangebreaks [ 3 ] . bounds [ 1 ] ) . toBe ( '-1' , 'string' ) ;
1164+ } ) ;
1165+
1166+ it ( 'should validate inputs in respect to *day of week* pattern' , function ( ) {
1167+ layoutIn = {
1168+ xaxis : { type : 'date' , rangebreaks : [ { pattern : 'day of week' , bounds : [ '6' , '0' ] } ] } ,
1169+ xaxis2 : { type : 'date' , rangebreaks : [ { bounds : [ 'Sunday' ] } ] } ,
1170+ xaxis3 : { type : 'date' , rangebreaks : [ { bounds : [ 'sun' , 'mon' , 'tue' ] } ] } ,
1171+ xaxis4 : { type : 'date' , rangebreaks : [ { pattern : 'day of week' , bounds : [ 1 , '-1' ] } ] } ,
1172+ xaxis5 : { type : 'date' , rangebreaks : [ { pattern : 'day of week' , bounds : [ 1 , '-.25' ] } ] } ,
1173+ xaxis6 : { type : 'date' , rangebreaks : [ { pattern : 'day of week' , bounds : [ 1 , '7' ] } ] } ,
1174+ xaxis7 : { type : 'date' , rangebreaks : [ { pattern : 'day of week' , bounds : [ 1 , '6.75' ] } ] } ,
1175+ xaxis8 : { type : 'date' , rangebreaks : [ { pattern : 'day of week' , bounds : [ 1 , '' ] } ] } ,
1176+ xaxis9 : { type : 'date' , rangebreaks : [ { pattern : 'day of week' , bounds : [ 1 , null ] } ] } ,
1177+ xaxis10 : { type : 'date' , rangebreaks : [ { pattern : 'day of week' , bounds : [ 1 , false ] } ] } ,
1178+ xaxis11 : { type : 'date' , rangebreaks : [ { pattern : 'day of week' , bounds : [ 1 , true ] } ] }
1179+ } ;
1180+ layoutOut . _subplots . xaxis . push ( 'x2' , 'x3' , 'x4' , 'x5' , 'x6' , 'x7' , 'x8' , 'x9' , 'x10' , 'x11' ) ;
1181+ supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
1182+
1183+ expect ( layoutOut . xaxis . rangebreaks [ 0 ] . enabled ) . toBe ( true , 'valid' ) ;
1184+ expect ( layoutOut . xaxis . rangebreaks [ 0 ] . bounds [ 0 ] ) . toBe ( 6 , 'cast float to int' ) ;
1185+ expect ( layoutOut . xaxis . rangebreaks [ 0 ] . bounds [ 1 ] ) . toBe ( 0 , 'cast string to int' ) ;
1186+ expect ( layoutOut . xaxis2 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject bounds.length < 2' ) ;
1187+ expect ( layoutOut . xaxis3 . rangebreaks [ 0 ] . enabled ) . toBe ( true , 'do not reject bounds.length > 2' ) ;
1188+ expect ( layoutOut . xaxis3 . rangebreaks [ 0 ] . bounds . length ) . toBe ( 2 , 'pick first two' ) ;
1189+ expect ( layoutOut . xaxis4 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject bound < 0' ) ;
1190+ expect ( layoutOut . xaxis5 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject bound < 0' ) ;
1191+ expect ( layoutOut . xaxis6 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject bound >= 7' ) ;
1192+ expect ( layoutOut . xaxis7 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject bound < 7 - not supported yet' ) ;
1193+ expect ( layoutOut . xaxis8 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject blank string' ) ;
1194+ expect ( layoutOut . xaxis9 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject null' ) ;
1195+ expect ( layoutOut . xaxis10 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject false' ) ;
1196+ expect ( layoutOut . xaxis11 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject true' ) ;
1197+ } ) ;
1198+
1199+ it ( 'should validate inputs in respect to *hour* pattern' , function ( ) {
1200+ layoutIn = {
1201+ xaxis : { type : 'date' , rangebreaks : [ { pattern : 'hour' , bounds : [ '24' , '1e-3' ] } ] } ,
1202+ xaxis2 : { type : 'date' , rangebreaks : [ { pattern : 'hour' , bounds : [ 1 ] } ] } ,
1203+ xaxis3 : { type : 'date' , rangebreaks : [ { pattern : 'hour' , bounds : [ 1 , 2 , 3 ] } ] } ,
1204+ xaxis4 : { type : 'date' , rangebreaks : [ { pattern : 'hour' , bounds : [ 1 , '-1' ] } ] } ,
1205+ xaxis5 : { type : 'date' , rangebreaks : [ { pattern : 'hour' , bounds : [ 1 , '-.001' ] } ] } ,
1206+ xaxis6 : { type : 'date' , rangebreaks : [ { pattern : 'hour' , bounds : [ 1 , '24.001' ] } ] } ,
1207+ xaxis7 : { type : 'date' , rangebreaks : [ { pattern : 'hour' , bounds : [ 1 , '23.999' ] } ] } ,
1208+ xaxis8 : { type : 'date' , rangebreaks : [ { pattern : 'day of week' , bounds : [ 1 , '' ] } ] } ,
1209+ xaxis9 : { type : 'date' , rangebreaks : [ { pattern : 'day of week' , bounds : [ 1 , null ] } ] } ,
1210+ xaxis10 : { type : 'date' , rangebreaks : [ { pattern : 'day of week' , bounds : [ 1 , false ] } ] } ,
1211+ xaxis11 : { type : 'date' , rangebreaks : [ { pattern : 'day of week' , bounds : [ 1 , true ] } ] }
1212+ } ;
1213+ layoutOut . _subplots . xaxis . push ( 'x2' , 'x3' , 'x4' , 'x5' , 'x6' , 'x7' , 'x8' , 'x9' , 'x10' , 'x11' ) ;
1214+ supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
1215+
1216+ expect ( layoutOut . xaxis . rangebreaks [ 0 ] . enabled ) . toBe ( true , 'valid' ) ;
1217+ expect ( layoutOut . xaxis . rangebreaks [ 0 ] . bounds [ 0 ] ) . toBe ( 24 , 'accept 24' ) ;
1218+ expect ( layoutOut . xaxis . rangebreaks [ 0 ] . bounds [ 1 ] ) . toBe ( 0.001 , 'cast string to float' ) ;
1219+ expect ( layoutOut . xaxis2 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject bounds.length < 2' ) ;
1220+ expect ( layoutOut . xaxis3 . rangebreaks [ 0 ] . enabled ) . toBe ( true , 'do not reject bounds.length > 2' ) ;
1221+ expect ( layoutOut . xaxis3 . rangebreaks [ 0 ] . bounds . length ) . toBe ( 2 , 'pick first two' ) ;
1222+ expect ( layoutOut . xaxis4 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject bound < 0' ) ;
1223+ expect ( layoutOut . xaxis5 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject bound < 0' ) ;
1224+ expect ( layoutOut . xaxis6 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject bound > 24' ) ;
1225+ expect ( layoutOut . xaxis7 . rangebreaks [ 0 ] . enabled ) . toBe ( true , 'do not reject bound <= 24' ) ;
1226+ expect ( layoutOut . xaxis8 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject blank string' ) ;
1227+ expect ( layoutOut . xaxis9 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject null' ) ;
1228+ expect ( layoutOut . xaxis10 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject false' ) ;
1229+ expect ( layoutOut . xaxis11 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject true' ) ;
1230+ } ) ;
11381231 } ) ;
11391232
11401233 describe ( 'constraints relayout' , function ( ) {
0 commit comments