(g, gd, legendObj, aTitle)
| 742 | } |
| 743 | |
| 744 | function computeTextDimensions(g, gd, legendObj, aTitle) { |
| 745 | var legendItem = g.data()[0][0]; |
| 746 | var showlegend = legendItem && legendItem.trace.showlegend; |
| 747 | if (Array.isArray(showlegend)) { |
| 748 | showlegend = showlegend[legendItem.i] !== false; |
| 749 | } |
| 750 | if(!legendObj._inHover && legendItem && !showlegend) { |
| 751 | g.remove(); |
| 752 | return; |
| 753 | } |
| 754 | |
| 755 | var mathjaxGroup = g.select('g[class*=math-group]'); |
| 756 | var mathjaxNode = mathjaxGroup.node(); |
| 757 | |
| 758 | var legendId = helpers.getId(legendObj); |
| 759 | if(!legendObj) { |
| 760 | legendObj = gd._fullLayout[legendId]; |
| 761 | } |
| 762 | var bw = legendObj.borderwidth; |
| 763 | var font; |
| 764 | if(aTitle === MAIN_TITLE) { |
| 765 | font = legendObj.title.font; |
| 766 | } else if(legendItem.groupTitle) { |
| 767 | font = legendItem.groupTitle.font; |
| 768 | } else { |
| 769 | font = legendObj.font; |
| 770 | } |
| 771 | var lineHeight = font.size * LINE_SPACING; |
| 772 | var height, width; |
| 773 | |
| 774 | if(mathjaxNode) { |
| 775 | var mathjaxBB = Drawing.bBox(mathjaxNode); |
| 776 | |
| 777 | height = mathjaxBB.height; |
| 778 | width = mathjaxBB.width; |
| 779 | |
| 780 | if(aTitle === MAIN_TITLE) { |
| 781 | Drawing.setTranslate(mathjaxGroup, bw, bw + height * 0.75); |
| 782 | } else { // legend item |
| 783 | Drawing.setTranslate(mathjaxGroup, 0, height * 0.25); |
| 784 | } |
| 785 | } else { |
| 786 | var cls = '.' + legendId + ( |
| 787 | aTitle === MAIN_TITLE ? 'title' : '' |
| 788 | ) + 'text'; |
| 789 | |
| 790 | var textEl = g.select(cls); |
| 791 | |
| 792 | var textLines = svgTextUtils.lineCount(textEl); |
| 793 | var textNode = textEl.node(); |
| 794 | |
| 795 | height = lineHeight * textLines; |
| 796 | width = textNode ? Drawing.bBox(textNode).width : 0; |
| 797 | |
| 798 | // approximation to height offset to center the font |
| 799 | // to avoid getBoundingClientRect |
| 800 | if(aTitle === MAIN_TITLE) { |
| 801 | if(legendObj.title.side === 'left') { |
no outgoing calls
no test coverage detected
searching dependent graphs…