@@ -3988,14 +3988,18 @@ describe('hovermode: (x|y)unified', function() {
3988
3988
Lib . clearThrottle ( ) ;
3989
3989
}
3990
3990
3991
+ function getHoverLabel ( ) {
3992
+ var hoverLayer = d3 . select ( 'g.hoverlayer' ) ;
3993
+ return hoverLayer . select ( 'g.legend' ) ;
3994
+ }
3995
+
3991
3996
function assertElementCount ( selector , size ) {
3992
3997
var g = d3 . selectAll ( selector ) ;
3993
3998
expect ( g . size ( ) ) . toBe ( size ) ;
3994
3999
}
3995
4000
3996
4001
function assertLabel ( expectation ) {
3997
- var hoverLayer = d3 . select ( 'g.hoverlayer' ) ;
3998
- var hover = hoverLayer . select ( 'g.legend' ) ;
4002
+ var hover = getHoverLabel ( ) ;
3999
4003
var title = hover . select ( 'text.legendtitletext' ) ;
4000
4004
var traces = hover . selectAll ( 'g.traces' ) ;
4001
4005
@@ -4011,15 +4015,13 @@ describe('hovermode: (x|y)unified', function() {
4011
4015
}
4012
4016
4013
4017
function assertBgcolor ( color ) {
4014
- var hoverLayer = d3 . select ( 'g.hoverlayer' ) ;
4015
- var hover = hoverLayer . select ( 'g.legend' ) ;
4018
+ var hover = getHoverLabel ( ) ;
4016
4019
var bg = hover . select ( 'rect.bg' ) ;
4017
4020
expect ( bg . node ( ) . style . fill ) . toBe ( color ) ;
4018
4021
}
4019
4022
4020
4023
function assertSymbol ( exp ) {
4021
- var hoverLayer = d3 . select ( 'g.hoverlayer' ) ;
4022
- var hover = hoverLayer . select ( 'g.legend' ) ;
4024
+ var hover = getHoverLabel ( ) ;
4023
4025
var traces = hover . selectAll ( 'g.traces' ) ;
4024
4026
expect ( traces . size ( ) ) . toBe ( exp . length ) ;
4025
4027
@@ -4034,6 +4036,17 @@ describe('hovermode: (x|y)unified', function() {
4034
4036
} ) ;
4035
4037
}
4036
4038
4039
+ function assertFont ( fontFamily , fontSize , fontColor ) {
4040
+ var hover = getHoverLabel ( ) ;
4041
+ var text = hover . select ( 'text.legendtext' ) ;
4042
+ var node = text . node ( ) ;
4043
+
4044
+ var textStyle = window . getComputedStyle ( node ) ;
4045
+ expect ( textStyle . fontFamily . split ( ',' ) [ 0 ] ) . toBe ( fontFamily , 'wrong font family' ) ;
4046
+ expect ( textStyle . fontSize ) . toBe ( fontSize , 'wrong font size' ) ;
4047
+ expect ( textStyle . fill ) . toBe ( fontColor , 'wrong font color' ) ;
4048
+ }
4049
+
4037
4050
it ( 'set smart defaults for spikeline in x unified' , function ( done ) {
4038
4051
Plotly . newPlot ( gd , [ { y : [ 4 , 6 , 5 ] } ] , { 'hovermode' : 'x unified' , 'xaxis' : { 'color' : 'red' } } )
4039
4052
. then ( function ( gd ) {
@@ -4371,6 +4384,61 @@ describe('hovermode: (x|y)unified', function() {
4371
4384
. then ( done ) ;
4372
4385
} ) ;
4373
4386
4387
+ it ( 'should use hoverlabel.font or legend.font or layout.font' , function ( done ) {
4388
+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
4389
+
4390
+ // Set layout.font
4391
+ mockCopy . layout . font = { size : 20 , family : 'Mono' , color : 'rgb(10, 10, 10)' } ;
4392
+ Plotly . newPlot ( gd , mockCopy )
4393
+ . then ( function ( gd ) {
4394
+ _hover ( gd , { xval : 3 } ) ;
4395
+
4396
+ assertFont ( 'Mono' , '20px' , 'rgb(10, 10, 10)' ) ;
4397
+
4398
+ // Set legend.font which should win over layout font
4399
+ return Plotly . relayout ( gd , {
4400
+ 'showlegend' : true ,
4401
+ 'legend.font.size' : 15 ,
4402
+ 'legend.font.family' : 'Helvetica' ,
4403
+ 'legend.font.color' : 'rgb(20, 20, 20)'
4404
+ } ) ;
4405
+ } )
4406
+ . then ( function ( gd ) {
4407
+ _hover ( gd , { xval : 3 } ) ;
4408
+
4409
+ assertFont ( 'Helvetica' , '15px' , 'rgb(20, 20, 20)' ) ;
4410
+
4411
+ // Set hoverlabel.font which should win over legend.font
4412
+ return Plotly . relayout ( gd , {
4413
+ 'hoverlabel.font.size' : 22 ,
4414
+ 'hoverlabel.font.family' : 'Arial' ,
4415
+ 'hoverlabel.font.color' : 'rgb(30, 30, 30)'
4416
+ } ) ;
4417
+ } )
4418
+ . then ( function ( ) {
4419
+ _hover ( gd , { xval : 3 } ) ;
4420
+
4421
+ assertFont ( 'Arial' , '22px' , 'rgb(30, 30, 30)' ) ;
4422
+
4423
+ // Finally, check that a hoverlabel.font defined in template wins
4424
+ delete mockCopy . layout ;
4425
+ mockCopy . layout = {
4426
+ hovermode : 'x unified' ,
4427
+ template : { layout : { hoverlabel : { font : { family : 'Mono' , size : 30 , color : 'red' } } } } ,
4428
+ legend : { font : { size : 20 , family : 'Mono' , color : 'rgb(10, 10, 10)' } }
4429
+ } ;
4430
+
4431
+ return Plotly . newPlot ( gd , mockCopy ) ;
4432
+ } )
4433
+ . then ( function ( ) {
4434
+ _hover ( gd , { xval : 3 } ) ;
4435
+
4436
+ assertFont ( 'Mono' , '30px' , 'rgb(255, 0, 0)' ) ;
4437
+ } )
4438
+ . catch ( failTest )
4439
+ . then ( done ) ;
4440
+ } ) ;
4441
+
4374
4442
it ( 'should work with hovertemplate' , function ( done ) {
4375
4443
var mockCopy = Lib . extendDeep ( { } , mock ) ;
4376
4444
mockCopy . data [ 0 ] . hovertemplate = 'hovertemplate: %{y:0.2f}' ;
0 commit comments