@@ -339,56 +339,22 @@ function getTransformToMoveInsideBar(x0, x1, y0, y1, textBB, orientation) {
339339}
340340
341341function getTransformToMoveOutsideBar ( x0 , x1 , y0 , y1 , textBB , orientation ) {
342- // In order to handle both orientations with the same algorithm,
343- // *textWidth* is defined as the text length in the direction of *barWidth*.
344- var barWidth ,
345- textWidth ,
346- textHeight ;
347- if ( orientation === 'h' ) {
348- barWidth = Math . abs ( y1 - y0 ) ;
349- textWidth = textBB . height ;
350- textHeight = textBB . width ;
351- }
352- else {
353- barWidth = Math . abs ( x1 - x0 ) ;
354- textWidth = textBB . width ;
355- textHeight = textBB . height ;
356- }
342+ var barWidth = ( orientation === 'h' ) ?
343+ Math . abs ( y1 - y0 ) :
344+ Math . abs ( x1 - x0 ) ,
345+ textpad ;
357346
358- // apply text padding
359- var textpad ;
347+ // apply text padding if possible
360348 if ( barWidth > 2 * TEXTPAD ) {
361349 textpad = TEXTPAD ;
362350 barWidth -= 2 * textpad ;
363351 }
364352
365353 // compute rotation and scale
366- var rotate ,
367- scale ;
368- if ( textWidth <= barWidth ) {
369- // no scale or rotation
370- rotate = false ;
371- scale = 1 ;
372- }
373- else if ( textHeight <= textWidth ) {
374- // only scale
375- // (don't rotate to prevent having text perpendicular to the bar)
376- rotate = false ;
377- scale = barWidth / textWidth ;
378- }
379- else if ( textHeight <= barWidth ) {
380- // only rotation
381- rotate = true ;
382- scale = 1 ;
383- }
384- else {
385- // both scale and rotation
386- // (rotation prevents having text perpendicular to the bar)
387- rotate = true ;
388- scale = barWidth / textHeight ;
389- }
390-
391- if ( rotate ) rotate = 90 ; // rotate clockwise
354+ var rotate = false ,
355+ scale = ( orientation === 'h' ) ?
356+ Math . min ( 1 , barWidth / textBB . height ) :
357+ Math . min ( 1 , barWidth / textBB . width ) ;
392358
393359 // compute text and target positions
394360 var textX = ( textBB . left + textBB . right ) / 2 ,
0 commit comments