Measure rotated labels

Oystein Bjorke 4 years ago 0
This discussion was imported from CodePlex

anomistu wrote at 2012-03-28 16:58:

Just an fyi for this...

If ever you want to set the angle of an axis for displaying rotated major labels, you may want to correct the AxisBase.Measure method with the angle. Here's one quick way to do it:

...

double radians = this.Angle * Math.PI / 180;
var maximumTextSize = new OxySize();
foreach (double v in majorLabelValues)
{
    string s = this.FormatValue(v);
    OxySize size = rc.MeasureText(s, this.ActualFont, this.FontSize, this.FontWeight, this.Angle);
    size = new OxySize(
        Math.Abs(size.Width * Math.Cos(radians) + size.Height * Math.Sin(radians)),
        Math.Abs(size.Width * Math.Sin(radians) + size.Height * Math.Cos(radians)));
...

anomistu wrote at 2012-03-28 18:41:

Fixed (I hope) by bringing to first quadrant:

double radians = Math.Abs(this.Angle) * Math.PI / 180;
var maximumTextSize = new OxySize();
foreach (double v in majorLabelValues)
{
    string s = this.FormatValue(v);
    OxySize size = rc.MeasureText(s, this.ActualFont, this.FontSize, this.FontWeight, this.Angle);
    if (radians > Math.PI / 2)
        radians = Math.PI - radians;
    size = new OxySize(
        size.Width * Math.Cos(radians) + size.Height * Math.Sin(radians),
        size.Width * Math.Sin(radians) + size.Height * Math.Cos(radians));

objo wrote at 2012-03-30 13:23:

thanks, I will have a look at this! But isn't it necessary to check all 4 corners of the text bounding box to get the correct extents?


chage wrote at 2014-02-12 00:19:

Hi guys,
I changed the axis code according to above example to handle rotated label. Things look great on WPF but the PDF export has the label overlapped with the axis, can you advise how to fix this as well?

Image
CodePlex