@@ -676,6 +676,105 @@ describe('A bar plot', function() {
676
676
} ) ;
677
677
} ) ;
678
678
679
+ describe ( 'bar hover' , function ( ) {
680
+ 'use strict' ;
681
+
682
+ var gd ;
683
+
684
+ var TOL = 0.1 ;
685
+
686
+ beforeAll ( function ( ) {
687
+ jasmine . addMatchers ( customMatchers ) ;
688
+ } ) ;
689
+
690
+ afterEach ( destroyGraphDiv ) ;
691
+
692
+ function getPointData ( gd ) {
693
+ var cd = gd . calcdata ,
694
+ subplot = gd . _fullLayout . _plots . xy ;
695
+
696
+ return {
697
+ index : false ,
698
+ distance : 20 ,
699
+ cd : cd [ 0 ] ,
700
+ trace : cd [ 0 ] [ 0 ] . trace ,
701
+ xa : subplot . xaxis ,
702
+ ya : subplot . yaxis
703
+ } ;
704
+ }
705
+
706
+ function _hover ( gd , xval , yval , closest ) {
707
+ var pointData = getPointData ( gd ) ;
708
+ var pt = Bar . hoverPoints ( pointData , xval , yval , closest ) [ 0 ] ;
709
+
710
+ return {
711
+ index : pt . index ,
712
+ color : pt . color ,
713
+ pos : [ pt . x0 , pt . x1 , pt . y0 , pt . y1 , pt . xLabelVal , pt . yLabelVal ]
714
+ } ;
715
+ }
716
+
717
+ describe ( 'with orientation *v*' , function ( ) {
718
+ beforeAll ( function ( done ) {
719
+ gd = createGraphDiv ( ) ;
720
+
721
+ var mock = Lib . extendDeep ( { } , require ( '@mocks/11.json' ) ) ;
722
+
723
+ Plotly . plot ( gd , mock . data , mock . layout ) . then ( done ) ;
724
+ } ) ;
725
+
726
+ it ( 'should return the correct hover point data (case x)' , function ( ) {
727
+ var out = _hover ( gd , 0 , 0 , 'x' ) ;
728
+
729
+ expect ( out . index ) . toEqual ( 0 ) ;
730
+ expect ( out . color ) . toEqual ( 'rgb(255, 102, 97)' ) ;
731
+ expect ( out . pos ) . toBeCloseToArray ( [
732
+ 11.87 , 106.8 , 152.76 , 152.76 , 0 , 13.23
733
+ ] , TOL ) ;
734
+ } ) ;
735
+
736
+ it ( 'should return the correct hover point data (case closest)' , function ( ) {
737
+ var out = _hover ( gd , - 0.2 , 12 , 'closest' ) ;
738
+
739
+ expect ( out . index ) . toEqual ( 0 ) ;
740
+ expect ( out . color ) . toEqual ( 'rgb(255, 102, 97)' ) ;
741
+ expect ( out . pos ) . toBeCloseToArray ( [
742
+ 11.87 , 59.33 , 152.76 , 152.76 , 0 , 13.23
743
+ ] , TOL ) ;
744
+ } ) ;
745
+ } ) ;
746
+
747
+ describe ( 'with orientation *h*' , function ( ) {
748
+ beforeAll ( function ( done ) {
749
+ gd = createGraphDiv ( ) ;
750
+
751
+ var mock = Lib . extendDeep ( { } , require ( '@mocks/bar_attrs_group_norm.json' ) ) ;
752
+
753
+ Plotly . plot ( gd , mock . data , mock . layout ) . then ( done ) ;
754
+ } ) ;
755
+
756
+ it ( 'should return the correct hover point data (case y)' , function ( ) {
757
+ var out = _hover ( gd , 185.645 , 0.15 , 'y' ) ;
758
+
759
+ expect ( out . index ) . toEqual ( 0 ) ;
760
+ expect ( out . color ) . toEqual ( '#1f77b4' ) ;
761
+ expect ( out . pos ) . toBeCloseToArray ( [
762
+ 182.88 , 182.88 , 214.5 , 170.5 , 75 , 0
763
+ ] , TOL ) ;
764
+ } ) ;
765
+
766
+ it ( 'should return the correct hover point data (case closest)' , function ( ) {
767
+ var out = _hover ( gd , 135.88 , - 0.15 , 'closest' ) ;
768
+
769
+ expect ( out . index ) . toEqual ( 0 ) ;
770
+ expect ( out . color ) . toEqual ( '#1f77b4' ) ;
771
+ expect ( out . pos ) . toBeCloseToArray ( [
772
+ 182.88 , 182.88 , 214.5 , 192.5 , 75 , 0
773
+ ] , TOL ) ;
774
+ } ) ;
775
+ } ) ;
776
+
777
+ } ) ;
679
778
680
779
function mockBarPlot ( dataWithoutTraceType , layout ) {
681
780
var traceTemplate = { type : 'bar' } ;
0 commit comments