Skip to content

Adjust d3 update to enable text mode animation #1011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ drawing.textPointStyle = function(s, trace) {
s.each(function(d) {
var p = d3.select(this),
text = d.tx || trace.text;

if(!text || Array.isArray(text)) {
// isArray test handles the case of (intentionally) missing
// or empty text within a text array
Expand Down
23 changes: 18 additions & 5 deletions src/traces/scatter/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,21 +443,34 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
}

// text points

selection = s.selectAll('g');

join = selection.data(textFilter, keyFunc);

// each text needs to go in its own 'g' in case
// it gets converted to mathjax
join.enter().append('g')
.append('text');
join.enter().append('g').append('text');

join.each(function(d) {
var sel = d3.select(this).select('text');
var sel = transition(d3.select(this).select('text'));
Drawing.translatePoint(d, sel, xa, ya);
});

join.selectAll('text')
.call(Drawing.textPointStyle, trace)
.each(function(d) {

// This just *has* to be totally custom becuase of SVG text positioning :(
// It's obviously copied from translatePoint; we just can't use that
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: technically I think maybe translatePoint would work. I'm not 100% certain how much work it is to recompute the positions a bunch, but it seems silly to do that for every tspan.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha. That's not too bad. Thanks for the comment!

//
// put xp and yp into d if pixel scaling is already done
var x = d.xp || xa.c2p(d.x),
y = d.yp || ya.c2p(d.y);

d3.select(this).selectAll('tspan').each(function() {
transition(d3.select(this)).attr({x: x, y: y});
});
});

join.exit().remove();
}

Expand Down