@@ -676,6 +676,103 @@ describe('A bar plot', function() {
676676 } ) ;
677677} ) ;
678678
679+ describe ( 'bar hover' , function ( ) {
680+ 'use strict' ;
681+
682+ var gd ;
683+
684+ beforeAll ( function ( ) {
685+ jasmine . addMatchers ( customMatchers ) ;
686+ } ) ;
687+
688+ afterAll ( 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+ index : pt . index ,
710+ color : pt . color ,
711+ pos : [ pt . x0 , pt . x1 , pt . y0 , pt . y1 , pt . xLabelVal , pt . yLabelVal ]
712+ } ;
713+ }
714+
715+ describe ( 'with orientation *v*' , function ( ) {
716+ beforeAll ( function ( done ) {
717+ gd = createGraphDiv ( ) ;
718+
719+ var mock = Lib . extendDeep ( { } , require ( '@mocks/11.json' ) ) ;
720+
721+ Plotly . plot ( gd , mock . data , mock . layout ) . then ( done ) ;
722+ } ) ;
723+
724+ it ( 'should return the correct hover point data (case x)' , function ( ) {
725+ var out = _hover ( gd , 0 , 0 , 'x' ) ;
726+
727+ expect ( out . index ) . toEqual ( 0 ) ;
728+ expect ( out . color ) . toEqual ( 'rgb(255, 102, 97)' ) ;
729+ expect ( out . pos ) . toBeCloseToArray ( [
730+ 11.87 , 106.8 , 152.76 , 152.76 , 0 , 13.23
731+ ] ) ;
732+ } ) ;
733+
734+ it ( 'should return the correct hover point data (case closest)' , function ( ) {
735+ var out = _hover ( gd , - 0.2 , 12 , 'closest' ) ;
736+
737+ expect ( out . index ) . toEqual ( 0 ) ;
738+ expect ( out . color ) . toEqual ( 'rgb(255, 102, 97)' ) ;
739+ expect ( out . pos ) . toBeCloseToArray ( [
740+ 11.87 , 59.33 , 152.76 , 152.76 , 0 , 13.23
741+ ] ) ;
742+ } ) ;
743+ } ) ;
744+
745+ describe ( 'with orientation *h*' , function ( ) {
746+ beforeAll ( function ( done ) {
747+ gd = createGraphDiv ( ) ;
748+
749+ var mock = Lib . extendDeep ( { } , require ( '@mocks/bar_attrs_group_norm.json' ) ) ;
750+
751+ Plotly . plot ( gd , mock . data , mock . layout ) . then ( done ) ;
752+ } ) ;
753+
754+ it ( 'should return the correct hover point data (case y)' , function ( ) {
755+ var out = _hover ( gd , 185.645 , 0.15 , 'y' ) ;
756+
757+ expect ( out . index ) . toEqual ( 0 ) ;
758+ expect ( out . color ) . toEqual ( '#1f77b4' ) ;
759+ expect ( out . pos ) . toBeCloseToArray ( [
760+ 182.88 , 182.88 , 214.5 , 170.5 , 75 , 0
761+ ] ) ;
762+ } ) ;
763+
764+ it ( 'should return the correct hover point data (case closest)' , function ( ) {
765+ var out = _hover ( gd , 135.88 , - 0.15 , 'closest' ) ;
766+
767+ expect ( out . index ) . toEqual ( 0 ) ;
768+ expect ( out . color ) . toEqual ( '#1f77b4' ) ;
769+ expect ( out . pos ) . toBeCloseToArray ( [
770+ 182.88 , 182.88 , 214.5 , 192.5 , 75 , 0
771+ ] ) ;
772+ } ) ;
773+ } ) ;
774+
775+ } ) ;
679776
680777function mockBarPlot ( dataWithoutTraceType , layout ) {
681778 var traceTemplate = { type : 'bar' } ;
0 commit comments