@@ -7141,6 +7141,76 @@ describe('hovermode: (x|y)unified', function () {
71417141 . then ( done , done . fail ) ;
71427142 } ) ;
71437143
7144+ it ( 'should style bar pattern swatches from the hovered point' , async ( ) => {
7145+ const getSwatch = ( ) => getHoverLabel ( ) . select ( 'g.legendpoints path' ) ;
7146+
7147+ const getPatternId = ( fill ) => {
7148+ const match = / u r l \( [ " ' ] ? # ( [ ^ " ' ) ] + ) [ " ' ] ? \) / . exec ( fill ) ;
7149+ return match ? match [ 1 ] : null ;
7150+ } ;
7151+
7152+ const getPatternStroke = ( patternId ) => {
7153+ const pattern = document . getElementById ( patternId ) ;
7154+ if ( ! pattern ) return null ;
7155+ const painted = pattern . querySelector ( 'path, circle' ) ;
7156+ return painted ? painted . getAttribute ( 'stroke' ) || painted . getAttribute ( 'fill' ) : null ;
7157+ } ;
7158+
7159+ const getSwatchStroke = ( ) => getPatternStroke ( getPatternId ( getSwatch ( ) . node ( ) . style . fill ) ) ;
7160+
7161+ await Plotly . newPlot (
7162+ gd ,
7163+ [
7164+ {
7165+ type : 'bar' ,
7166+ x : [ 0 , 1 ] ,
7167+ y : [ 1 , 2 ] ,
7168+ marker : {
7169+ color : [ 'red' , 'purple' ] ,
7170+ pattern : { shape : [ '/' , '\\' ] }
7171+ }
7172+ }
7173+ ] ,
7174+ {
7175+ hovermode : 'x unified' ,
7176+ showlegend : false ,
7177+ width : 400 ,
7178+ height : 400 ,
7179+ margin : { t : 50 , b : 50 , l : 50 , r : 50 }
7180+ }
7181+ ) ;
7182+
7183+ _hover ( gd , { xval : 0 } ) ;
7184+ assertLabel ( { title : '0' , items : [ '1' ] } ) ;
7185+
7186+ const patternId0 = getPatternId ( getSwatch ( ) . node ( ) . style . fill ) ;
7187+ expect ( patternId0 ) . toBeTruthy ( 'first bar swatch uses a pattern fill' ) ;
7188+ expect ( getPatternStroke ( patternId0 ) ) . toBe ( 'rgb(255, 0, 0)' ) ;
7189+
7190+ _hover ( gd , { xval : 1 } ) ;
7191+ assertLabel ( { title : '1' , items : [ '2' ] } ) ;
7192+
7193+ const patternId1 = getPatternId ( getSwatch ( ) . node ( ) . style . fill ) ;
7194+ expect ( patternId1 ) . toBeTruthy ( 'second bar swatch uses a pattern fill' ) ;
7195+ expect ( patternId1 ) . not . toBe ( patternId0 ) ;
7196+ expect ( getPatternStroke ( patternId1 ) ) . toBe ( 'rgb(128, 0, 128)' ) ;
7197+
7198+ await Plotly . restyle ( gd , 'marker.pattern.fgcolor' , [ [ 'blue' , 'green' ] ] ) ;
7199+
7200+ _hover ( gd , { xval : 0 } ) ;
7201+ expect ( getSwatchStroke ( ) ) . toBe ( 'rgb(0, 0, 255)' ) ;
7202+
7203+ _hover ( gd , { xval : 1 } ) ;
7204+ expect ( getSwatchStroke ( ) ) . toBe ( 'rgb(0, 128, 0)' ) ;
7205+
7206+ await Plotly . restyle ( gd , 'marker.pattern.shape' , [ [ '/' , '' ] ] ) ;
7207+
7208+ _hover ( gd , { xval : 1 } ) ;
7209+ assertLabel ( { title : '1' , items : [ '2' ] } ) ;
7210+ expect ( getSwatch ( ) . node ( ) . style . fill ) . toBe ( 'rgb(128, 0, 128)' ) ;
7211+ expect ( getPatternId ( getSwatch ( ) . node ( ) . style . fill ) ) . toBe ( null ) ;
7212+ } ) ;
7213+
71447214 it ( 'should style funnel symbols accordingly' , function ( done ) {
71457215 var mock = require ( '../../image/mocks/funnel_custom.json' ) ;
71467216 var mockCopy = Lib . extendDeep ( { } , mock ) ;
0 commit comments