@@ -512,7 +512,7 @@ describe('finance charts calc transforms:', function() {
512512
513513 expect ( out [ 2 ] . name ) . toEqual ( 'trace 0 - increasing' ) ;
514514 expect ( out [ 2 ] . x . map ( ms2DateTime ) ) . toEqual ( [
515- '2016-09-03 23:59:59.999 ' , '2016-09-04' , '2016-09-04' , '2016-09-04' , '2016-09-04' , '2016-09-04' , null
515+ '2016-09-03 22:48 ' , '2016-09-04' , '2016-09-04' , '2016-09-04' , '2016-09-04' , '2016-09-04 01:12 ' , null
516516 ] ) ;
517517 expect ( out [ 2 ] . y ) . toEqual ( [
518518 32.06 , 32.06 , 34.25 , 31.62 , 33.18 , 33.18 , null
@@ -564,6 +564,78 @@ describe('finance charts calc transforms:', function() {
564564 32.87 , 33.5 , 33.37 , 33.37 , 33.37 , 33.62
565565 ] ) ;
566566 } ) ;
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+ } ) ;
567639} ) ;
568640
569641describe ( 'finance charts updates:' , function ( ) {
@@ -780,4 +852,53 @@ describe('finance charts updates:', function() {
780852 done ( ) ;
781853 } ) ;
782854 } ) ;
855+
856+ it ( 'Plotly.addTraces + Plotly.relayout should update candlestick box position values' , function ( done ) {
857+
858+ function assertBoxPosFields ( dPos ) {
859+ expect ( gd . calcdata . length ) . toEqual ( dPos . length ) ;
860+
861+ gd . calcdata . forEach ( function ( calcTrace , i ) {
862+ if ( dPos [ i ] === undefined ) {
863+ expect ( calcTrace [ 0 ] . t . dPos ) . toBeUndefined ( ) ;
864+ }
865+ else {
866+ expect ( calcTrace [ 0 ] . t . dPos ) . toEqual ( dPos [ i ] ) ;
867+ }
868+ } ) ;
869+ }
870+
871+ var trace0 = {
872+ type : 'candlestick' ,
873+ x : [ '2011-01-01' ] ,
874+ open : [ 0 ] ,
875+ high : [ 3 ] ,
876+ low : [ 1 ] ,
877+ close : [ 3 ]
878+ } ;
879+
880+ Plotly . plot ( gd , [ trace0 ] ) . then ( function ( ) {
881+ assertBoxPosFields ( [ 0.5 , undefined ] ) ;
882+
883+ return Plotly . addTraces ( gd , { } ) ;
884+
885+ } )
886+ . then ( function ( ) {
887+ var update = {
888+ type : 'candlestick' ,
889+ x : [ [ '2011-02-02' ] ] ,
890+ open : [ [ 0 ] ] ,
891+ high : [ [ 3 ] ] ,
892+ low : [ [ 1 ] ] ,
893+ close : [ [ 3 ] ]
894+ } ;
895+
896+ return Plotly . restyle ( gd , update ) ;
897+ } )
898+ . then ( function ( ) {
899+ assertBoxPosFields ( [ 0.5 , undefined , 0.5 , undefined ] ) ;
900+
901+ done ( ) ;
902+ } ) ;
903+ } ) ;
783904} ) ;
0 commit comments