@@ -3688,13 +3688,28 @@ describe('hovermode: (x|y)unified', function() {
3688
3688
} ) ;
3689
3689
}
3690
3690
3691
- function assertStyle ( color ) {
3691
+ function assertBgcolor ( color ) {
3692
3692
var hoverLayer = d3 . select ( 'g.hoverlayer' ) ;
3693
3693
var hover = hoverLayer . select ( 'g.legend' ) ;
3694
3694
var bg = hover . select ( 'rect.bg' ) ;
3695
3695
expect ( bg . node ( ) . style . fill ) . toBe ( color ) ;
3696
3696
}
3697
3697
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
+
3698
3713
it ( 'set smart defaults for spikeline in x unified' , function ( done ) {
3699
3714
Plotly . newPlot ( gd , [ { y : [ 4 , 6 , 5 ] } ] , { 'hovermode' : 'x unified' , 'xaxis' : { 'color' : 'red' } } )
3700
3715
. then ( function ( gd ) {
@@ -3773,7 +3788,7 @@ describe('hovermode: (x|y)unified', function() {
3773
3788
. then ( done ) ;
3774
3789
} ) ;
3775
3790
3776
- it ( 'should for finance traces' , function ( done ) {
3791
+ it ( 'should work for finance traces' , function ( done ) {
3777
3792
var mockOhlc = require ( '@mocks/finance_multicategory.json' ) ;
3778
3793
var mockCopy = Lib . extendDeep ( { } , mockOhlc ) ;
3779
3794
mockCopy . layout . hovermode = 'x unified' ;
@@ -3790,6 +3805,66 @@ describe('hovermode: (x|y)unified', function() {
3790
3805
. then ( done ) ;
3791
3806
} ) ;
3792
3807
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
+
3793
3868
it ( 'label should have color of paper_bgcolor' , function ( done ) {
3794
3869
var mockCopy = Lib . extendDeep ( { } , mock ) ;
3795
3870
var bgcolor = 'rgb(15, 200, 85)' ;
@@ -3798,7 +3873,7 @@ describe('hovermode: (x|y)unified', function() {
3798
3873
. then ( function ( gd ) {
3799
3874
_hover ( gd , { xval : 3 } ) ;
3800
3875
3801
- assertStyle ( bgcolor ) ;
3876
+ assertBgcolor ( bgcolor ) ;
3802
3877
} )
3803
3878
. catch ( failTest )
3804
3879
. then ( done ) ;
0 commit comments