@@ -593,4 +593,139 @@ describe('spikeline hover', function() {
593
593
. catch ( failTest )
594
594
. then ( done ) ;
595
595
} ) ;
596
+
597
+ it ( 'correctly draws lines up to the last point' , function ( done ) {
598
+ Plotly . newPlot ( gd , [
599
+ { type : 'bar' , y : [ 5 , 7 , 9 , 6 , 4 , 3 ] } ,
600
+ { y : [ 5 , 7 , 9 , 6 , 4 , 3 ] } ,
601
+ { y : [ 5 , 7 , 9 , 6 , 4 , 3 ] , marker : { color : 'red' } }
602
+ ] , {
603
+ xaxis : { showspikes : true } ,
604
+ yaxis : { showspikes : true } ,
605
+ spikedistance : - 1 ,
606
+ width : 400 , height : 400 ,
607
+ showlegend : false
608
+ } )
609
+ . then ( function ( ) {
610
+ _hover ( { xpx : 150 , ypx : 250 } ) ;
611
+
612
+ var lines = d3 . selectAll ( 'line.spikeline' ) ;
613
+ expect ( lines . size ( ) ) . toBe ( 4 ) ;
614
+ expect ( lines [ 0 ] [ 1 ] . getAttribute ( 'stroke' ) ) . toBe ( 'red' ) ;
615
+ expect ( lines [ 0 ] [ 3 ] . getAttribute ( 'stroke' ) ) . toBe ( 'red' ) ;
616
+ } )
617
+ . catch ( failTest )
618
+ . then ( done ) ;
619
+ } ) ;
620
+
621
+ describe ( 'works across all cartesian traces' , function ( ) {
622
+ var schema = Plotly . PlotSchema . get ( ) ;
623
+ var traces = Object . keys ( schema . traces ) ;
624
+ var tracesSchema = [ ] ;
625
+ var i , j , k ;
626
+ for ( i = 0 ; i < traces . length ; i ++ ) {
627
+ tracesSchema . push ( schema . traces [ traces [ i ] ] ) ;
628
+ }
629
+ var excludedTraces = [ 'image' ] ;
630
+ var cartesianTraces = tracesSchema . filter ( function ( t ) {
631
+ return t . categories . length &&
632
+ t . categories . indexOf ( 'cartesian' ) !== - 1 &&
633
+ t . categories . indexOf ( 'noHover' ) === - 1 &&
634
+ excludedTraces . indexOf ( t . type ) === - 1 ;
635
+ } ) ;
636
+
637
+ function makeData ( type , axName , a , b ) {
638
+ var input = [ a , b ] ;
639
+ var cat = input [ axName === 'yaxis' ? 1 : 0 ] ;
640
+ var data = input [ axName === 'yaxis' ? 0 : 1 ] ;
641
+
642
+ var measure = [ ] ;
643
+ for ( j = 0 ; j < data . length ; j ++ ) {
644
+ measure . push ( 'absolute' ) ;
645
+ }
646
+
647
+ var z = Lib . init2dArray ( cat . length , data . length ) ;
648
+ for ( j = 0 ; j < z . length ; j ++ ) {
649
+ for ( k = 0 ; k < z [ j ] . length ; k ++ ) {
650
+ z [ j ] [ k ] = 0 ;
651
+ }
652
+ }
653
+ if ( axName === 'xaxis' ) {
654
+ for ( j = 0 ; j < b . length ; j ++ ) {
655
+ z [ 0 ] [ j ] = b [ j ] ;
656
+ }
657
+ }
658
+ if ( axName === 'yaxis' ) {
659
+ for ( j = 0 ; j < b . length ; j ++ ) {
660
+ z [ j ] [ 0 ] = b [ j ] ;
661
+ }
662
+ }
663
+
664
+ return Lib . extendDeep ( { } , {
665
+ orientation : axName === 'yaxis' ? 'h' : 'v' ,
666
+ type : type ,
667
+ x : cat ,
668
+ a : cat ,
669
+
670
+ b : data ,
671
+ y : data ,
672
+ z : z ,
673
+
674
+ // For OHLC
675
+ open : data ,
676
+ close : data ,
677
+ high : data ,
678
+ low : data ,
679
+
680
+ // For histogram
681
+ nbinsx : cat . length ,
682
+ nbinsy : data . length ,
683
+
684
+ // For waterfall
685
+ measure : measure ,
686
+
687
+ // For splom
688
+ dimensions : [
689
+ {
690
+ label : 'DimensionA' ,
691
+ values : a
692
+ } ,
693
+ {
694
+ label : 'DimensionB' ,
695
+ values : b
696
+ }
697
+ ]
698
+ } ) ;
699
+ }
700
+
701
+ cartesianTraces . forEach ( function ( trace ) {
702
+ it ( 'correctly responds to setting the spikedistance to -1 for ' + trace . type , function ( done ) {
703
+ var type = trace . type ;
704
+ var x = [ 4 , 5 , 6 ] ;
705
+ var data = [ 7 , 2 , 3 ] ;
706
+
707
+ var mock = {
708
+ data : [ makeData ( type , 'xaxis' , x , data ) ] ,
709
+ layout : {
710
+ spikedistance : - 1 ,
711
+ xaxis : { showspikes : true } ,
712
+ yaxis : { showspikes : true } ,
713
+ zaxis : { showspikes : true } ,
714
+ title : { text : trace . type } ,
715
+ width : 400 , height : 400
716
+ }
717
+ } ;
718
+
719
+ Plotly . newPlot ( gd , mock )
720
+ . then ( function ( ) {
721
+ _hover ( { xpx : 200 , ypx : 100 } ) ;
722
+
723
+ var lines = d3 . selectAll ( 'line.spikeline' ) ;
724
+ expect ( lines . size ( ) ) . toBe ( 4 ) ;
725
+ } )
726
+ . catch ( failTest )
727
+ . then ( done ) ;
728
+ } ) ;
729
+ } ) ;
730
+ } ) ;
596
731
} ) ;
0 commit comments