@@ -15,6 +15,7 @@ var Plotly = require('../../plotly');
1515var Plots = require ( '../../plots/plots' ) ;
1616var Lib = require ( '../../lib' ) ;
1717var Axes = require ( '../../plots/cartesian/axes' ) ;
18+ var Fx = require ( '../../plots/cartesian/graph_interact' ) ;
1819var Color = require ( '../color' ) ;
1920var Drawing = require ( '../drawing' ) ;
2021var svgTextUtils = require ( '../../lib/svg_text_utils' ) ;
@@ -96,7 +97,16 @@ function drawOne(gd, index) {
9697 var annGroup = fullLayout . _infolayer . append ( 'g' )
9798 . classed ( 'annotation' , true )
9899 . attr ( 'data-index' , String ( index ) )
99- . style ( 'opacity' , options . opacity )
100+ . style ( 'opacity' , options . opacity ) ;
101+
102+ // another group for text+background so that they can rotate together
103+ var annTextGroup = annGroup . append ( 'g' )
104+ . classed ( 'annotation-text-g' , true )
105+ . attr ( 'data-index' , String ( index ) ) ;
106+
107+ var annTextGroupInner = annTextGroup . append ( 'g' )
108+ . style ( 'pointer-events' , options . captureevents ? 'all' : null )
109+ . call ( setCursor , 'default' )
100110 . on ( 'click' , function ( ) {
101111 gd . _dragging = false ;
102112 gd . emit ( 'plotly_clickannotation' , {
@@ -106,12 +116,33 @@ function drawOne(gd, index) {
106116 } ) ;
107117 } ) ;
108118
109- // another group for text+background so that they can rotate together
110- var annTextGroup = annGroup . append ( 'g' )
111- . classed ( 'annotation-text-g' , true )
112- . attr ( 'data-index' , String ( index ) ) ;
113-
114- var annTextGroupInner = annTextGroup . append ( 'g' ) ;
119+ if ( options . hovertext ) {
120+ annTextGroupInner
121+ . on ( 'mouseover' , function ( ) {
122+ var hoverOptions = options . hoverlabel ;
123+ var hoverFont = hoverOptions . font ;
124+ var bBox = this . getBoundingClientRect ( ) ;
125+ var bBoxRef = gd . getBoundingClientRect ( ) ;
126+
127+ Fx . loneHover ( {
128+ x0 : bBox . left - bBoxRef . left ,
129+ x1 : bBox . right - bBoxRef . left ,
130+ y : ( bBox . top + bBox . bottom ) / 2 - bBoxRef . top ,
131+ text : options . hovertext ,
132+ color : hoverOptions . bgcolor ,
133+ borderColor : hoverOptions . bordercolor ,
134+ fontFamily : hoverFont . family ,
135+ fontSize : hoverFont . size ,
136+ fontColor : hoverFont . color
137+ } , {
138+ container : fullLayout . _hoverlayer . node ( ) ,
139+ outerContainer : fullLayout . _paper . node ( )
140+ } ) ;
141+ } )
142+ . on ( 'mouseout' , function ( ) {
143+ Fx . loneUnhover ( fullLayout . _hoverlayer . node ( ) ) ;
144+ } ) ;
145+ }
115146
116147 var borderwidth = options . borderwidth ,
117148 borderpad = options . borderpad ,
@@ -205,6 +236,7 @@ function drawOne(gd, index) {
205236 // but this one is the positive total size
206237 annSize = Math . abs ( annSizeFromWidth ) + Math . abs ( annSizeFromHeight ) ,
207238 anchor = options [ axLetter + 'anchor' ] ,
239+ overallShift = options [ axLetter + 'shift' ] * ( axLetter === 'x' ? 1 : - 1 ) ,
208240 posPx = annPosPx [ axLetter ] ,
209241 basePx ,
210242 textPadShift ,
@@ -295,6 +327,9 @@ function drawOne(gd, index) {
295327 posPx . text -= shiftMinus ;
296328 }
297329 }
330+
331+ posPx . tail += overallShift ;
332+ posPx . head += overallShift ;
298333 }
299334 else {
300335 // with no arrow, the text rotates and *then* we put the anchor
@@ -304,6 +339,10 @@ function drawOne(gd, index) {
304339 posPx . text = basePx + textShift ;
305340 }
306341
342+ posPx . text += overallShift ;
343+ textShift += overallShift ;
344+ textPadShift += overallShift ;
345+
307346 // padplus/minus are used by autorange
308347 options [ '_' + axLetter + 'padplus' ] = ( annSize / 2 ) + textPadShift ;
309348 options [ '_' + axLetter + 'padminus' ] = ( annSize / 2 ) - textPadShift ;
@@ -493,21 +532,17 @@ function drawOne(gd, index) {
493532
494533 update [ annbase + '.x' ] = xa ?
495534 xa . p2r ( xa . r2p ( options . x ) + dx ) :
496- ( ( headX + dx - gs . l ) / gs . w ) ;
535+ ( options . x + ( dx / gs . w ) ) ;
497536 update [ annbase + '.y' ] = ya ?
498537 ya . p2r ( ya . r2p ( options . y ) + dy ) :
499- ( 1 - ( ( headY + dy - gs . t ) / gs . h ) ) ;
538+ ( options . y - ( dy / gs . h ) ) ;
500539
501540 if ( options . axref === options . xref ) {
502- update [ annbase + '.ax' ] = xa ?
503- xa . p2r ( xa . r2p ( options . ax ) + dx ) :
504- ( ( headX + dx - gs . l ) / gs . w ) ;
541+ update [ annbase + '.ax' ] = xa . p2r ( xa . r2p ( options . ax ) + dx ) ;
505542 }
506543
507544 if ( options . ayref === options . yref ) {
508- update [ annbase + '.ay' ] = ya ?
509- ya . p2r ( ya . r2p ( options . ay ) + dy ) :
510- ( 1 - ( ( headY + dy - gs . t ) / gs . h ) ) ;
545+ update [ annbase + '.ay' ] = ya . p2r ( ya . r2p ( options . ay ) + dy ) ;
511546 }
512547
513548 arrowGroup . attr ( 'transform' , 'translate(' + dx + ',' + dy + ')' ) ;
@@ -563,7 +598,8 @@ function drawOne(gd, index) {
563598 if ( xa ) update [ annbase + '.x' ] = options . x + dx / xa . _m ;
564599 else {
565600 var widthFraction = options . _xsize / gs . w ,
566- xLeft = options . x + options . _xshift / gs . w - widthFraction / 2 ;
601+ xLeft = options . x + ( options . _xshift - options . xshift ) / gs . w -
602+ widthFraction / 2 ;
567603
568604 update [ annbase + '.x' ] = dragElement . align ( xLeft + dx / gs . w ,
569605 widthFraction , 0 , 1 , options . xanchor ) ;
@@ -572,7 +608,8 @@ function drawOne(gd, index) {
572608 if ( ya ) update [ annbase + '.y' ] = options . y + dy / ya . _m ;
573609 else {
574610 var heightFraction = options . _ysize / gs . h ,
575- yBottom = options . y - options . _yshift / gs . h - heightFraction / 2 ;
611+ yBottom = options . y - ( options . _yshift + options . yshift ) / gs . h -
612+ heightFraction / 2 ;
576613
577614 update [ annbase + '.y' ] = dragElement . align ( yBottom - dy / gs . h ,
578615 heightFraction , 0 , 1 , options . yanchor ) ;
0 commit comments