@@ -15,6 +15,7 @@ var Plotly = require('../../plotly');
15
15
var Plots = require ( '../../plots/plots' ) ;
16
16
var Lib = require ( '../../lib' ) ;
17
17
var Axes = require ( '../../plots/cartesian/axes' ) ;
18
+ var Fx = require ( '../../plots/cartesian/graph_interact' ) ;
18
19
var Color = require ( '../color' ) ;
19
20
var Drawing = require ( '../drawing' ) ;
20
21
var svgTextUtils = require ( '../../lib/svg_text_utils' ) ;
@@ -96,7 +97,16 @@ function drawOne(gd, index) {
96
97
var annGroup = fullLayout . _infolayer . append ( 'g' )
97
98
. classed ( 'annotation' , true )
98
99
. 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' )
100
110
. on ( 'click' , function ( ) {
101
111
gd . _dragging = false ;
102
112
gd . emit ( 'plotly_clickannotation' , {
@@ -106,12 +116,33 @@ function drawOne(gd, index) {
106
116
} ) ;
107
117
} ) ;
108
118
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
+ }
115
146
116
147
var borderwidth = options . borderwidth ,
117
148
borderpad = options . borderpad ,
@@ -205,6 +236,7 @@ function drawOne(gd, index) {
205
236
// but this one is the positive total size
206
237
annSize = Math . abs ( annSizeFromWidth ) + Math . abs ( annSizeFromHeight ) ,
207
238
anchor = options [ axLetter + 'anchor' ] ,
239
+ overallShift = options [ axLetter + 'shift' ] * ( axLetter === 'x' ? 1 : - 1 ) ,
208
240
posPx = annPosPx [ axLetter ] ,
209
241
basePx ,
210
242
textPadShift ,
@@ -295,6 +327,9 @@ function drawOne(gd, index) {
295
327
posPx . text -= shiftMinus ;
296
328
}
297
329
}
330
+
331
+ posPx . tail += overallShift ;
332
+ posPx . head += overallShift ;
298
333
}
299
334
else {
300
335
// with no arrow, the text rotates and *then* we put the anchor
@@ -304,6 +339,10 @@ function drawOne(gd, index) {
304
339
posPx . text = basePx + textShift ;
305
340
}
306
341
342
+ posPx . text += overallShift ;
343
+ textShift += overallShift ;
344
+ textPadShift += overallShift ;
345
+
307
346
// padplus/minus are used by autorange
308
347
options [ '_' + axLetter + 'padplus' ] = ( annSize / 2 ) + textPadShift ;
309
348
options [ '_' + axLetter + 'padminus' ] = ( annSize / 2 ) - textPadShift ;
@@ -493,21 +532,17 @@ function drawOne(gd, index) {
493
532
494
533
update [ annbase + '.x' ] = xa ?
495
534
xa . p2r ( xa . r2p ( options . x ) + dx ) :
496
- ( ( headX + dx - gs . l ) / gs . w ) ;
535
+ ( options . x + ( dx / gs . w ) ) ;
497
536
update [ annbase + '.y' ] = ya ?
498
537
ya . p2r ( ya . r2p ( options . y ) + dy ) :
499
- ( 1 - ( ( headY + dy - gs . t ) / gs . h ) ) ;
538
+ ( options . y - ( dy / gs . h ) ) ;
500
539
501
540
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 ) ;
505
542
}
506
543
507
544
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 ) ;
511
546
}
512
547
513
548
arrowGroup . attr ( 'transform' , 'translate(' + dx + ',' + dy + ')' ) ;
@@ -563,7 +598,8 @@ function drawOne(gd, index) {
563
598
if ( xa ) update [ annbase + '.x' ] = options . x + dx / xa . _m ;
564
599
else {
565
600
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 ;
567
603
568
604
update [ annbase + '.x' ] = dragElement . align ( xLeft + dx / gs . w ,
569
605
widthFraction , 0 , 1 , options . xanchor ) ;
@@ -572,7 +608,8 @@ function drawOne(gd, index) {
572
608
if ( ya ) update [ annbase + '.y' ] = options . y + dy / ya . _m ;
573
609
else {
574
610
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 ;
576
613
577
614
update [ annbase + '.y' ] = dragElement . align ( yBottom - dy / gs . h ,
578
615
heightFraction , 0 , 1 , options . yanchor ) ;
0 commit comments