@@ -2203,6 +2203,72 @@ describe('Test hover label custom styling:', function() {
2203
2203
. then ( done ) ;
2204
2204
} ) ;
2205
2205
2206
+ it ( 'should work for x/y cartesian traces (multi-trace case)' , function ( done ) {
2207
+ var gd = createGraphDiv ( ) ;
2208
+
2209
+ function assertNameLabel ( expectation ) {
2210
+ var g = d3 . selectAll ( 'g.hovertext > text.name' ) ;
2211
+
2212
+ if ( expectation === null ) {
2213
+ expect ( g . size ( ) ) . toBe ( 0 ) ;
2214
+ } else {
2215
+ g . each ( function ( _ , i ) {
2216
+ var textStyle = window . getComputedStyle ( this ) ;
2217
+ expect ( textStyle . fill ) . toBe ( expectation . color [ i ] ) ;
2218
+ } ) ;
2219
+ }
2220
+ }
2221
+
2222
+ Plotly . plot ( gd , [ {
2223
+ x : [ 1 , 2 , 3 ] ,
2224
+ y : [ 1 , 2 , 1 ] ,
2225
+ } , {
2226
+ x : [ 1 , 2 , 3 ] ,
2227
+ y : [ 4 , 5 , 4 ] ,
2228
+ } ] , {
2229
+ hovermode : 'x' ,
2230
+ } )
2231
+ . then ( function ( ) {
2232
+ _hover ( gd , { xval : gd . _fullData [ 0 ] . x [ 0 ] } ) ;
2233
+ assertNameLabel ( {
2234
+ color : [ 'rgb(31, 119, 180)' , 'rgb(255, 127, 14)' ]
2235
+ } ) ;
2236
+ return Plotly . restyle ( gd , 'marker.color' , [ 'red' , 'blue' ] ) ;
2237
+ } )
2238
+ . then ( function ( ) {
2239
+ _hover ( gd , { xval : gd . _fullData [ 0 ] . x [ 0 ] } ) ;
2240
+ assertNameLabel ( {
2241
+ color : [ 'rgb(255, 0, 0)' , 'rgb(0, 0, 255)' ]
2242
+ } ) ;
2243
+ return Plotly . relayout ( gd , 'hoverlabel.bgcolor' , 'white' ) ;
2244
+ } )
2245
+ . then ( function ( ) {
2246
+ _hover ( gd , { xval : gd . _fullData [ 0 ] . x [ 0 ] } ) ;
2247
+ // should not affect the name font color
2248
+ assertNameLabel ( {
2249
+ color : [ 'rgb(255, 0, 0)' , 'rgb(0, 0, 255)' ]
2250
+ } ) ;
2251
+ return Plotly . restyle ( gd , 'marker.color' , [ 'rgba(255,0,0,0.1)' , 'rgba(0,0,255,0.1)' ] ) ;
2252
+ } )
2253
+ . then ( function ( ) {
2254
+ _hover ( gd , { xval : gd . _fullData [ 0 ] . x [ 0 ] } ) ;
2255
+ // should blend with plot_bgcolor
2256
+ assertNameLabel ( {
2257
+ color : [ 'rgb(255, 179, 179)' , 'rgb(179, 179, 255)' ]
2258
+ } ) ;
2259
+ return Plotly . restyle ( gd , 'marker.color' , [ 'rgba(255,0,0,0)' , 'rgba(0,0,255,0)' ] ) ;
2260
+ } )
2261
+ . then ( function ( ) {
2262
+ _hover ( gd , { xval : gd . _fullData [ 0 ] . x [ 0 ] } ) ;
2263
+ // uses default line color when opacity=0
2264
+ assertNameLabel ( {
2265
+ color : [ 'rgb(68, 68, 68)' , 'rgb(68, 68, 68)' ]
2266
+ } ) ;
2267
+ } )
2268
+ . catch ( failTest )
2269
+ . then ( done ) ;
2270
+ } ) ;
2271
+
2206
2272
it ( 'should work for 2d z cartesian traces' , function ( done ) {
2207
2273
var gd = createGraphDiv ( ) ;
2208
2274
0 commit comments