Skip to content

Commit 35538d6

Browse files
committed
reduce the number of calls to compute newSvg width & height
1 parent 13b0212 commit 35538d6

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/lib/svg_text_utils.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ var LINE_SPACING = require('../constants/alignment').LINE_SPACING;
1111

1212
// text converter
1313

14-
function getSize(_selection, _dimension) {
15-
return _selection.node().getBoundingClientRect()[_dimension];
16-
}
17-
1814
var FIND_TEX = /([^$]*)([$]+[^$]*[$]+)([^$]*)/;
1915

2016
exports.convertToTspans = function(_context, gd, _callback) {
@@ -109,16 +105,17 @@ exports.convertToTspans = function(_context, gd, _callback) {
109105
var g = newSvg.select('g');
110106
g.attr({fill: fill, stroke: fill});
111107

112-
var newSvgW = getSize(g, 'width');
113-
var newSvgH = getSize(g, 'height');
108+
var gBB = g.node().getBoundingClientRect();
109+
var newSvgW = gBB.width;
110+
var newSvgH = gBB.height;
114111

115112
var x = +_context.attr('x');
116113
var y = +_context.attr('y');
117114

118115
var newX = x - newSvgW *
119116
{start: 0, middle: 0.5, end: 1}[_context.attr('text-anchor') || 'start'];
120117
// font baseline is about 1/4 fontSize below centerline
121-
var textHeight = fontSize || getSize(_context, 'height');
118+
var textHeight = fontSize || _context.node().getBoundingClientRect().height;
122119
var dy = -textHeight / 4;
123120

124121
if(svgClass[0] === 'y') {

0 commit comments

Comments
 (0)