@@ -10,6 +10,7 @@ var destroyGraphDiv = require('../assets/destroy_graph_div');
1010var mouseEvent = require ( '../assets/mouse_event' ) ;
1111var click = require ( '../assets/click' ) ;
1212var doubleClick = require ( '../assets/double_click' ) ;
13+ var fail = require ( '../assets/fail_test' ) ;
1314
1415describe ( 'hover info' , function ( ) {
1516 'use strict' ;
@@ -811,3 +812,62 @@ describe('hover on fill', function() {
811812 } ) . then ( done ) ;
812813 } ) ;
813814} ) ;
815+
816+ describe ( 'hover updates' , function ( ) {
817+ 'use strict' ;
818+
819+ afterEach ( destroyGraphDiv ) ;
820+
821+ function assertLabelsCorrect ( mousePos , labelPos , labelText ) {
822+ return new Promise ( function ( resolve ) {
823+ if ( mousePos ) {
824+ mouseEvent ( 'mousemove' , mousePos [ 0 ] , mousePos [ 1 ] ) ;
825+ }
826+
827+ setTimeout ( function ( ) {
828+ var hoverText = d3 . selectAll ( 'g.hovertext' ) ;
829+ expect ( hoverText . size ( ) ) . toEqual ( 1 ) ;
830+ expect ( hoverText . text ( ) ) . toEqual ( labelText ) ;
831+
832+ var transformParts = hoverText . attr ( 'transform' ) . split ( '(' ) ;
833+ expect ( transformParts [ 0 ] ) . toEqual ( 'translate' ) ;
834+ var transformCoords = transformParts [ 1 ] . split ( ')' ) [ 0 ] . split ( ',' ) ;
835+ expect ( + transformCoords [ 0 ] ) . toBeCloseTo ( labelPos [ 0 ] , - 1 , labelText + ':x' ) ;
836+ expect ( + transformCoords [ 1 ] ) . toBeCloseTo ( labelPos [ 1 ] , - 1 , labelText + ':y' ) ;
837+
838+ resolve ( ) ;
839+ } , constants . HOVERMINTIME ) ;
840+ } ) ;
841+ }
842+
843+ it ( 'should update the labels on animation' , function ( done ) {
844+ var mock = {
845+ data : [
846+ { x : [ 0.5 ] , y : [ 0.5 ] , showlegend : false } ,
847+ { x : [ 0 ] , y : [ 0 ] , showlegend : false } ,
848+ ] ,
849+ layout : {
850+ margin : { t : 0 , r : 0 , b : 0 , l : 0 } ,
851+ width : 200 ,
852+ height : 200 ,
853+ xaxis : { range : [ 0 , 1 ] } ,
854+ yaxis : { range : [ 0 , 1 ] } ,
855+ }
856+ } ;
857+
858+ var gd = createGraphDiv ( ) ;
859+ Plotly . plot ( gd , mock ) . then ( function ( ) {
860+ // The label text gets concatenated together when queried. Such is life.
861+ return assertLabelsCorrect ( [ 100 , 100 ] , [ 103 , 100 ] , 'trace 00.5' ) ;
862+ } ) . then ( function ( ) {
863+ return Plotly . animate ( gd , [ {
864+ data : [ { x : [ 0 ] , y : [ 0 ] } , { x : [ 0.5 ] , y : [ 0.5 ] } ] ,
865+ traces : [ 0 , 1 ] ,
866+ } ] , { frame : { redraw : false , duration : 0 } } ) ;
867+ } ) . then ( function ( ) {
868+ // No mouse event this time. Just change the data and check the label.
869+ // Ditto on concatenation. This is "trace 1" + "0.5"
870+ return assertLabelsCorrect ( null , [ 103 , 100 ] , 'trace 10.5' ) ;
871+ } ) . catch ( fail ) . then ( done ) ;
872+ } ) ;
873+ } ) ;
0 commit comments