Skip to content

Commit d223e47

Browse files
committed
Inverse-transform text on layout transition
1 parent e54d009 commit d223e47

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/plots/cartesian/transition_axes.js

+32-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ var Drawing = require('../../components/drawing');
1717
var Axes = require('./axes');
1818
var axisRegex = /((x|y)([2-9]|[1-9][0-9]+)?)axis$/;
1919

20+
var LAST_TRANSLATION_RE = /translate\([^)]*\)\s*$/;
21+
2022
module.exports = function transitionAxes(gd, newLayout, transitionOpts, makeOnCompleteCallback) {
2123
var fullLayout = gd._fullLayout;
2224
var axes = [];
@@ -149,7 +151,15 @@ module.exports = function transitionAxes(gd, newLayout, transitionOpts, makeOnCo
149151
// scale to individual points to counteract the scale of the trace
150152
// as a whole:
151153
.selectAll('.points').selectAll('.point')
152-
.call(Drawing.setPointGroupScale, 1, 1);
154+
.call(Drawing.setPointGroupScale, 1, 1)
155+
156+
subplot.plot.selectAll('.points').selectAll('g')
157+
.each(function () {
158+
var el = d3.select(this);
159+
var existingTransform = el.attr('transform').match(LAST_TRANSLATION_RE);
160+
el.attr('transform', existingTransform || '');
161+
});
162+
153163

154164
}
155165

@@ -229,6 +239,27 @@ module.exports = function transitionAxes(gd, newLayout, transitionOpts, makeOnCo
229239
.selectAll('.points').selectAll('.point')
230240
.call(Drawing.setPointGroupScale, 1 / xScaleFactor, 1 / yScaleFactor);
231241

242+
subplot.plot.selectAll('.points').selectAll('g')
243+
.each(function () {
244+
var el = d3.select(this);
245+
var text = el.select('text');
246+
var x = parseFloat(text.attr('x'));
247+
var y = parseFloat(text.attr('y'));
248+
249+
var existingTransform = el.attr('transform').match(LAST_TRANSLATION_RE);
250+
251+
var transforms = [
252+
'translate(' + x + ',' + y + ')',
253+
'scale(' + (1 / xScaleFactor) + ',' + (1 / yScaleFactor) + ')',
254+
'translate(' + (-x) + ',' + (-y) + ')',
255+
];
256+
257+
if (existingTransform) {
258+
transforms.push(existingTransform);
259+
}
260+
261+
el.attr('transform', transforms.join(' '));
262+
});
232263
}
233264

234265
var onComplete;

0 commit comments

Comments
 (0)