Skip to content

Commit 61ade94

Browse files
committed
fix #1247 - titles avoid labels in IE
IE puts a space between numbers in transforms, even if you set them with a comma
1 parent 4aa1a45 commit 61ade94

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/components/titles/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,12 @@ Titles.draw = function(gd, titleClass, options) {
151151
else {
152152
// so we don't have to offset each avoided element,
153153
// give the title the opposite offset
154-
titlebb.left -= avoid.offsetLeft;
155-
titlebb.right -= avoid.offsetLeft;
156-
titlebb.top -= avoid.offsetTop;
157-
titlebb.bottom -= avoid.offsetTop;
154+
var offsetLeft = avoid.offsetLeft || 0,
155+
offsetTop = avoid.offsetTop || 0;
156+
titlebb.left -= offsetLeft;
157+
titlebb.right -= offsetLeft;
158+
titlebb.top -= offsetTop;
159+
titlebb.bottom -= offsetTop;
158160

159161
// iterate over a set of elements (avoid.selection)
160162
// to avoid collisions with

src/lib/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,12 @@ lib.addStyleRule = function(selector, styleString) {
451451
else lib.warn('addStyleRule failed');
452452
};
453453

454-
lib.getTranslate = function(element) {
454+
// TODO (alexcjohnson): the following translate/scale functions should
455+
// get moved to components/drawing rather than the generic lib.
455456

457+
lib.getTranslate = function(element) {
458+
// Note the separator [^\d] between x and y in this regex
459+
// We generally use ',' but IE will convert it to ' '
456460
var re = /.*\btranslate\((\d*\.?\d*)[^\d]*(\d*\.?\d*)[^\d].*/,
457461
getter = element.attr ? 'attr' : 'getAttribute',
458462
transform = element[getter]('transform') || '';

src/plots/cartesian/axes.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,13 +1897,9 @@ axes.doTicks = function(gd, axid, skipTitle) {
18971897
x,
18981898
y;
18991899
if(avoidSelection.size()) {
1900-
var avoidTransform = d3.select(avoidSelection.node().parentNode)
1901-
.attr('transform')
1902-
.match(/translate\(([-\.\d]+),([-\.\d]+)\)/);
1903-
if(avoidTransform) {
1904-
avoid.offsetLeft = +avoidTransform[1];
1905-
avoid.offsetTop = +avoidTransform[2];
1906-
}
1900+
var translation = Lib.getTranslate(avoidSelection.node().parentNode);
1901+
avoid.offsetLeft = translation.x;
1902+
avoid.offsetTop = translation.y;
19071903
}
19081904

19091905
if(axLetter === 'x') {

0 commit comments

Comments
 (0)