@@ -303,32 +303,34 @@ function getTransformToMoveInsideBar(x0, x1, y0, y1, textBB, orientation) {
303
303
else textpad = 0 ;
304
304
305
305
// compute rotation and scale
306
- var needsRotating ,
306
+ var rotate ,
307
307
scale ;
308
308
309
309
if ( textWidth <= barWidth && textHeight <= barHeight ) {
310
310
// no scale or rotation is required
311
- needsRotating = false ;
311
+ rotate = false ;
312
312
scale = 1 ;
313
313
}
314
314
else if ( textWidth <= barHeight && textHeight <= barWidth ) {
315
315
// only rotation is required
316
- needsRotating = true ;
316
+ rotate = true ;
317
317
scale = 1 ;
318
318
}
319
319
else if ( ( textWidth < textHeight ) === ( barWidth < barHeight ) ) {
320
320
// only scale is required
321
- needsRotating = false ;
321
+ rotate = false ;
322
322
scale = Math . min ( barWidth / textWidth , barHeight / textHeight ) ;
323
323
}
324
324
else {
325
325
// both scale and rotation are required
326
- needsRotating = true ;
326
+ rotate = true ;
327
327
scale = Math . min ( barHeight / textWidth , barWidth / textHeight ) ;
328
328
}
329
329
330
+ if ( rotate ) rotate = - 90 ; // rotate counter-clockwise
331
+
330
332
// compute text and target positions
331
- if ( needsRotating ) {
333
+ if ( rotate ) {
332
334
targetWidth = scale * textHeight ;
333
335
targetHeight = scale * textWidth ;
334
336
}
@@ -360,7 +362,7 @@ function getTransformToMoveInsideBar(x0, x1, y0, y1, textBB, orientation) {
360
362
}
361
363
}
362
364
363
- return getTransform ( textX , textY , targetX , targetY , scale , needsRotating ) ;
365
+ return getTransform ( textX , textY , targetX , targetY , scale , rotate ) ;
364
366
}
365
367
366
368
function getTransformToMoveOutsideBar ( x0 , x1 , y0 , y1 , textBB , orientation ) {
@@ -388,28 +390,28 @@ function getTransformToMoveOutsideBar(x0, x1, y0, y1, textBB, orientation) {
388
390
}
389
391
390
392
// compute rotation and scale
391
- var needsRotating ,
393
+ var rotate ,
392
394
scale ;
393
395
if ( textWidth <= barWidth ) {
394
396
// no scale or rotation
395
- needsRotating = false ;
397
+ rotate = false ;
396
398
scale = 1 ;
397
399
}
398
400
else if ( textHeight <= textWidth ) {
399
401
// only scale
400
402
// (don't rotate to prevent having text perpendicular to the bar)
401
- needsRotating = false ;
403
+ rotate = false ;
402
404
scale = barWidth / textWidth ;
403
405
}
404
406
else if ( textHeight <= barWidth ) {
405
407
// only rotation
406
- needsRotating = true ;
408
+ rotate = true ;
407
409
scale = 1 ;
408
410
}
409
411
else {
410
412
// both scale and rotation
411
413
// (rotation prevents having text perpendicular to the bar)
412
- needsRotating = true ;
414
+ rotate = true ;
413
415
scale = barWidth / textHeight ;
414
416
}
415
417
@@ -420,7 +422,7 @@ function getTransformToMoveOutsideBar(x0, x1, y0, y1, textBB, orientation) {
420
422
targetHeight ,
421
423
targetX ,
422
424
targetY ;
423
- if ( needsRotating ) {
425
+ if ( rotate ) {
424
426
targetWidth = scale * textBB . height ;
425
427
targetHeight = scale * textBB . width ;
426
428
}
@@ -434,28 +436,32 @@ function getTransformToMoveOutsideBar(x0, x1, y0, y1, textBB, orientation) {
434
436
// bar end is on the left hand side
435
437
targetX = x1 - textpad - targetWidth / 2 ;
436
438
targetY = ( y0 + y1 ) / 2 ;
439
+ if ( rotate ) rotate = - 90 ; // rotate counter-clockwise
437
440
}
438
441
else {
439
442
targetX = x1 + textpad + targetWidth / 2 ;
440
443
targetY = ( y0 + y1 ) / 2 ;
444
+ if ( rotate ) rotate = 90 ; // rotate clockwise
441
445
}
442
446
}
443
447
else {
444
448
if ( y1 > y0 ) {
445
449
// bar end is on the bottom
446
450
targetX = ( x0 + x1 ) / 2 ;
447
451
targetY = y1 + textpad + targetHeight / 2 ;
452
+ if ( rotate ) rotate = - 90 ; // rotate counter-clockwise
448
453
}
449
454
else {
450
455
targetX = ( x0 + x1 ) / 2 ;
451
456
targetY = y1 - textpad - targetHeight / 2 ;
457
+ if ( rotate ) rotate = 90 ; // rotate clockwise
452
458
}
453
459
}
454
460
455
- return getTransform ( textX , textY , targetX , targetY , scale , needsRotating ) ;
461
+ return getTransform ( textX , textY , targetX , targetY , scale , rotate ) ;
456
462
}
457
463
458
- function getTransform ( textX , textY , targetX , targetY , scale , needsRotating ) {
464
+ function getTransform ( textX , textY , targetX , targetY , scale , rotate ) {
459
465
var transformScale ,
460
466
transformRotate ,
461
467
transformTranslate ;
@@ -466,8 +472,8 @@ function getTransform(textX, textY, targetX, targetY, scale, needsRotating) {
466
472
transformScale = '' ;
467
473
}
468
474
469
- transformRotate = ( needsRotating ) ?
470
- 'rotate(-90 ' + textX + ' ' + textY + ') ' : '' ;
475
+ transformRotate = ( rotate ) ?
476
+ 'rotate(' + rotate + ' ' + textX + ' ' + textY + ') ' : '' ;
471
477
472
478
// Note that scaling also affects the center of the text box
473
479
var translateX = ( targetX - scale * textX ) ,
0 commit comments