(x0, x1, y0, y1, textBB, opts)
| 757 | } |
| 758 | |
| 759 | function toMoveInsideBar(x0, x1, y0, y1, textBB, opts) { |
| 760 | var isHorizontal = !!opts.isHorizontal; |
| 761 | var constrained = !!opts.constrained; |
| 762 | var angle = opts.angle || 0; |
| 763 | var anchor = opts.anchor; |
| 764 | var isEnd = anchor === 'end'; |
| 765 | var isStart = anchor === 'start'; |
| 766 | var leftToRight = opts.leftToRight || 0; // left: -1, center: 0, right: 1 |
| 767 | var toRight = (leftToRight + 1) / 2; |
| 768 | var toLeft = 1 - toRight; |
| 769 | var hasB = opts.hasB; |
| 770 | var r = opts.r; |
| 771 | var overhead = opts.overhead; |
| 772 | |
| 773 | var textWidth = textBB.width; |
| 774 | var textHeight = textBB.height; |
| 775 | |
| 776 | var lx = Math.abs(x1 - x0); |
| 777 | var ly = Math.abs(y1 - y0); |
| 778 | |
| 779 | // compute remaining space |
| 780 | var textpad = lx > 2 * TEXTPAD && ly > 2 * TEXTPAD ? TEXTPAD : 0; |
| 781 | |
| 782 | lx -= 2 * textpad; |
| 783 | ly -= 2 * textpad; |
| 784 | |
| 785 | var rotate = getRotateFromAngle(angle); |
| 786 | if ( |
| 787 | angle === 'auto' && |
| 788 | !(textWidth <= lx && textHeight <= ly) && |
| 789 | (textWidth > lx || textHeight > ly) && |
| 790 | (!(textWidth > ly || textHeight > lx) || textWidth < textHeight !== lx < ly) |
| 791 | ) { |
| 792 | rotate += 90; |
| 793 | } |
| 794 | |
| 795 | var t = getRotatedTextSize(textBB, rotate); |
| 796 | |
| 797 | var scale, padForRounding; |
| 798 | // Scale text for rounded bars |
| 799 | if (r && r - overhead > TEXTPAD) { |
| 800 | var scaleAndPad = scaleTextForRoundedBar(x0, x1, y0, y1, t, r, overhead, isHorizontal, hasB); |
| 801 | scale = scaleAndPad.scale; |
| 802 | padForRounding = scaleAndPad.pad; |
| 803 | // Scale text for non-rounded bars |
| 804 | } else { |
| 805 | scale = 1; |
| 806 | if (constrained) { |
| 807 | scale = Math.min(1, lx / t.x, ly / t.y); |
| 808 | } |
| 809 | padForRounding = 0; |
| 810 | } |
| 811 | |
| 812 | // compute text and target positions |
| 813 | var textX = textBB.left * toLeft + textBB.right * toRight; |
| 814 | var textY = (textBB.top + textBB.bottom) / 2; |
| 815 | var targetX = (x0 + TEXTPAD) * toLeft + (x1 - TEXTPAD) * toRight; |
| 816 | var targetY = (y0 + y1) / 2; |
no test coverage detected
searching dependent graphs…