@@ -984,3 +984,89 @@ describe('hover updates', function() {
984984
985985 } ) ;
986986} ) ;
987+
988+ describe ( 'Test hover label custom styling:' , function ( ) {
989+ afterEach ( destroyGraphDiv ) ;
990+
991+ function assertLabel ( className , expectation ) {
992+ var g = d3 . select ( 'g.' + className ) ;
993+
994+ var path = g . select ( 'path' ) ;
995+ expect ( path . style ( 'fill' ) ) . toEqual ( expectation . path [ 0 ] , 'bgcolor' ) ;
996+ expect ( path . style ( 'stroke' ) ) . toEqual ( expectation . path [ 1 ] , 'bordercolor' ) ;
997+
998+ var text = g . select ( 'text' ) ;
999+ expect ( parseInt ( text . style ( 'font-size' ) ) ) . toEqual ( expectation . text [ 0 ] , 'font.size' ) ;
1000+ expect ( text . style ( 'font-family' ) . split ( ',' ) [ 0 ] ) . toEqual ( expectation . text [ 1 ] , 'font.family' ) ;
1001+ expect ( text . style ( 'fill' ) ) . toEqual ( expectation . text [ 2 ] , 'font.color' ) ;
1002+ }
1003+
1004+ function assertPtLabel ( expectation ) {
1005+ assertLabel ( 'hovertext' , expectation ) ;
1006+ }
1007+
1008+ function assertCommonLabel ( expectation ) {
1009+ assertLabel ( 'axistext' , expectation ) ;
1010+ }
1011+
1012+ function _hover ( gd , opts ) {
1013+ Fx . hover ( gd , opts ) ;
1014+ delete gd . _lastHoverTime ;
1015+ }
1016+
1017+ it ( 'should work for x/y cartesian traces' , function ( done ) {
1018+ var gd = createGraphDiv ( ) ;
1019+
1020+ Plotly . plot ( gd , [ {
1021+ x : [ 1 , 2 , 3 ] ,
1022+ y : [ 1 , 2 , 1 ] ,
1023+ hoverlabel : {
1024+ font : {
1025+ color : [ 'red' , 'green' , 'blue' ] ,
1026+ size : 20
1027+ }
1028+ }
1029+ } ] , {
1030+ hovermode : 'x' ,
1031+ hoverlabel : { bgcolor : 'white' }
1032+ } )
1033+ . then ( function ( ) {
1034+ _hover ( gd , { xval : gd . _fullData [ 0 ] . x [ 0 ] } ) ;
1035+
1036+ assertPtLabel ( {
1037+ path : [ 'rgb(255, 255, 255)' , 'rgb(68, 68, 68)' ] ,
1038+ text : [ 20 , 'Arial' , 'rgb(255, 0, 0)' ]
1039+ } ) ;
1040+ assertCommonLabel ( {
1041+ path : [ 'rgb(255, 255, 255)' , 'rgb(255, 255, 255)' ] ,
1042+ text : [ 13 , 'Arial' , 'rgb(255, 255, 255)' ]
1043+ } ) ;
1044+ } )
1045+ . then ( function ( ) {
1046+ _hover ( gd , { xval : gd . _fullData [ 0 ] . x [ 1 ] } ) ;
1047+
1048+ assertPtLabel ( {
1049+ path : [ 'rgb(255, 255, 255)' , 'rgb(68, 68, 68)' ] ,
1050+ text : [ 20 , 'Arial' , 'rgb(0, 128, 0)' ]
1051+ } ) ;
1052+ assertCommonLabel ( {
1053+ path : [ 'rgb(255, 255, 255)' , 'rgb(255, 255, 255)' ] ,
1054+ text : [ 13 , 'Arial' , 'rgb(255, 255, 255)' ]
1055+ } ) ;
1056+ } )
1057+ . then ( function ( ) {
1058+ _hover ( gd , { xval : gd . _fullData [ 0 ] . x [ 2 ] } ) ;
1059+
1060+ assertPtLabel ( {
1061+ path : [ 'rgb(255, 255, 255)' , 'rgb(68, 68, 68)' ] ,
1062+ text : [ 20 , 'Arial' , 'rgb(0, 0, 255)' ]
1063+ } ) ;
1064+ assertCommonLabel ( {
1065+ path : [ 'rgb(255, 255, 255)' , 'rgb(255, 255, 255)' ] ,
1066+ text : [ 13 , 'Arial' , 'rgb(255, 255, 255)' ]
1067+ } ) ;
1068+ } )
1069+ . catch ( fail )
1070+ . then ( done ) ;
1071+ } ) ;
1072+ } ) ;
0 commit comments