Skip to content
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

Scatter <g textpoint> join fixup #1672

Merged
merged 4 commits into from
May 16, 2017
Merged

Scatter <g textpoint> join fixup #1672

merged 4 commits into from
May 16, 2017

Conversation

etpinard
Copy link
Contributor

fixes #1666

cc @rreusser and @n-riesco

Continuing on #1666 (comment), I found a case (see 310e67a ) where restyle was failing on blank x, y arrays without using filter transforms, so the patch had to be made in scatter/plot.js (see 49e5da5)

After this patch:

peek 2017-05-11 11-00

- return false when sel is removed i.e.
   when its x/y coords are non-numeric
- this is helpful for clearing associated <g textpoint>
- return true otherwise
@etpinard etpinard added status: reviewable bug something broken labels May 11, 2017
var g = d3.select(this);
var sel = transition(g.select('text'));
var hasTextPt = Drawing.translatePoint(d, sel, xa, ya);
if(!hasTextPt) g.remove();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Each <text> node is wrapped in a <g class="textpoint"> group. It is on this group that the data-join happens so we must make sure that group is removed whenever <text> node are removed to obtain the correct enter and merge selections on updates.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Drawing.translatePoint gets used in line 436 above too, and could short-circuit the lines after it if it removed the node.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good eyes 👁️ thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 3f7601c

return Plotly.restyle(gd, {
x: [[null, undefined, NaN]],
y: [[NaN, null, undefined]]
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

On master, this restyle call results in

d3.selectAll('.point').size() // => 0 (as desired)
d3.selectAll('.textpoint').size() // => 3 (which messes up subsequent updates)

* @return {boolean} :
* true if selection got translated
* false if selection got removed
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks 🎎 !

@alexcjohnson
Copy link
Collaborator

Great! 💃

@etpinard etpinard merged commit e58dcb0 into master May 16, 2017
@etpinard etpinard deleted the scatter-text-join-fixup branch May 16, 2017 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filter transform doesn't restore data text
3 participants