Skip to content

Commit 85dacd7

Browse files
authored
Merge pull request #1011 from plotly/fix-text-animation
Adjust d3 update to enable text mode animation
2 parents 293f201 + 2ca2443 commit 85dacd7

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/components/drawing/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ drawing.textPointStyle = function(s, trace) {
343343
s.each(function(d) {
344344
var p = d3.select(this),
345345
text = d.tx || trace.text;
346+
346347
if(!text || Array.isArray(text)) {
347348
// isArray test handles the case of (intentionally) missing
348349
// or empty text within a text array

src/traces/scatter/plot.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,21 +443,34 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
443443
}
444444

445445
// text points
446-
447446
selection = s.selectAll('g');
448-
449447
join = selection.data(textFilter, keyFunc);
450448

451449
// each text needs to go in its own 'g' in case
452450
// it gets converted to mathjax
453-
join.enter().append('g')
454-
.append('text');
451+
join.enter().append('g').append('text');
455452

456453
join.each(function(d) {
457-
var sel = d3.select(this).select('text');
454+
var sel = transition(d3.select(this).select('text'));
458455
Drawing.translatePoint(d, sel, xa, ya);
459456
});
460457

458+
join.selectAll('text')
459+
.call(Drawing.textPointStyle, trace)
460+
.each(function(d) {
461+
462+
// This just *has* to be totally custom becuase of SVG text positioning :(
463+
// It's obviously copied from translatePoint; we just can't use that
464+
//
465+
// put xp and yp into d if pixel scaling is already done
466+
var x = d.xp || xa.c2p(d.x),
467+
y = d.yp || ya.c2p(d.y);
468+
469+
d3.select(this).selectAll('tspan').each(function() {
470+
transition(d3.select(this)).attr({x: x, y: y});
471+
});
472+
});
473+
461474
join.exit().remove();
462475
}
463476

0 commit comments

Comments
 (0)