@@ -1187,6 +1187,61 @@ describe('pie hovering', function() {
11871187 . catch ( failTest )
11881188 . then ( done ) ;
11891189 } ) ;
1190+
1191+ it ( 'should honor *hoverlabel.align*' , function ( done ) {
1192+ function _assert ( msg , exp ) {
1193+ var tx = d3 . select ( 'g.hovertext' ) . select ( 'text' ) ;
1194+ expect ( tx . attr ( 'text-anchor' ) ) . toBe ( exp . textAnchor , 'text anchor|' + msg ) ;
1195+ expect ( Number ( tx . attr ( 'x' ) ) ) . toBeCloseTo ( exp . posX , 2 , 'x position|' + msg ) ;
1196+ }
1197+
1198+ function _hoverLeft ( ) {
1199+ mouseEvent ( 'mouseover' , 100 , 200 ) ;
1200+ Lib . clearThrottle ( ) ;
1201+ }
1202+
1203+ function _hoverRight ( ) {
1204+ mouseEvent ( 'mouseover' , 300 , 200 ) ;
1205+ Lib . clearThrottle ( ) ;
1206+ }
1207+
1208+ Plotly . plot ( gd , [ {
1209+ type : 'pie' ,
1210+ labels : [ 'a' , 'b' ]
1211+ } ] , {
1212+ showlegend : false ,
1213+ margin : { l : 0 , t : 0 , b : 0 , r : 0 } ,
1214+ width : 400 ,
1215+ height : 400
1216+ } )
1217+ . then ( _hoverLeft )
1218+ . then ( function ( ) { _assert ( 'base left sector' , { textAnchor : 'start' , posX : 9 } ) ; } )
1219+ . then ( _hoverRight )
1220+ . then ( function ( ) { _assert ( 'base right sector' , { textAnchor : 'end' , posX : - 9 } ) ; } )
1221+ . then ( function ( ) {
1222+ return Plotly . relayout ( gd , 'hoverlabel.align' , 'left' ) ;
1223+ } )
1224+ . then ( _hoverLeft )
1225+ . then ( function ( ) { _assert ( 'align:left left sector' , { textAnchor : 'start' , posX : 9 } ) ; } )
1226+ . then ( _hoverRight )
1227+ . then ( function ( ) { _assert ( 'align:left right sector' , { textAnchor : 'start' , posX : - 37.45 } ) ; } )
1228+ . then ( function ( ) {
1229+ return Plotly . restyle ( gd , 'hoverlabel.align' , 'right' ) ;
1230+ } )
1231+ . then ( _hoverLeft )
1232+ . then ( function ( ) { _assert ( 'align:right left sector' , { textAnchor : 'end' , posX : 37.45 } ) ; } )
1233+ . then ( _hoverRight )
1234+ . then ( function ( ) { _assert ( 'align:right right sector' , { textAnchor : 'end' , posX : - 9 } ) ; } )
1235+ . then ( function ( ) {
1236+ return Plotly . restyle ( gd , 'hoverlabel.align' , [ [ 'left' , 'right' ] ] ) ;
1237+ } )
1238+ . then ( _hoverLeft )
1239+ . then ( function ( ) { _assert ( 'arrayOk align:right left sector' , { textAnchor : 'end' , posX : 37.45 } ) ; } )
1240+ . then ( _hoverRight )
1241+ . then ( function ( ) { _assert ( 'arrayOk align:left right sector' , { textAnchor : 'start' , posX : - 37.45 } ) ; } )
1242+ . catch ( failTest )
1243+ . then ( done ) ;
1244+ } ) ;
11901245 } ) ;
11911246
11921247 describe ( 'should fit labels within graph div' , function ( ) {
0 commit comments