@@ -1078,6 +1078,64 @@ describe('Plotly.react and uirevision attributes', function() {
10781078 . then ( done ) ;
10791079 } ) ;
10801080
1081+ describe ( 'should handle case where traces are removed' , function ( ) {
1082+ var y0 = [ 1 , 2 , 1 ] ;
1083+ var y1 = [ 2 , 1 , 2 ] ;
1084+
1085+ function mockLegendClick ( ) {
1086+ return Registry . call ( '_guiRestyle' , gd , 'visible' , 'legendonly' ) ;
1087+ }
1088+
1089+ function _assert ( msg , exp ) {
1090+ return function ( ) {
1091+ expect ( gd . _fullData . length ) . toBe ( exp . length , msg + ' - # traces' ) ;
1092+ exp . forEach ( function ( expi , i ) {
1093+ expect ( gd . _fullData [ i ] . visible ) . toBe ( expi , msg + ' trace ' + i + ' visibility' ) ;
1094+ } ) ;
1095+ } ;
1096+ }
1097+
1098+ it ( '- case no uirevision no uid' , function ( done ) {
1099+ Plotly . newPlot ( gd , [ { y : y0 } , { y : y1 } ] )
1100+ . then ( _assert ( 'base' , [ true , true ] ) )
1101+ . then ( mockLegendClick )
1102+ . then ( _react ( [ { y : [ 1 , 2 , 1 ] } ] ) )
1103+ . then ( _assert ( 'after react' , [ true ] ) )
1104+ . catch ( failTest )
1105+ . then ( done ) ;
1106+ } ) ;
1107+
1108+ it ( '- case no uirevision with uid' , function ( done ) {
1109+ Plotly . newPlot ( gd , [ { y : y0 , uid : 'a' } , { y : y1 , uid : 'b' } ] )
1110+ . then ( _assert ( 'base' , [ true , true ] ) )
1111+ . then ( mockLegendClick )
1112+ . then ( _react ( [ { y : [ 1 , 2 , 1 ] , uid : 'a' } ] ) )
1113+ . then ( _assert ( 'after react' , [ true ] ) )
1114+ . catch ( failTest )
1115+ . then ( done ) ;
1116+ } ) ;
1117+
1118+ it ( '- case with uirevision no uid' , function ( done ) {
1119+ Plotly . newPlot ( gd , [ { y : y0 } , { y : y1 } ] , { uirevision : true } )
1120+ . then ( _assert ( 'base' , [ true , true ] ) )
1121+ . then ( mockLegendClick )
1122+ . then ( _react ( { data : [ { y : [ 1 , 2 , 1 ] } ] , layout : { uirevision : true } } ) )
1123+ . then ( _assert ( 'after react' , [ 'legendonly' ] ) )
1124+ . catch ( failTest )
1125+ . then ( done ) ;
1126+ } ) ;
1127+
1128+ it ( '- case with uirevision with uid' , function ( done ) {
1129+ Plotly . newPlot ( gd , [ { y : y0 , uid : 'a' } , { y : y1 , uid : 'b' } ] , { uirevision : true } )
1130+ . then ( _assert ( 'base' , [ true , true ] ) )
1131+ . then ( mockLegendClick )
1132+ . then ( _react ( { data : [ { y : [ 1 , 2 , 1 ] , uid : 'a' } ] , layout : { uirevision : true } } ) )
1133+ . then ( _assert ( 'after react' , [ 'legendonly' ] ) )
1134+ . catch ( failTest )
1135+ . then ( done ) ;
1136+ } ) ;
1137+ } ) ;
1138+
10811139 it ( 'controls axis edits with axis.uirevision' , function ( done ) {
10821140 function fig ( mainRev , xRev , yRev , x2Rev , y2Rev ) {
10831141 return {
0 commit comments