@@ -1146,7 +1146,57 @@ describe('pie hovering', function() {
1146
1146
'hovertemplate arrayOK'
1147
1147
) ;
1148
1148
} )
1149
- . catch ( fail )
1149
+ . catch ( failTest )
1150
+ . then ( done ) ;
1151
+ } ) ;
1152
+ } ) ;
1153
+
1154
+ describe ( 'should fit labels within graph div' , function ( ) {
1155
+ var gd ;
1156
+
1157
+ beforeEach ( function ( ) { gd = createGraphDiv ( ) ; } ) ;
1158
+
1159
+ afterEach ( destroyGraphDiv ) ;
1160
+
1161
+ it ( '- when labels overflow left and right' , function ( done ) {
1162
+ Plotly . plot ( gd , [ {
1163
+ hole : 0.33 ,
1164
+ hoverinfo : 'label+text+percent' ,
1165
+ values : [ '22238.58' , '3145.82' , '2865.21' , '1664.58' ] ,
1166
+ labels : [ 'label 1 - another long text label' , 'label 2' , 'label 3 - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16' , 'label 4' ] ,
1167
+ hovertext : [ '$22,238.58' , '$3,145.82' , '$2,865.21' , '$1,664.58' ] ,
1168
+ type : 'pie'
1169
+ } ] , {
1170
+ showlegend : false ,
1171
+ width : 220 ,
1172
+ height : 220 ,
1173
+ margin : { l : 0 , r : 0 , t : 0 , b : 0 }
1174
+ } )
1175
+ . then ( function ( ) { mouseEvent ( 'mouseover' , 50 , 50 ) ; } )
1176
+ . then ( function ( ) {
1177
+ assertHoverLabelContent ( {
1178
+ nums : 'label 3 - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n$2,865.21\n9.58%'
1179
+ } , 'long label to the left' ) ;
1180
+
1181
+ var label = d3 . select ( 'g.hovertext' ) ;
1182
+ var bbox = label . node ( ) . getBoundingClientRect ( ) ;
1183
+
1184
+ expect ( bbox . left ) . toBeWithin ( 1 , 10 , 'bbox left bound' ) ;
1185
+ expect ( bbox . right ) . toBeWithin ( 275 , 10 , 'bbox right bound (beyond graph)' ) ;
1186
+ } )
1187
+ . then ( function ( ) { mouseEvent ( 'mouseover' , 150 , 150 ) ; } )
1188
+ . then ( function ( ) {
1189
+ assertHoverLabelContent ( {
1190
+ nums : 'label 1 - another long text label\n$22,238.58\n74.3%'
1191
+ } , 'long label to the right' ) ;
1192
+
1193
+ var label = d3 . select ( 'g.hovertext' ) ;
1194
+ var bbox = label . node ( ) . getBoundingClientRect ( ) ;
1195
+
1196
+ expect ( bbox . left ) . toBeWithin ( 30 , 10 , 'bbox left bound' ) ;
1197
+ expect ( bbox . right ) . toBeWithin ( 220 , 10 , 'bbox right bound' ) ;
1198
+ } )
1199
+ . catch ( failTest )
1150
1200
. then ( done ) ;
1151
1201
} ) ;
1152
1202
} ) ;
0 commit comments