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

Rotations between 180-360 degrees on x axis labels #5246

Closed
wants to merge 6 commits into from

Conversation

teroman
Copy link
Contributor

@teroman teroman commented Feb 7, 2018

Text rotated -90° does not work correctly, example at this fiddle : https://jsfiddle.net/thLyc5wh/7/

Changes are

  1. Take abs() of sin/cos when measuring text so that sizes are always positive. Text was measured as having a negative width.
  2. Move label drawing offset by the text length so that it is drawn outside the chart area, below the axis.

@teroman
Copy link
Contributor Author

teroman commented Feb 7, 2018

image

Sample image, before and after this change

Copy link
Member

@etimberg etimberg left a comment

Choose a reason for hiding this comment

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

Left a comment on the code. I would say that a test needs to be written for this otherwise it's pretty easy for it to accidentally get removed later

var yRotationOffset = 0;

if (me.labelRotation < 0) {
var longestText = helpers.longestText(context, tickFont.font, labelsFromTicks(ticks), me.longestTextCache);
Copy link
Member

Choose a reason for hiding this comment

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

I think you can avoid looking this up by using me.longestLabelWidth

@teroman
Copy link
Contributor Author

teroman commented Feb 8, 2018

Updated the longestLabelWidth as you recommended, but I'm not sure were to go to write the test. Is there a similar example I could take inspiration from?

@etimberg
Copy link
Member

etimberg commented Feb 8, 2018

In terms of a test, I think this is a good test to use #3988 @simonbrunel thoughts?

@simonbrunel
Copy link
Member

Unfortunately, image based tests don't work when there is text because font rendering is not stable between browsers.

Text rotated -90° does not work correctly, example at this fiddle : https://jsfiddle.net/thLyc5wh/1/

Changes are
1) Take abs() of sin/cos when measuring text so that sizes are always positive. Text was measured as having a negative width.
2) Move label drawing offset by the text length so that it is drawn outside the chart area, below the axis.
@benmccann
Copy link
Contributor

benmccann commented May 23, 2018

@etimberg @simonbrunel do you still want a test written for this one? If so, do you have any advice on how it could be tested?

@benmccann benmccann changed the title Negative rotations on x axis labels Rotations between 180-360 degrees on x axis labels Aug 1, 2018
@@ -709,6 +709,12 @@ module.exports = Element.extend({
var xTickEnd = options.position === 'right' ? me.left + tl : me.right;
var yTickStart = options.position === 'bottom' ? me.top + axisWidth : me.bottom - tl - axisWidth;
var yTickEnd = options.position === 'bottom' ? me.top + axisWidth + tl : me.bottom + axisWidth;
var yRotationOffset = 0;

if (me.labelRotation < 0) {
Copy link
Contributor

@benmccann benmccann Aug 1, 2018

Choose a reason for hiding this comment

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

This doesn't seem right. What if the labelRotation is 270 degrees? We should make sure it works in that case as well. I think what you want is to check if (Math.sin(labelRotationRadians) < 0) ?

@benmccann
Copy link
Contributor

@teroman would you be able to update this to address my comment?

@benmccann
Copy link
Contributor

@teroman would you be able to give this PR another look?

@benmccann
Copy link
Contributor

@teroman would you be able to update this PR to address the comment?

@benmccann
Copy link
Contributor

@teroman we'd love to get this PR in. Just a quick reminder that there's a pending comment

@benmccann
Copy link
Contributor

@teroman are you giving up on this PR? I'd love to get it in if you can quickly respond to the issue I raised

@benmccann
Copy link
Contributor

I'm closing this PR given the lack of response. Please feel free to reopen if you're able to update it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants