@@ -772,18 +772,19 @@ function createHoverText(hoverData, opts, gd) {
772
772
var commonBgColor = commonLabelOpts . bgcolor || Color . defaultLine ;
773
773
var commonStroke = commonLabelOpts . bordercolor || Color . contrast ( commonBgColor ) ;
774
774
var contrastColor = Color . contrast ( commonBgColor ) ;
775
+ var commonLabelFont = {
776
+ family : commonLabelOpts . font . family || fontFamily ,
777
+ size : commonLabelOpts . font . size || fontSize ,
778
+ color : commonLabelOpts . font . color || contrastColor
779
+ } ;
775
780
776
781
lpath . style ( {
777
782
fill : commonBgColor ,
778
783
stroke : commonStroke
779
784
} ) ;
780
785
781
786
ltext . text ( t0 )
782
- . call ( Drawing . font ,
783
- commonLabelOpts . font . family || fontFamily ,
784
- commonLabelOpts . font . size || fontSize ,
785
- commonLabelOpts . font . color || contrastColor
786
- )
787
+ . call ( Drawing . font , commonLabelFont )
787
788
. call ( svgTextUtils . positionText , 0 , 0 )
788
789
. call ( svgTextUtils . convertToTspans , gd ) ;
789
790
@@ -861,23 +862,39 @@ function createHoverText(hoverData, opts, gd) {
861
862
'H' + leftsign + HOVERARROWSIZE + 'V-' + HOVERARROWSIZE + 'Z' ) ;
862
863
863
864
var halfHeight = tbb . height / 2 ;
865
+ var lty = outerTop - tbb . top - halfHeight ;
864
866
var clipId = 'clip' + fullLayout . _uid + 'commonlabel' + ya . _id ;
865
867
var clipPath ;
866
- var ltx ;
867
868
868
869
if ( lx < ( tbb . width + 2 * HOVERTEXTPAD + HOVERARROWSIZE ) ) {
869
- ltx = tbb . width - lx + HOVERTEXTPAD ;
870
870
clipPath = 'M-' + ( HOVERARROWSIZE + HOVERTEXTPAD ) + '-' + halfHeight +
871
871
'h-' + ( tbb . width - HOVERTEXTPAD ) +
872
872
'V' + halfHeight +
873
873
'h' + ( tbb . width - HOVERTEXTPAD ) + 'Z' ;
874
+
875
+ var ltx = tbb . width - lx + HOVERTEXTPAD ;
876
+ svgTextUtils . positionText ( ltext , ltx , lty ) ;
877
+
878
+ // shift each line (except the longest) so that start-of-line
879
+ // is always visible
880
+ if ( anchor === 'end' ) {
881
+ ltext . selectAll ( 'tspan' ) . each ( function ( ) {
882
+ var s = d3 . select ( this ) ;
883
+ var dummy = Drawing . tester . append ( 'text' )
884
+ . text ( s . text ( ) )
885
+ . call ( Drawing . font , commonLabelFont ) ;
886
+ var dummyBB = dummy . node ( ) . getBoundingClientRect ( ) ;
887
+ if ( dummyBB . width < tbb . width ) {
888
+ s . attr ( 'x' , ltx - dummyBB . width ) ;
889
+ }
890
+ dummy . remove ( ) ;
891
+ } ) ;
892
+ }
874
893
} else {
875
- ltx = sgn * ( HOVERTEXTPAD + HOVERARROWSIZE ) ;
894
+ svgTextUtils . positionText ( ltext , sgn * ( HOVERTEXTPAD + HOVERARROWSIZE ) , lty ) ;
876
895
clipPath = null ;
877
896
}
878
897
879
- svgTextUtils . positionText ( ltext , ltx , outerTop - tbb . top - halfHeight ) ;
880
-
881
898
var textClip = fullLayout . _topclips . selectAll ( '#' + clipId ) . data ( clipPath ? [ 0 ] : [ ] ) ;
882
899
textClip . enter ( ) . append ( 'clipPath' ) . attr ( 'id' , clipId ) . append ( 'path' ) ;
883
900
textClip . exit ( ) . remove ( ) ;
0 commit comments