@@ -1317,4 +1317,191 @@ describe('Time scale tests', function() {
1317
1317
} ) ;
1318
1318
} ) ;
1319
1319
} ) ;
1320
+
1321
+ describe ( 'when ticks.reverse' , function ( ) {
1322
+ describe ( 'is "true"' , function ( ) {
1323
+ it ( 'should reverse the labels' , function ( ) {
1324
+ this . chart = window . acquireChart ( {
1325
+ type : 'line' ,
1326
+ data : {
1327
+ labels : [ '2017' , '2019' , '2020' , '2025' , '2042' ] ,
1328
+ datasets : [ { data : [ 0 , 1 , 2 , 3 , 4 , 5 ] } ]
1329
+ } ,
1330
+ options : {
1331
+ scales : {
1332
+ xAxes : [ {
1333
+ id : 'x' ,
1334
+ type : 'time' ,
1335
+ time : {
1336
+ parser : 'YYYY' ,
1337
+ } ,
1338
+ ticks : {
1339
+ source : 'labels' ,
1340
+ reverse : true
1341
+ }
1342
+ } ] ,
1343
+ yAxes : [ {
1344
+ display : false
1345
+ } ]
1346
+ }
1347
+ }
1348
+ } ) ;
1349
+ var scale = this . chart . scales . x ;
1350
+ expect ( scale . getPixelForValue ( '2017' ) ) . toBeCloseToPixel ( scale . left + scale . width ) ;
1351
+ expect ( scale . getPixelForValue ( '2042' ) ) . toBeCloseToPixel ( scale . left ) ;
1352
+ } ) ;
1353
+ } ) ;
1354
+ } ) ;
1355
+
1356
+ describe ( 'when ticks.reverse is "true" and distribution' , function ( ) {
1357
+ describe ( 'is "series"' , function ( ) {
1358
+ beforeEach ( function ( ) {
1359
+ this . chart = window . acquireChart ( {
1360
+ type : 'line' ,
1361
+ data : {
1362
+ labels : [ '2017' , '2019' , '2020' , '2025' , '2042' ] ,
1363
+ datasets : [ { data : [ 0 , 1 , 2 , 3 , 4 , 5 ] } ]
1364
+ } ,
1365
+ options : {
1366
+ scales : {
1367
+ xAxes : [ {
1368
+ id : 'x' ,
1369
+ type : 'time' ,
1370
+ time : {
1371
+ parser : 'YYYY'
1372
+ } ,
1373
+ distribution : 'series' ,
1374
+ ticks : {
1375
+ source : 'labels' ,
1376
+ reverse : true
1377
+ }
1378
+ } ] ,
1379
+ yAxes : [ {
1380
+ display : false
1381
+ } ]
1382
+ }
1383
+ }
1384
+ } ) ;
1385
+ } ) ;
1386
+
1387
+ it ( 'should reverse the labels and space data out with the same gap, whatever their time values' , function ( ) {
1388
+ var scale = this . chart . scales . x ;
1389
+ var start = scale . left ;
1390
+ var slice = scale . width / 4 ;
1391
+
1392
+ expect ( scale . getPixelForValue ( '2017' ) ) . toBeCloseToPixel ( start + slice * 4 ) ;
1393
+ expect ( scale . getPixelForValue ( '2019' ) ) . toBeCloseToPixel ( start + slice * 3 ) ;
1394
+ expect ( scale . getPixelForValue ( '2020' ) ) . toBeCloseToPixel ( start + slice * 2 ) ;
1395
+ expect ( scale . getPixelForValue ( '2025' ) ) . toBeCloseToPixel ( start + slice ) ;
1396
+ expect ( scale . getPixelForValue ( '2042' ) ) . toBeCloseToPixel ( start ) ;
1397
+ } ) ;
1398
+
1399
+ it ( 'should reverse the labels and should add a step before if scale.min is before the first data' , function ( ) {
1400
+ var chart = this . chart ;
1401
+ var scale = chart . scales . x ;
1402
+ var options = chart . options . scales . xAxes [ 0 ] ;
1403
+
1404
+ options . time . min = '2012' ;
1405
+ chart . update ( ) ;
1406
+
1407
+ var start = scale . left ;
1408
+ var slice = scale . width / 5 ;
1409
+
1410
+ expect ( scale . getPixelForValue ( '2017' ) ) . toBeCloseToPixel ( start + slice * 4 ) ;
1411
+ expect ( scale . getPixelForValue ( '2042' ) ) . toBeCloseToPixel ( start ) ;
1412
+ } ) ;
1413
+
1414
+ it ( 'should reverse the labels and should add a step after if scale.max is after the last data' , function ( ) {
1415
+ var chart = this . chart ;
1416
+ var scale = chart . scales . x ;
1417
+ var options = chart . options . scales . xAxes [ 0 ] ;
1418
+
1419
+ options . time . max = '2050' ;
1420
+ chart . update ( ) ;
1421
+
1422
+ var start = scale . left ;
1423
+ var slice = scale . width / 5 ;
1424
+
1425
+ expect ( scale . getPixelForValue ( '2017' ) ) . toBeCloseToPixel ( start + slice * 5 ) ;
1426
+ expect ( scale . getPixelForValue ( '2042' ) ) . toBeCloseToPixel ( start + slice ) ;
1427
+ } ) ;
1428
+
1429
+ it ( 'should reverse the labels and should add steps before and after if scale.min/max are outside the data range' , function ( ) {
1430
+ var chart = this . chart ;
1431
+ var scale = chart . scales . x ;
1432
+ var options = chart . options . scales . xAxes [ 0 ] ;
1433
+
1434
+ options . time . min = '2012' ;
1435
+ options . time . max = '2050' ;
1436
+ chart . update ( ) ;
1437
+
1438
+ var start = scale . left ;
1439
+ var slice = scale . width / 6 ;
1440
+
1441
+ expect ( scale . getPixelForValue ( '2017' ) ) . toBeCloseToPixel ( start + slice * 5 ) ;
1442
+ expect ( scale . getPixelForValue ( '2042' ) ) . toBeCloseToPixel ( start + slice ) ;
1443
+ } ) ;
1444
+ } ) ;
1445
+ describe ( 'is "linear"' , function ( ) {
1446
+ beforeEach ( function ( ) {
1447
+ this . chart = window . acquireChart ( {
1448
+ type : 'line' ,
1449
+ data : {
1450
+ labels : [ '2017' , '2019' , '2020' , '2025' , '2042' ] ,
1451
+ datasets : [ { data : [ 0 , 1 , 2 , 3 , 4 , 5 ] } ]
1452
+ } ,
1453
+ options : {
1454
+ scales : {
1455
+ xAxes : [ {
1456
+ id : 'x' ,
1457
+ type : 'time' ,
1458
+ time : {
1459
+ parser : 'YYYY'
1460
+ } ,
1461
+ distribution : 'linear' ,
1462
+ ticks : {
1463
+ source : 'labels' ,
1464
+ reverse : true
1465
+ }
1466
+ } ] ,
1467
+ yAxes : [ {
1468
+ display : false
1469
+ } ]
1470
+ }
1471
+ }
1472
+ } ) ;
1473
+ } ) ;
1474
+
1475
+ it ( 'should reverse the labels and should space data out with a gap relative to their time values' , function ( ) {
1476
+ var scale = this . chart . scales . x ;
1477
+ var start = scale . left ;
1478
+ var slice = scale . width / ( 2042 - 2017 ) ;
1479
+
1480
+ expect ( scale . getPixelForValue ( '2017' ) ) . toBeCloseToPixel ( start + slice * ( 2042 - 2017 ) ) ;
1481
+ expect ( scale . getPixelForValue ( '2019' ) ) . toBeCloseToPixel ( start + slice * ( 2042 - 2019 ) ) ;
1482
+ expect ( scale . getPixelForValue ( '2020' ) ) . toBeCloseToPixel ( start + slice * ( 2042 - 2020 ) ) ;
1483
+ expect ( scale . getPixelForValue ( '2025' ) ) . toBeCloseToPixel ( start + slice * ( 2042 - 2025 ) ) ;
1484
+ expect ( scale . getPixelForValue ( '2042' ) ) . toBeCloseToPixel ( start ) ;
1485
+ } ) ;
1486
+
1487
+ it ( 'should reverse the labels and should take in account scale min and max if outside the ticks range' , function ( ) {
1488
+ var chart = this . chart ;
1489
+ var scale = chart . scales . x ;
1490
+ var options = chart . options . scales . xAxes [ 0 ] ;
1491
+
1492
+ options . time . min = '2012' ;
1493
+ options . time . max = '2050' ;
1494
+ chart . update ( ) ;
1495
+
1496
+ var start = scale . left ;
1497
+ var slice = scale . width / ( 2050 - 2012 ) ;
1498
+
1499
+ expect ( scale . getPixelForValue ( '2017' ) ) . toBeCloseToPixel ( start + slice * ( 2050 - 2017 ) ) ;
1500
+ expect ( scale . getPixelForValue ( '2019' ) ) . toBeCloseToPixel ( start + slice * ( 2050 - 2019 ) ) ;
1501
+ expect ( scale . getPixelForValue ( '2020' ) ) . toBeCloseToPixel ( start + slice * ( 2050 - 2020 ) ) ;
1502
+ expect ( scale . getPixelForValue ( '2025' ) ) . toBeCloseToPixel ( start + slice * ( 2050 - 2025 ) ) ;
1503
+ expect ( scale . getPixelForValue ( '2042' ) ) . toBeCloseToPixel ( start + slice * ( 2050 - 2042 ) ) ;
1504
+ } ) ;
1505
+ } ) ;
1506
+ } ) ;
1320
1507
} ) ;
0 commit comments