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