@@ -3688,13 +3688,28 @@ describe('hovermode: (x|y)unified', function() {
36883688 } ) ;
36893689 }
36903690
3691- function assertStyle ( color ) {
3691+ function assertBgcolor ( color ) {
36923692 var hoverLayer = d3 . select ( 'g.hoverlayer' ) ;
36933693 var hover = hoverLayer . select ( 'g.legend' ) ;
36943694 var bg = hover . select ( 'rect.bg' ) ;
36953695 expect ( bg . node ( ) . style . fill ) . toBe ( color ) ;
36963696 }
36973697
3698+ function assertSymbol ( exp ) {
3699+ var hoverLayer = d3 . select ( 'g.hoverlayer' ) ;
3700+ var hover = hoverLayer . select ( 'g.legend' ) ;
3701+ var traces = hover . selectAll ( 'g.traces' ) ;
3702+ traces . each ( function ( d , i ) {
3703+ var pts = d3 . select ( this ) . selectAll ( 'g.legendpoints path' ) ;
3704+ pts . each ( function ( ) {
3705+ var node = d3 . select ( this ) . node ( ) ;
3706+ expect ( node . style . fill ) . toBe ( exp [ i ] [ 0 ] , 'wrong fill for point ' + i ) ;
3707+ expect ( node . style . strokeWidth ) . toBe ( exp [ i ] [ 1 ] , 'wrong stroke-width for point ' + i ) ;
3708+ expect ( node . style . stroke ) . toBe ( exp [ i ] [ 2 ] , 'wrong stroke for point ' + i ) ;
3709+ } ) ;
3710+ } ) ;
3711+ }
3712+
36983713 it ( 'set smart defaults for spikeline in x unified' , function ( done ) {
36993714 Plotly . newPlot ( gd , [ { y : [ 4 , 6 , 5 ] } ] , { 'hovermode' : 'x unified' , 'xaxis' : { 'color' : 'red' } } )
37003715 . then ( function ( gd ) {
@@ -3773,7 +3788,7 @@ describe('hovermode: (x|y)unified', function() {
37733788 . then ( done ) ;
37743789 } ) ;
37753790
3776- it ( 'should for finance traces' , function ( done ) {
3791+ it ( 'should work for finance traces' , function ( done ) {
37773792 var mockOhlc = require ( '@mocks/finance_multicategory.json' ) ;
37783793 var mockCopy = Lib . extendDeep ( { } , mockOhlc ) ;
37793794 mockCopy . layout . hovermode = 'x unified' ;
@@ -3790,6 +3805,66 @@ describe('hovermode: (x|y)unified', function() {
37903805 . then ( done ) ;
37913806 } ) ;
37923807
3808+ it ( 'should style scatter symbols accordingly' , function ( done ) {
3809+ var mock = require ( '@mocks/marker_colorscale_template.json' ) ;
3810+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
3811+ mockCopy . layout . hovermode = 'x unified' ;
3812+ Plotly . newPlot ( gd , mockCopy )
3813+ . then ( function ( gd ) {
3814+ _hover ( gd , { xval : 1 } ) ;
3815+ assertLabel ( { title : '1' , items : [ '2' ] } ) ;
3816+ assertSymbol ( [ [ 'rgb(33, 145, 140)' , '0px' , '' ] ] ) ;
3817+ } )
3818+ . then ( function ( ) {
3819+ _hover ( gd , { xval : 2 } ) ;
3820+ assertLabel ( { title : '2' , items : [ '3' ] } ) ;
3821+ assertSymbol ( [ [ 'rgb(253, 231, 37)' , '0px' , '' ] ] ) ;
3822+ } )
3823+ . catch ( failTest )
3824+ . then ( done ) ;
3825+ } ) ;
3826+
3827+ it ( 'should style bar symbols accordingly' , function ( done ) {
3828+ var mock = require ( '@mocks/bar-marker-line-colorscales.json' ) ;
3829+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
3830+ mockCopy . layout . hovermode = 'x unified' ;
3831+ Plotly . newPlot ( gd , mockCopy )
3832+ . then ( function ( gd ) {
3833+ _hover ( gd , { xval : 10 } ) ;
3834+ assertLabel ( { title : '10' , items : [ '10' ] } ) ;
3835+ assertSymbol ( [ [ 'rgb(94, 216, 43)' , '4px' , 'rgb(197, 232, 190)' ] ] ) ;
3836+ } )
3837+ . then ( function ( ) {
3838+ _hover ( gd , { xval : 20 } ) ;
3839+ assertLabel ( { title : '20' , items : [ '20' ] } ) ;
3840+ assertSymbol ( [ [ 'rgb(168, 140, 33)' , '4px' , 'rgb(111, 193, 115)' ] ] ) ;
3841+ } )
3842+ . catch ( failTest )
3843+ . then ( done ) ;
3844+ } ) ;
3845+
3846+ it ( 'should style funnel symbols accordingly' , function ( done ) {
3847+ var mock = require ( '@mocks/funnel_custom.json' ) ;
3848+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
3849+ mockCopy . layout . hovermode = 'x unified' ;
3850+ Plotly . newPlot ( gd , mockCopy )
3851+ . then ( function ( gd ) {
3852+ _hover ( gd , { xval : 1 } ) ;
3853+ // assertLabel({title: 'B', items: ['asdf', 'asdf']});
3854+ assertSymbol ( [
3855+ [ 'rgb(0, 255, 0)' , '0px' , '' ] ,
3856+ [ 'rgb(255, 255, 0)' , '5px' , 'rgb(0, 0, 127)' ]
3857+ ] ) ;
3858+ } )
3859+ . then ( function ( ) {
3860+ _hover ( gd , { xval : 4 } ) ;
3861+ // assertLabel({title: 'E', items: ['asdf', 'asdf']});
3862+ // assertSymbol([['rgb(168, 140, 33)', '4px', 'rgb(111, 193, 115)']]);
3863+ } )
3864+ . catch ( failTest )
3865+ . then ( done ) ;
3866+ } ) ;
3867+
37933868 it ( 'label should have color of paper_bgcolor' , function ( done ) {
37943869 var mockCopy = Lib . extendDeep ( { } , mock ) ;
37953870 var bgcolor = 'rgb(15, 200, 85)' ;
@@ -3798,7 +3873,7 @@ describe('hovermode: (x|y)unified', function() {
37983873 . then ( function ( gd ) {
37993874 _hover ( gd , { xval : 3 } ) ;
38003875
3801- assertStyle ( bgcolor ) ;
3876+ assertBgcolor ( bgcolor ) ;
38023877 } )
38033878 . catch ( failTest )
38043879 . then ( done ) ;
0 commit comments