Measure rotated labels

Mar 28, 2012 at 3:58 PM

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)));
...
Mar 28, 2012 at 5:41 PM

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));
Coordinator
Mar 30, 2012 at 12:23 PM

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?

Feb 12, 2014 at 12:19 AM
Edited Feb 12, 2014 at 12:19 AM
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