@@ -681,8 +681,6 @@ describe('bar hover', function() {
681
681
682
682
var gd ;
683
683
684
- var TOL = 0.1 ;
685
-
686
684
beforeAll ( function ( ) {
687
685
jasmine . addMatchers ( customMatchers ) ;
688
686
} ) ;
@@ -708,12 +706,19 @@ describe('bar hover', function() {
708
706
var pt = Bar . hoverPoints ( pointData , xval , yval , closest ) [ 0 ] ;
709
707
710
708
return {
711
- index : pt . index ,
712
- color : pt . color ,
713
- pos : [ pt . x0 , pt . x1 , pt . y0 , pt . y1 , pt . xLabelVal , pt . yLabelVal ]
709
+ style : [ pt . index , pt . color , pt . xLabelVal , pt . yLabelVal ] ,
710
+ pos : [ pt . x0 , pt . x1 , pt . y0 , pt . y1 ]
714
711
} ;
715
712
}
716
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
+
717
722
describe ( 'with orientation *v*' , function ( ) {
718
723
beforeAll ( function ( done ) {
719
724
gd = createGraphDiv ( ) ;
@@ -726,21 +731,15 @@ describe('bar hover', function() {
726
731
it ( 'should return the correct hover point data (case x)' , function ( ) {
727
732
var out = _hover ( gd , 0 , 0 , 'x' ) ;
728
733
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
+ expect ( out . style ) . toEqual ( [ 0 , 'rgb(255, 102, 97)' , 0 , 13.23 ] ) ;
735
+ assertPos ( out . pos , [ 11.87 , 106.8 , 152.76 , 152.76 ] ) ;
734
736
} ) ;
735
737
736
738
it ( 'should return the correct hover point data (case closest)' , function ( ) {
737
739
var out = _hover ( gd , - 0.2 , 12 , 'closest' ) ;
738
740
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 ) ;
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 ] ) ;
744
743
} ) ;
745
744
} ) ;
746
745
@@ -756,21 +755,15 @@ describe('bar hover', function() {
756
755
it ( 'should return the correct hover point data (case y)' , function ( ) {
757
756
var out = _hover ( gd , 185.645 , 0.15 , 'y' ) ;
758
757
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 ) ;
758
+ expect ( out . style ) . toEqual ( [ 0 , '#1f77b4' , 75 , 0 ] ) ;
759
+ assertPos ( out . pos , [ 182.88 , 182.88 , 214.5 , 170.5 ] ) ;
764
760
} ) ;
765
761
766
762
it ( 'should return the correct hover point data (case closest)' , function ( ) {
767
763
var out = _hover ( gd , 135.88 , - 0.15 , 'closest' ) ;
768
764
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 ) ;
765
+ expect ( out . style ) . toEqual ( [ 0 , '#1f77b4' , 75 , 0 ] ) ;
766
+ assertPos ( out . pos , [ 182.88 , 182.88 , 214.5 , 192.5 ] ) ;
774
767
} ) ;
775
768
} ) ;
776
769
0 commit comments