@@ -564,6 +564,78 @@ describe('finance charts calc transforms:', function() {
564
564
32.87 , 33.5 , 33.37 , 33.37 , 33.37 , 33.62
565
565
] ) ;
566
566
} ) ;
567
+
568
+ it ( 'should use the smallest trace minimum x difference to convert *tickwidth* to data coords for all traces attached to a given x-axis' , function ( ) {
569
+ var trace0 = Lib . extendDeep ( { } , mock1 , {
570
+ type : 'ohlc' ,
571
+ tickwidth : 0.5
572
+ } ) ;
573
+
574
+ var trace1 = Lib . extendDeep ( { } , mock1 , {
575
+ type : 'ohlc' ,
576
+ tickwidth : 0.5
577
+ } ) ;
578
+
579
+ // shift time coordinates by 10 hours
580
+ trace1 . x = trace1 . x . map ( function ( d ) {
581
+ return d + ' 10:00' ;
582
+ } ) ;
583
+
584
+ var out = _calc ( [ trace0 , trace1 ] ) ;
585
+
586
+ expect ( out [ 0 ] . x . map ( ms2DateTime ) ) . toEqual ( [
587
+ '2016-08-31 12' , '2016-09-01' , '2016-09-01' , '2016-09-01' , '2016-09-01' , '2016-09-01 12' , null ,
588
+ '2016-09-03 12' , '2016-09-04' , '2016-09-04' , '2016-09-04' , '2016-09-04' , '2016-09-04 12' , null ,
589
+ '2016-09-05 12' , '2016-09-06' , '2016-09-06' , '2016-09-06' , '2016-09-06' , '2016-09-06 12' , null ,
590
+ '2016-09-09 12' , '2016-09-10' , '2016-09-10' , '2016-09-10' , '2016-09-10' , '2016-09-10 12' , null
591
+ ] ) ;
592
+
593
+ expect ( out [ 1 ] . x . map ( ms2DateTime ) ) . toEqual ( [
594
+ '2016-09-01 12' , '2016-09-02' , '2016-09-02' , '2016-09-02' , '2016-09-02' , '2016-09-02 12' , null ,
595
+ '2016-09-02 12' , '2016-09-03' , '2016-09-03' , '2016-09-03' , '2016-09-03' , '2016-09-03 12' , null ,
596
+ '2016-09-04 12' , '2016-09-05' , '2016-09-05' , '2016-09-05' , '2016-09-05' , '2016-09-05 12' , null ,
597
+ '2016-09-06 12' , '2016-09-07' , '2016-09-07' , '2016-09-07' , '2016-09-07' , '2016-09-07 12' , null
598
+ ] ) ;
599
+
600
+ expect ( out [ 2 ] . x . map ( ms2DateTime ) ) . toEqual ( [
601
+ '2016-08-31 22' , '2016-09-01 10' , '2016-09-01 10' , '2016-09-01 10' , '2016-09-01 10' , '2016-09-01 22' , null ,
602
+ '2016-09-03 22' , '2016-09-04 10' , '2016-09-04 10' , '2016-09-04 10' , '2016-09-04 10' , '2016-09-04 22' , null ,
603
+ '2016-09-05 22' , '2016-09-06 10' , '2016-09-06 10' , '2016-09-06 10' , '2016-09-06 10' , '2016-09-06 22' , null ,
604
+ '2016-09-09 22' , '2016-09-10 10' , '2016-09-10 10' , '2016-09-10 10' , '2016-09-10 10' , '2016-09-10 22' , null
605
+ ] ) ;
606
+
607
+ expect ( out [ 3 ] . x . map ( ms2DateTime ) ) . toEqual ( [
608
+ '2016-09-01 22' , '2016-09-02 10' , '2016-09-02 10' , '2016-09-02 10' , '2016-09-02 10' , '2016-09-02 22' , null ,
609
+ '2016-09-02 22' , '2016-09-03 10' , '2016-09-03 10' , '2016-09-03 10' , '2016-09-03 10' , '2016-09-03 22' , null ,
610
+ '2016-09-04 22' , '2016-09-05 10' , '2016-09-05 10' , '2016-09-05 10' , '2016-09-05 10' , '2016-09-05 22' , null ,
611
+ '2016-09-06 22' , '2016-09-07 10' , '2016-09-07 10' , '2016-09-07 10' , '2016-09-07 10' , '2016-09-07 22' , null
612
+ ] ) ;
613
+ } ) ;
614
+
615
+ it ( 'should fallback to a minimum x difference of 0.5 in one-item traces' , function ( ) {
616
+ var trace0 = Lib . extendDeep ( { } , mock1 , {
617
+ type : 'ohlc' ,
618
+ tickwidth : 0.5
619
+ } ) ;
620
+ trace0 . x = [ '2016-01-01' ] ;
621
+
622
+ var trace1 = Lib . extendDeep ( { } , mock0 , {
623
+ type : 'ohlc' ,
624
+ tickwidth : 0.5
625
+ } ) ;
626
+ trace1 . x = [ 10 ] ;
627
+
628
+ var out = _calc ( [ trace0 , trace1 ] ) ;
629
+
630
+ var x0 = out [ 0 ] . x ;
631
+ expect ( x0 [ x0 . length - 2 ] - x0 [ 0 ] ) . toEqual ( 1 ) ;
632
+
633
+ var x2 = out [ 2 ] . x ;
634
+ expect ( x2 [ x2 . length - 2 ] - x2 [ 0 ] ) . toEqual ( 1 ) ;
635
+
636
+ expect ( out [ 1 ] . x ) . toEqual ( [ ] ) ;
637
+ expect ( out [ 3 ] . x ) . toEqual ( [ ] ) ;
638
+ } ) ;
567
639
} ) ;
568
640
569
641
describe ( 'finance charts updates:' , function ( ) {
0 commit comments