Skip to content

Inverse-transform text on layout transition #1616

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 5 commits into from
May 10, 2017
Merged

Conversation

rreusser
Copy link
Contributor

@rreusser rreusser commented Apr 21, 2017

Addresses #1608. cc @alexcjohnson @n-riesco

See: http://rreusser.github.io/demos/plotly-unsupported/text-transition.html

(The hover/click behavior is frustratingly finicky, but that's a separate issue. Also the date axes just return NaN which is why things are weird with dates. That's not addressed here.)

As for this PR, I'm a little worried .points g is too general a selector, so may need to add a class on text points to ensure only text is selected/modified by this tweak. Finally the transform logic is more than a little weird/ugly, but there's probably no avoiding that.

@@ -17,6 +17,8 @@ var Drawing = require('../../components/drawing');
var Axes = require('./axes');
var axisRegex = /((x|y)([2-9]|[1-9][0-9]+)?)axis$/;

var LAST_TRANSLATION_RE = /translate\([^)]*\)\s*$/;
Copy link
Contributor Author

@rreusser rreusser Apr 21, 2017

Choose a reason for hiding this comment

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

Note: this will break or at least do something very unexpected if the last transform is not a vertical offset for the text. Not sure how to handle that more generally. The general pattern of parsing existing transforms with regular expressions is fragile but unavoidable without lots of changes to how things work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you just use Drawing.getTranslate instead?

Copy link
Contributor Author

@rreusser rreusser Apr 24, 2017

Choose a reason for hiding this comment

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

No, for two reasons, I think. First, the drawing function doesn't get the last translation explicitly, and second, it teases apart the numbers involved, which is unnecessary here. We only need to preserve the last transform without modification, not parse and reconstruct it.

@alexcjohnson
Copy link
Collaborator

Adding a class to text groups seems like a great idea - there aren't too many places this would be needed, and then we could ensure this is targeted exactly where we want it. For example, bars with text (eg test_dashboard/#bar_attrs_relative) often the text gets autosized, with a maximum font size that shrinks to fit if necessary, and even auto rotation. This seems like a disaster to replicate on the fly, so I'd vote to just omit bar text from this effect at least for now.

Make sure it works with axis drag zooms and scroll zooms too!

@etpinard etpinard added status: in progress bug something broken labels Apr 24, 2017
@rreusser rreusser force-pushed the text-layout-transition branch from a1f2138 to bf600bc Compare May 2, 2017 16:33
@rreusser
Copy link
Contributor Author

rreusser commented May 2, 2017

@alexcjohnson I've pushed a fix that fixes an error I'd made in applying the class and have refactored things into a method that sets the scale for a group of text points. The result works with transitions and zooming:

ezgif-1-0a5d3c4b7c

Last step is to 🔒 the drawing method logic with a quick test. Need to head back to conference, but will do that asap.

@etpinard etpinard added this to the 1.27.0 milestone May 3, 2017
@rreusser
Copy link
Contributor Author

rreusser commented May 3, 2017

Okay, added test. I'm 😄

@etpinard
Copy link
Contributor

etpinard commented May 9, 2017

💃

@rreusser rreusser merged commit 28f4a05 into master May 10, 2017
@rreusser rreusser deleted the text-layout-transition branch May 10, 2017 13:06
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.

3 participants