@@ -698,8 +698,8 @@ function toMoveInsideBar(x0, x1, y0, y1, textBB, opts) {
698698 if ( isStart || isEnd ) {
699699 var extrapad = ( isHorizontal ? t . x : t . y ) / 2 ;
700700
701- if ( r && ( hasB || isEnd ) ) {
702- extrapad += padForRounding ;
701+ if ( r && ( isEnd || hasB ) ) {
702+ textpad += padForRounding ;
703703 }
704704
705705 var dir = isHorizontal ? dirSign ( x0 , x1 ) : dirSign ( y0 , y1 ) ;
@@ -744,22 +744,13 @@ function scaleTextForRoundedBar(x0, x1, y0, y1, t, r, isHorizontal, hasB) {
744744 var a , b , c ;
745745 var scale , pad ;
746746
747- // Calculate how much extra padding is needed for bar
748- // TODO: This is the equation I worked out, but it seems to give a value that's too small
749- if ( isHorizontal ) {
750- pad = Math . max ( 0 , R - Math . sqrt ( R * R + ( t . y - barHeight ) / 2 - R ) ) ;
751- } else {
752- pad = Math . max ( 0 , R - Math . sqrt ( R * R + ( t . x - barWidth ) / 2 - R ) ) ;
753- }
754747
755748 if ( t . y / t . x >= barHeight / ( barWidth - rX ) ) {
756749 // Case 1 (Tall text)
757750 scale = barHeight / t . y ;
758- pad = 0 ;
759751 } else if ( t . y / t . x <= ( barHeight - rY ) / barWidth ) {
760752 // Case 2 (Wide text)
761753 scale = barWidth / t . x ;
762- pad = 0 ;
763754 } else if ( ! hasB && isHorizontal ) {
764755 // Case 3a (Quadratic case, two side corners are rounded)
765756 a = t . x * t . x + t . y * t . y / 4 ;
@@ -780,6 +771,13 @@ function scaleTextForRoundedBar(x0, x1, y0, y1, t, r, isHorizontal, hasB) {
780771 c = ( R - barHeight / 2 ) * ( R - barHeight / 2 ) + ( R - barWidth / 2 ) * ( R - barWidth / 2 ) - R * R ;
781772 scale = ( - b + Math . sqrt ( b * b - 4 * a * c ) ) / ( 2 * a ) ;
782773 }
774+
775+ if ( isHorizontal ) {
776+ pad = Math . max ( 0 , R - Math . sqrt ( ( barHeight - t . y * scale ) * ( R + ( barHeight - t . y * scale ) / 4 ) ) ) || 0 ;
777+ } else {
778+ pad = Math . max ( 0 , R - Math . sqrt ( ( barWidth - t . x * scale ) * ( R + ( barWidth - t . x * scale ) / 4 ) ) ) || 0 ;
779+ }
780+
783781 return { scale : scale , pad : pad } ;
784782}
785783
0 commit comments