@@ -1041,3 +1041,51 @@ describe('annotation dragging', function() {
1041
1041
. then ( done ) ;
1042
1042
} ) ;
1043
1043
} ) ;
1044
+
1045
+ describe ( 'annotation clip paths' , function ( ) {
1046
+ var gd ;
1047
+
1048
+ beforeEach ( function ( done ) {
1049
+ gd = createGraphDiv ( ) ;
1050
+
1051
+ // we've already tested autorange with relayout, so fix the geometry
1052
+ // completely so we know exactly what we're dealing with
1053
+ // plot area is 300x300, and covers data range 100x100
1054
+ Plotly . plot ( gd , [ { x : [ 0 , 100 ] , y : [ 0 , 100 ] } ] , {
1055
+ annotations : [
1056
+ { x : 50 , y : 50 , text : 'hi' , width : 50 } ,
1057
+ { x : 20 , y : 20 , text : 'bye' , height : 40 } ,
1058
+ { x : 80 , y : 80 , text : 'why?' }
1059
+ ]
1060
+ } )
1061
+ . then ( done ) ;
1062
+ } ) ;
1063
+
1064
+ afterEach ( destroyGraphDiv ) ;
1065
+
1066
+ it ( 'should only make the clippaths it needs and delete others' , function ( done ) {
1067
+ expect ( d3 . select ( gd ) . selectAll ( '.annclip' ) . size ( ) ) . toBe ( 2 ) ;
1068
+
1069
+ Plotly . relayout ( gd , { 'annotations[0].visible' : false } )
1070
+ . then ( function ( ) {
1071
+ expect ( d3 . select ( gd ) . selectAll ( '.annclip' ) . size ( ) ) . toBe ( 1 ) ;
1072
+
1073
+ return Plotly . relayout ( gd , { 'annotations[2].width' : 20 } ) ;
1074
+ } )
1075
+ . then ( function ( ) {
1076
+ expect ( d3 . select ( gd ) . selectAll ( '.annclip' ) . size ( ) ) . toBe ( 2 ) ;
1077
+
1078
+ return Plotly . relayout ( gd , { 'annotations[1].height' : null } ) ;
1079
+ } )
1080
+ . then ( function ( ) {
1081
+ expect ( d3 . select ( gd ) . selectAll ( '.annclip' ) . size ( ) ) . toBe ( 1 ) ;
1082
+
1083
+ return Plotly . relayout ( gd , { 'annotations[2]' : null } ) ;
1084
+ } )
1085
+ . then ( function ( ) {
1086
+ expect ( d3 . select ( gd ) . selectAll ( '.annclip' ) . size ( ) ) . toBe ( 0 ) ;
1087
+ } )
1088
+ . catch ( failTest )
1089
+ . then ( done ) ;
1090
+ } ) ;
1091
+ } ) ;
0 commit comments