@@ -772,18 +772,19 @@ function createHoverText(hoverData, opts, gd) {
772772 var commonBgColor = commonLabelOpts . bgcolor || Color . defaultLine ;
773773 var commonStroke = commonLabelOpts . bordercolor || Color . contrast ( commonBgColor ) ;
774774 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+ } ;
775780
776781 lpath . style ( {
777782 fill : commonBgColor ,
778783 stroke : commonStroke
779784 } ) ;
780785
781786 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 )
787788 . call ( svgTextUtils . positionText , 0 , 0 )
788789 . call ( svgTextUtils . convertToTspans , gd ) ;
789790
@@ -861,23 +862,39 @@ function createHoverText(hoverData, opts, gd) {
861862 'H' + leftsign + HOVERARROWSIZE + 'V-' + HOVERARROWSIZE + 'Z' ) ;
862863
863864 var halfHeight = tbb . height / 2 ;
865+ var lty = outerTop - tbb . top - halfHeight ;
864866 var clipId = 'clip' + fullLayout . _uid + 'commonlabel' + ya . _id ;
865867 var clipPath ;
866- var ltx ;
867868
868869 if ( lx < ( tbb . width + 2 * HOVERTEXTPAD + HOVERARROWSIZE ) ) {
869- ltx = tbb . width - lx + HOVERTEXTPAD ;
870870 clipPath = 'M-' + ( HOVERARROWSIZE + HOVERTEXTPAD ) + '-' + halfHeight +
871871 'h-' + ( tbb . width - HOVERTEXTPAD ) +
872872 'V' + halfHeight +
873873 '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+ }
874893 } else {
875- ltx = sgn * ( HOVERTEXTPAD + HOVERARROWSIZE ) ;
894+ svgTextUtils . positionText ( ltext , sgn * ( HOVERTEXTPAD + HOVERARROWSIZE ) , lty ) ;
876895 clipPath = null ;
877896 }
878897
879- svgTextUtils . positionText ( ltext , ltx , outerTop - tbb . top - halfHeight ) ;
880-
881898 var textClip = fullLayout . _topclips . selectAll ( '#' + clipId ) . data ( clipPath ? [ 0 ] : [ ] ) ;
882899 textClip . enter ( ) . append ( 'clipPath' ) . attr ( 'id' , clipId ) . append ( 'path' ) ;
883900 textClip . exit ( ) . remove ( ) ;
0 commit comments