* Follow same interface to `Displayable.prototype.calculateTextPosition`. * @public * @param {Obejct} [out] Prepared out object. If not input, auto created in the method. * @param {module:zrender/graphic/Style} style where `textPosition` and `textDistance` are visited. * @param {Object} rect {x,
(out, style, rect)
| 7720 | * @return {Object} The input `out`. Set: {x, y, textAlign, textVerticalAlign} |
| 7721 | */ |
| 7722 | function calculateTextPosition(out, style, rect) { |
| 7723 | var textPosition = style.textPosition; |
| 7724 | var distance = style.textDistance; |
| 7725 | |
| 7726 | var x = rect.x; |
| 7727 | var y = rect.y; |
| 7728 | distance = distance || 0; |
| 7729 | |
| 7730 | var height = rect.height; |
| 7731 | var width = rect.width; |
| 7732 | var halfHeight = height / 2; |
| 7733 | |
| 7734 | var textAlign = 'left'; |
| 7735 | var textVerticalAlign = 'top'; |
| 7736 | |
| 7737 | switch (textPosition) { |
| 7738 | case 'left': |
| 7739 | x -= distance; |
| 7740 | y += halfHeight; |
| 7741 | textAlign = 'right'; |
| 7742 | textVerticalAlign = 'middle'; |
| 7743 | break; |
| 7744 | case 'right': |
| 7745 | x += distance + width; |
| 7746 | y += halfHeight; |
| 7747 | textVerticalAlign = 'middle'; |
| 7748 | break; |
| 7749 | case 'top': |
| 7750 | x += width / 2; |
| 7751 | y -= distance; |
| 7752 | textAlign = 'center'; |
| 7753 | textVerticalAlign = 'bottom'; |
| 7754 | break; |
| 7755 | case 'bottom': |
| 7756 | x += width / 2; |
| 7757 | y += height + distance; |
| 7758 | textAlign = 'center'; |
| 7759 | break; |
| 7760 | case 'inside': |
| 7761 | x += width / 2; |
| 7762 | y += halfHeight; |
| 7763 | textAlign = 'center'; |
| 7764 | textVerticalAlign = 'middle'; |
| 7765 | break; |
| 7766 | case 'insideLeft': |
| 7767 | x += distance; |
| 7768 | y += halfHeight; |
| 7769 | textVerticalAlign = 'middle'; |
| 7770 | break; |
| 7771 | case 'insideRight': |
| 7772 | x += width - distance; |
| 7773 | y += halfHeight; |
| 7774 | textAlign = 'right'; |
| 7775 | textVerticalAlign = 'middle'; |
| 7776 | break; |
| 7777 | case 'insideTop': |
| 7778 | x += width / 2; |
| 7779 | y += distance; |
no outgoing calls
no test coverage detected