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

Wrong vertical label position on rotation bar chart #4756

Closed
dmitrygorbenko opened this issue Nov 19, 2015 · 2 comments

Comments

@dmitrygorbenko
Copy link

commented Nov 19, 2015

Hi,
I found a bug when in bar chart I rotate vertical labels (specified in xAxis ) by 45 degree and it makes them display in wrong place.
It seems like what HC code calculates wrong label length and thinks it (label) should take much more size.
Try it out: http://jsfiddle.net/DimaGorbenko/b3p9xj9a/

issue

Thank you,
Dima

@dmitrygorbenko

This comment has been minimized.

Copy link
Author

commented Nov 19, 2015

here is what I've found: file hightcharts.js function getLabelPosition:

yOffset = mathCos(label.rotation * deg2rad) * (rotCorr.y - label.getBBox().height / 2);

this offset moves the label to the top taking into account:

  1. angle
  2. position of the rotCorr
  3. height of the label

The problem what label.getBBox() returns "rotated height", while that line of code assumes what "label.getBBox().height" is the height of the not-rotated label (that's why it divides it by 2 --- to place it in center).

Here is my patch which fixed this case:

                var labelHeight, savedAngle = label.rotation;
                label.rotation = 0;
                labelHeight = label.getBBox().height;
                label.rotation = savedAngle;

                yOffset = mathCos(label.rotation * deg2rad) * (rotCorr.y - labelHeight / 2);

@dmitrygorbenko dmitrygorbenko changed the title Wrong calculation of label length on rotation Wrong calculation of Y label position on rotation bar chart Nov 19, 2015

@dmitrygorbenko dmitrygorbenko changed the title Wrong calculation of Y label position on rotation bar chart Wrong vertical label position on rotation bar chart Nov 19, 2015

@TorsteinHonsi

This comment has been minimized.

Copy link
Collaborator

commented Nov 24, 2015

Drag the handle to see the issue clearly: http://jsfiddle.net/highcharts/b3p9xj9a/2/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.