(x0, x1, y0, y1, textBB, opts)
| 921 | } |
| 922 | |
| 923 | function toMoveOutsideBar(x0, x1, y0, y1, textBB, opts) { |
| 924 | var isHorizontal = !!opts.isHorizontal; |
| 925 | var constrained = !!opts.constrained; |
| 926 | var angle = opts.angle || 0; |
| 927 | |
| 928 | var textWidth = textBB.width; |
| 929 | var textHeight = textBB.height; |
| 930 | var lx = Math.abs(x1 - x0); |
| 931 | var ly = Math.abs(y1 - y0); |
| 932 | |
| 933 | var textpad; |
| 934 | // Keep the padding so the text doesn't sit right against |
| 935 | // the bars, but don't factor it into barWidth |
| 936 | if (isHorizontal) { |
| 937 | textpad = ly > 2 * TEXTPAD ? TEXTPAD : 0; |
| 938 | } else { |
| 939 | textpad = lx > 2 * TEXTPAD ? TEXTPAD : 0; |
| 940 | } |
| 941 | |
| 942 | // compute rotate and scale |
| 943 | var scale = 1; |
| 944 | if (constrained) { |
| 945 | scale = isHorizontal ? Math.min(1, ly / textHeight) : Math.min(1, lx / textWidth); |
| 946 | } |
| 947 | |
| 948 | var rotate = getRotateFromAngle(angle); |
| 949 | var t = getRotatedTextSize(textBB, rotate); |
| 950 | |
| 951 | // compute text and target positions |
| 952 | var extrapad = (isHorizontal ? t.x : t.y) / 2; |
| 953 | var textX = (textBB.left + textBB.right) / 2; |
| 954 | var textY = (textBB.top + textBB.bottom) / 2; |
| 955 | var targetX = (x0 + x1) / 2; |
| 956 | var targetY = (y0 + y1) / 2; |
| 957 | var anchorX = 0; |
| 958 | var anchorY = 0; |
| 959 | |
| 960 | var dir = isHorizontal ? dirSign(x1, x0) : dirSign(y0, y1); |
| 961 | if (isHorizontal) { |
| 962 | targetX = x1 - dir * textpad; |
| 963 | anchorX = dir * extrapad; |
| 964 | } else { |
| 965 | targetY = y1 + dir * textpad; |
| 966 | anchorY = -dir * extrapad; |
| 967 | } |
| 968 | |
| 969 | return { |
| 970 | textX: textX, |
| 971 | textY: textY, |
| 972 | targetX: targetX, |
| 973 | targetY: targetY, |
| 974 | anchorX: anchorX, |
| 975 | anchorY: anchorY, |
| 976 | scale: scale, |
| 977 | rotate: rotate |
| 978 | }; |
| 979 | } |
| 980 |
no test coverage detected
searching dependent graphs…