@@ -937,6 +937,192 @@ describe('resizing with Plotly.relayout and Plotly.react', function() {
937
937
} ) ;
938
938
} ) ;
939
939
940
+ describe ( 'clear bglayer react' , function ( ) {
941
+ var x = [ 1 ] ;
942
+ var y = [ 2 ] ;
943
+ var z = [ 3 ] ;
944
+
945
+ var gd ;
946
+
947
+ beforeEach ( function ( ) {
948
+ gd = createGraphDiv ( ) ;
949
+ } ) ;
950
+
951
+ afterEach ( destroyGraphDiv ) ;
952
+
953
+ function hasBgRect ( ) {
954
+ var bgLayer = d3 . selectAll ( '.bglayer .bg' ) ;
955
+ return bgLayer [ 0 ] [ 0 ] !== undefined ; // i.e. background rect
956
+ }
957
+
958
+ it ( 'clear plot background when react from cartesian to gl3d & back' , function ( done ) {
959
+ Plotly . newPlot ( gd , {
960
+ data : [ { type : 'scatter' , x : x , y : y , z : z } ] ,
961
+ layout : { plot_bgcolor : 'green' }
962
+ } ) . then ( function ( ) {
963
+ expect ( gd . _fullLayout . plot_bgcolor ) . toBe ( 'green' ) ;
964
+ expect ( hasBgRect ( ) ) . toBe ( true ) ;
965
+ } ) . then ( function ( ) {
966
+ Plotly . react ( gd , {
967
+ data : [ { type : 'scatter3d' , x : x , y : y , z : z } ] ,
968
+ layout : { plot_bgcolor : 'red' }
969
+ } ) ;
970
+ } ) . then ( function ( ) {
971
+ expect ( gd . _fullLayout . plot_bgcolor ) . toBe ( undefined ) ;
972
+ expect ( hasBgRect ( ) ) . toBe ( false ) ;
973
+ } ) . then ( function ( ) {
974
+ Plotly . react ( gd , {
975
+ data : [ { type : 'scatter' , x : x , y : y , z : z } ] ,
976
+ layout : { plot_bgcolor : 'green' }
977
+ } ) ;
978
+ } ) . then ( function ( ) {
979
+ expect ( gd . _fullLayout . plot_bgcolor ) . toBe ( 'green' ) ;
980
+ expect ( hasBgRect ( ) ) . toBe ( true ) ;
981
+ } )
982
+ . catch ( failTest )
983
+ . then ( done ) ;
984
+ } ) ;
985
+
986
+ it ( 'clear plot background when react from gl2d to gl3d & back' , function ( done ) {
987
+ Plotly . newPlot ( gd , {
988
+ data : [ { type : 'scatter2d' , x : x , y : y , z : z } ] ,
989
+ layout : { plot_bgcolor : 'green' }
990
+ } ) . then ( function ( ) {
991
+ expect ( gd . _fullLayout . plot_bgcolor ) . toBe ( 'green' ) ;
992
+ expect ( hasBgRect ( ) ) . toBe ( true ) ;
993
+ } ) . then ( function ( ) {
994
+ Plotly . react ( gd , {
995
+ data : [ { type : 'scatter3d' , x : x , y : y , z : z } ] ,
996
+ layout : { plot_bgcolor : 'red' }
997
+ } ) ;
998
+ } ) . then ( function ( ) {
999
+ expect ( gd . _fullLayout . plot_bgcolor ) . toBe ( undefined ) ;
1000
+ expect ( hasBgRect ( ) ) . toBe ( false ) ;
1001
+ } ) . then ( function ( ) {
1002
+ Plotly . react ( gd , {
1003
+ data : [ { type : 'scatter2d' , x : x , y : y , z : z } ] ,
1004
+ layout : { plot_bgcolor : 'green' }
1005
+ } ) ;
1006
+ } ) . then ( function ( ) {
1007
+ expect ( gd . _fullLayout . plot_bgcolor ) . toBe ( 'green' ) ;
1008
+ expect ( hasBgRect ( ) ) . toBe ( true ) ;
1009
+ } )
1010
+ . catch ( failTest )
1011
+ . then ( done ) ;
1012
+ } ) ;
1013
+
1014
+ it ( 'create plot background when react from gl3d to gl2d & back' , function ( done ) {
1015
+ Plotly . newPlot ( gd , {
1016
+ data : [ { type : 'scatter3d' , x : x , y : y , z : z } ] ,
1017
+ layout : { plot_bgcolor : 'red' }
1018
+ } ) . then ( function ( ) {
1019
+ expect ( gd . _fullLayout . plot_bgcolor ) . toBe ( undefined ) ;
1020
+ expect ( hasBgRect ( ) ) . toBe ( false ) ;
1021
+ } ) . then ( function ( ) {
1022
+ Plotly . react ( gd , {
1023
+ data : [ { type : 'scatter2d' , x : x , y : y , z : z } ] ,
1024
+ layout : { plot_bgcolor : 'green' }
1025
+ } ) ;
1026
+ } ) . then ( function ( ) {
1027
+ expect ( gd . _fullLayout . plot_bgcolor ) . toBe ( 'green' ) ;
1028
+ expect ( hasBgRect ( ) ) . toBe ( true ) ;
1029
+ } ) . then ( function ( ) {
1030
+ Plotly . react ( gd , {
1031
+ data : [ { type : 'scatter3d' , x : x , y : y , z : z } ] ,
1032
+ layout : { plot_bgcolor : 'red' }
1033
+ } ) ;
1034
+ } ) . then ( function ( ) {
1035
+ expect ( gd . _fullLayout . plot_bgcolor ) . toBe ( undefined ) ;
1036
+ expect ( hasBgRect ( ) ) . toBe ( false ) ;
1037
+ } )
1038
+ . catch ( failTest )
1039
+ . then ( done ) ;
1040
+ } ) ;
1041
+
1042
+ it ( 'create plot background when react from gl3d to cartesian & back' , function ( done ) {
1043
+ Plotly . newPlot ( gd , {
1044
+ data : [ { type : 'scatter3d' , x : x , y : y , z : z } ] ,
1045
+ layout : { plot_bgcolor : 'red' }
1046
+ } ) . then ( function ( ) {
1047
+ expect ( gd . _fullLayout . plot_bgcolor ) . toBe ( undefined ) ;
1048
+ expect ( hasBgRect ( ) ) . toBe ( false ) ;
1049
+ } ) . then ( function ( ) {
1050
+ Plotly . react ( gd , {
1051
+ data : [ { type : 'scatter' , x : x , y : y , z : z } ] ,
1052
+ layout : { plot_bgcolor : 'green' }
1053
+ } ) ;
1054
+ } ) . then ( function ( ) {
1055
+ expect ( gd . _fullLayout . plot_bgcolor ) . toBe ( 'green' ) ;
1056
+ expect ( hasBgRect ( ) ) . toBe ( true ) ;
1057
+ } ) . then ( function ( ) {
1058
+ Plotly . react ( gd , {
1059
+ data : [ { type : 'scatter3d' , x : x , y : y , z : z } ] ,
1060
+ layout : { plot_bgcolor : 'red' }
1061
+ } ) ;
1062
+ } ) . then ( function ( ) {
1063
+ expect ( gd . _fullLayout . plot_bgcolor ) . toBe ( undefined ) ;
1064
+ expect ( hasBgRect ( ) ) . toBe ( false ) ;
1065
+ } )
1066
+ . catch ( failTest )
1067
+ . then ( done ) ;
1068
+ } ) ;
1069
+
1070
+ it ( 'change plot background when react from cartesian to gl2d & back' , function ( done ) {
1071
+ Plotly . newPlot ( gd , {
1072
+ data : [ { type : 'scatter' , x : x , y : y , z : z } ] ,
1073
+ layout : { plot_bgcolor : 'yellow' }
1074
+ } ) . then ( function ( ) {
1075
+ expect ( gd . _fullLayout . plot_bgcolor ) . toBe ( 'yellow' ) ;
1076
+ expect ( hasBgRect ( ) ) . toBe ( true ) ;
1077
+ } ) . then ( function ( ) {
1078
+ Plotly . react ( gd , {
1079
+ data : [ { type : 'scatter2d' , x : x , y : y , z : z } ] ,
1080
+ layout : { plot_bgcolor : 'green' }
1081
+ } ) ;
1082
+ } ) . then ( function ( ) {
1083
+ expect ( gd . _fullLayout . plot_bgcolor ) . toBe ( 'green' ) ;
1084
+ expect ( hasBgRect ( ) ) . toBe ( true ) ;
1085
+ } ) . then ( function ( ) {
1086
+ Plotly . react ( gd , {
1087
+ data : [ { type : 'scatter' , x : x , y : y , z : z } ] ,
1088
+ layout : { plot_bgcolor : 'yellow' }
1089
+ } ) ;
1090
+ } ) . then ( function ( ) {
1091
+ expect ( gd . _fullLayout . plot_bgcolor ) . toBe ( 'yellow' ) ;
1092
+ expect ( hasBgRect ( ) ) . toBe ( true ) ;
1093
+ } )
1094
+ . catch ( failTest )
1095
+ . then ( done ) ;
1096
+ } ) ;
1097
+
1098
+ it ( 'change plot background when react from gl2d to cartesian & back' , function ( done ) {
1099
+ Plotly . newPlot ( gd , {
1100
+ data : [ { type : 'scatter2d' , x : x , y : y , z : z } ] ,
1101
+ layout : { plot_bgcolor : 'yellow' }
1102
+ } ) . then ( function ( ) {
1103
+ expect ( gd . _fullLayout . plot_bgcolor ) . toBe ( 'yellow' ) ;
1104
+ expect ( hasBgRect ( ) ) . toBe ( true ) ;
1105
+ } ) . then ( function ( ) {
1106
+ Plotly . react ( gd , {
1107
+ data : [ { type : 'scatter' , x : x , y : y , z : z } ] ,
1108
+ layout : { plot_bgcolor : 'green' }
1109
+ } ) ;
1110
+ } ) . then ( function ( ) {
1111
+ expect ( gd . _fullLayout . plot_bgcolor ) . toBe ( 'green' ) ;
1112
+ expect ( hasBgRect ( ) ) . toBe ( true ) ;
1113
+ } ) . then ( function ( ) {
1114
+ Plotly . react ( gd , {
1115
+ data : [ { type : 'scatter2d' , x : x , y : y , z : z } ] ,
1116
+ layout : { plot_bgcolor : 'yellow' }
1117
+ } ) ;
1118
+ } ) . then ( function ( ) {
1119
+ expect ( gd . _fullLayout . plot_bgcolor ) . toBe ( 'yellow' ) ;
1120
+ expect ( hasBgRect ( ) ) . toBe ( true ) ;
1121
+ } )
1122
+ . catch ( failTest )
1123
+ . then ( done ) ;
1124
+ } ) ;
1125
+ } ) ;
940
1126
941
1127
describe ( 'Plotly.react and uirevision attributes' , function ( ) {
942
1128
var gd ;
0 commit comments