Skip to content

Commit ba20321

Browse files
committed
temporary fix for firefox v82+ bounding box issue
1 parent 4253453 commit ba20321

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/lib/svg_text_utils.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,12 @@ exports.convertToTspans = function(_context, gd, _callback) {
9494
newSvg.node().firstChild);
9595
}
9696

97+
var w0 = _svgBBox.width;
98+
var h0 = _svgBBox.height;
99+
97100
newSvg.attr({
98101
'class': svgClass,
99-
height: _svgBBox.height,
102+
height: h0,
100103
preserveAspectRatio: 'xMinYMin meet'
101104
})
102105
.style({overflow: 'visible', 'pointer-events': 'none'});
@@ -105,9 +108,18 @@ exports.convertToTspans = function(_context, gd, _callback) {
105108
var g = newSvg.select('g');
106109
g.attr({fill: fill, stroke: fill});
107110

108-
var gBB = g.node().getBoundingClientRect();
109-
var newSvgW = gBB.width;
110-
var newSvgH = gBB.height;
111+
var bb = g.node().getBoundingClientRect();
112+
var w = bb.width;
113+
var h = bb.height;
114+
115+
if(w > w0 || h > h0) {
116+
// this happen in firefox v82+ | see https://bugzilla.mozilla.org/show_bug.cgi?id=1709251 addressed
117+
// temporary fix:
118+
newSvg.style('overflow', 'hidden');
119+
bb = newSvg.node().getBoundingClientRect();
120+
w = bb.width;
121+
h = bb.height;
122+
}
111123

112124
var x = +_context.attr('x');
113125
var y = +_context.attr('y');
@@ -119,21 +131,21 @@ exports.convertToTspans = function(_context, gd, _callback) {
119131
if(svgClass[0] === 'y') {
120132
mathjaxGroup.attr({
121133
transform: 'rotate(' + [-90, x, y] +
122-
')' + strTranslate(-newSvgW / 2, dy - newSvgH / 2)
134+
')' + strTranslate(-w / 2, dy - h / 2)
123135
});
124136
} else if(svgClass[0] === 'l') {
125-
y = dy - newSvgH / 2;
137+
y = dy - h / 2;
126138
} else if(svgClass[0] === 'a' && svgClass.indexOf('atitle') !== 0) {
127139
x = 0;
128140
y = dy;
129141
} else {
130142
var anchor = _context.attr('text-anchor');
131143

132-
x = x - newSvgW * (
144+
x = x - w * (
133145
anchor === 'middle' ? 0.5 :
134146
anchor === 'end' ? 1 : 0
135147
);
136-
y = y + dy - newSvgH / 2;
148+
y = y + dy - h / 2;
137149
}
138150

139151
newSvg.attr({

0 commit comments

Comments
 (0)