0

I've tried everything I can find suggested elsewhere and I've also tried every permutation of the code you can see below and I just cannot crack this.

The plot itself is working great there isn't an issue there. I have a certain screen in my application that I want to draw an OxyPlot onto this view but rotate 90 degrees to suit the data better (for various reasons the application is currently locked to portrait).

The code in the view is:

private void CreatePlotChart()
{
    var normalRect = new CGRect(0,0, View.Frame.Width, View.Frame.Height);
    var rotatedRect = new CGRect(0, 0, View.Frame.Height, View.Frame.Width); // height and width swapped

    var plot = new PlotView();

    var radians = -90d.ToRadians();

    plot.Transform = CGAffineTransform.MakeRotation((nfloat)radians);
    // plot.Frame = normalRect;
    plot.Model = ViewModel.Model;
    // plot.InvalidatePlot(true); // no discernable effect
    Add(plot);

    // plot.Draw(rotatedRect); // context error

    View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();

    View.AddConstraints(
        plot.AtTopOf(View),
        plot.AtLeftOf(View),
        plot.WithSameHeight(View),
        plot.WithSameWidth(View),
        plot.AtBottomOf(View)
        );
}

The code above results in a chart as shown below, I also get this exact same chart if I pass in the rotatedRect to the constructor new PlotView(rotatedRect):

enter image description here

If I remove the use of constraints and pass in the rotatedRect like this:

private void CreatePlotChart()
{
    var normalRect = new CGRect(0,0, View.Frame.Width, View.Frame.Height);
    var rotatedRect = new CGRect(0, 0, View.Frame.Height, View.Frame.Width); // height and width swapped

    var plot = new PlotView(rotatedRect);

    var radians = -90d.ToRadians();

    plot.Transform = CGAffineTransform.MakeRotation((nfloat)radians);
    // plot.Frame = normalRect;
    plot.Model = ViewModel.Model;
    // plot.InvalidatePlot(true); // no discernable effect
    Add(plot);

    // plot.Draw(rotatedRect); // context error

    // View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();

    //View.AddConstraints(
    //    plot.AtTopOf(View),
    //    plot.AtLeftOf(View),
    //    plot.WithSameHeight(View),
    //    plot.WithSameWidth(View),
    //    plot.AtBottomOf(View)
    //    );
}

I get a lot closer to the desired effect, as can be seen below:

enter image description here

If I go another step and "reset" it's frame to the cached normalRect I get even closer, with this:

enter image description here

All of these attempts feel too hacky. What is the best way of achieving the chart manipulation I need and maintaining the use of constraints to make sure things are positioned properly?

Update

If after the first chart is drawn and I kick off another select of data, the exact same code rendered the chart exactly correctly:

enter image description here

This is also 100% repeatable so I think this might be a bug in OxyPlot or some odd side effect of the way I'm using it.

Jammer
  • 9,969
  • 11
  • 68
  • 115

0 Answers0