@@ -4728,27 +4728,144 @@ describe('hovermode: (x|y)unified', function() {
4728
4728
. then ( done , done . fail ) ;
4729
4729
} ) ;
4730
4730
4731
- it ( 'shares filtering logic with compare mode x' , function ( done ) {
4731
+ it ( 'filtering logic for compare mode x' , function ( done ) {
4732
4732
var mock = require ( '@mocks/27.json' ) ;
4733
4733
var mockCopy = Lib . extendDeep ( { } , mock ) ;
4734
4734
4735
4735
Plotly . newPlot ( gd , mockCopy )
4736
4736
. then ( function ( gd ) {
4737
4737
_hover ( gd , { xval : '2002' } ) ;
4738
4738
assertElementCount ( 'g.hovertext' , 2 ) ;
4739
-
4740
- return Plotly . relayout ( gd , 'hovermode' , 'x unified' ) ;
4741
- } )
4742
- . then ( function ( ) {
4743
- _hover ( gd , { xval : '2002' } ) ;
4744
- assertLabel ( { title : '2002.042' , items : [
4745
- 'Market income : 0.5537845' ,
4746
- 'Market incom... : 0.4420997'
4747
- ] } ) ;
4748
4739
} )
4749
4740
. then ( done , done . fail ) ;
4750
4741
} ) ;
4751
4742
4743
+ it ( 'x unified should include close points and filter multiple points from the same trace' , function ( done ) {
4744
+ Plotly . newPlot ( gd , {
4745
+ data : [
4746
+ {
4747
+ type : 'bar' ,
4748
+ name : 'bar' ,
4749
+ x : [
4750
+ '2017-04' ,
4751
+ '2017-07' ,
4752
+ '2017-10' ,
4753
+ '2018-01'
4754
+ ] ,
4755
+ xperiod : 'M3' ,
4756
+ y : [ 10 , 5 , 10 , 5 ]
4757
+ } ,
4758
+ {
4759
+ type : 'scatter' ,
4760
+ name : 'scatter' ,
4761
+ x : [
4762
+ '2017-01-01' ,
4763
+ '2017-02-01' ,
4764
+ '2017-03-01' ,
4765
+ '2017-04-01' ,
4766
+ '2017-05-01' ,
4767
+ '2017-06-01' ,
4768
+ '2017-07-01' ,
4769
+ '2017-08-01' ,
4770
+ '2017-09-01' ,
4771
+ '2017-10-01' ,
4772
+ '2017-11-01' ,
4773
+ '2017-12-01'
4774
+ ] ,
4775
+ y : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 ]
4776
+ }
4777
+ ] ,
4778
+ layout : {
4779
+ hovermode : 'x unified' ,
4780
+ showlegend : false ,
4781
+ width : 500 ,
4782
+ height : 500 ,
4783
+ margin : {
4784
+ t : 50 ,
4785
+ b : 50 ,
4786
+ l : 50 ,
4787
+ r : 50
4788
+ }
4789
+ }
4790
+ } )
4791
+ . then ( function ( gd ) {
4792
+ _hover ( gd , { xpx : 25 , ypx : 250 } ) ;
4793
+ assertLabel ( { title : 'Jan 1, 2017' , items : [
4794
+ 'scatter : 1'
4795
+ ] } ) ;
4796
+
4797
+ _hover ( gd , { xpx : 50 , ypx : 250 } ) ;
4798
+ assertLabel ( { title : 'Feb 1, 2017' , items : [
4799
+ 'scatter : 2'
4800
+ ] } ) ;
4801
+
4802
+ _hover ( gd , { xpx : 75 , ypx : 250 } ) ;
4803
+ assertLabel ( { title : 'Mar 1, 2017' , items : [
4804
+ 'scatter : 3'
4805
+ ] } ) ;
4806
+
4807
+ _hover ( gd , { xpx : 100 , ypx : 250 } ) ;
4808
+ assertLabel ( { title : 'Apr 1, 2017' , items : [
4809
+ 'bar : 10' ,
4810
+ 'scatter : 4'
4811
+ ] } ) ;
4812
+
4813
+ _hover ( gd , { xpx : 125 , ypx : 250 } ) ;
4814
+ assertLabel ( { title : 'May 1, 2017' , items : [
4815
+ 'bar : (Apr 1, 2017, 10)' ,
4816
+ 'scatter : 5'
4817
+ ] } ) ;
4818
+
4819
+ _hover ( gd , { xpx : 150 , ypx : 250 } ) ;
4820
+ assertLabel ( { title : 'Jun 1, 2017' , items : [
4821
+ 'bar : (Apr 1, 2017, 10)' ,
4822
+ 'scatter : 6'
4823
+ ] } ) ;
4824
+
4825
+ _hover ( gd , { xpx : 175 , ypx : 250 } ) ;
4826
+ assertLabel ( { title : 'Jul 1, 2017' , items : [
4827
+ 'bar : 5' ,
4828
+ 'scatter : 7'
4829
+ ] } ) ;
4830
+
4831
+ _hover ( gd , { xpx : 200 , ypx : 250 } ) ;
4832
+ assertLabel ( { title : 'Aug 1, 2017' , items : [
4833
+ 'bar : (Jul 1, 2017, 5)' ,
4834
+ 'scatter : 8'
4835
+ ] } ) ;
4836
+
4837
+ _hover ( gd , { xpx : 225 , ypx : 250 } ) ;
4838
+ assertLabel ( { title : 'Sep 1, 2017' , items : [
4839
+ 'bar : (Jul 1, 2017, 5)' ,
4840
+ 'scatter : 9'
4841
+ ] } ) ;
4842
+
4843
+ _hover ( gd , { xpx : 250 , ypx : 250 } ) ;
4844
+ assertLabel ( { title : 'Oct 1, 2017' , items : [
4845
+ 'bar : 10' ,
4846
+ 'scatter : 10'
4847
+ ] } ) ;
4848
+
4849
+ _hover ( gd , { xpx : 275 , ypx : 250 } ) ;
4850
+ assertLabel ( { title : 'Nov 1, 2017' , items : [
4851
+ 'bar : (Oct 1, 2017, 10)' ,
4852
+ 'scatter : 11'
4853
+ ] } ) ;
4854
+
4855
+ _hover ( gd , { xpx : 300 , ypx : 250 } ) ;
4856
+ assertLabel ( { title : 'Dec 1, 2017' , items : [
4857
+ 'bar : (Oct 1, 2017, 10)' ,
4858
+ 'scatter : 12'
4859
+ ] } ) ;
4860
+
4861
+ _hover ( gd , { xpx : 350 , ypx : 250 } ) ;
4862
+ assertLabel ( { title : 'Jan 1, 2018' , items : [
4863
+ 'bar : 5'
4864
+ ] } ) ;
4865
+ } )
4866
+ . then ( done , done . fail ) ;
4867
+ } ) ;
4868
+
4752
4869
it ( 'should have the same traceorder as the legend' , function ( done ) {
4753
4870
var mock = require ( '@mocks/stacked_area.json' ) ;
4754
4871
var mockCopy = Lib . extendDeep ( { } , mock ) ;
0 commit comments