Anton

Anton

  • NA
  • 1
  • 1.2k

OxyPlot axis always null

Jun 19 2015 5:38 AM
I have problem with OxyPlot Library. I do npt understand why it's working so weird. 
For example why  "double temp1 = XAxis.Transform(this.MyMemento._rectangle.MaximumX);" is alway NaN?
 
namespace OxyRectangle
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new RectangleScale();
}
}
public class RectangleScale
{
public PlotModel PlotModel { get; set; }
RectangleAnnotation Rectum;
private LinearAxis XAxis;
private LinearAxis YAxis;
public Memento MyMemento { get; set; }
public RectangleScale()
{
PlotModel = new PlotModel();
XAxis = new LinearAxis
{
Position = AxisPosition.Bottom
};
YAxis = new LinearAxis
{
Position= AxisPosition.Left,
IsPanEnabled=false
};
Rectum = new RectangleAnnotation();
SetRectum(Rectum, 1, 1, 10, 10);
MyMemento = new Memento(Rectum);
PlotModel.Axes.Add(XAxis);
PlotModel.Axes.Add(YAxis);
PlotModel.Annotations.Add(Rectum);
ChangeAxis(PlotModel, 100, 200);
ConvertOldRectangle(Rectum);
PlotModel.InvalidatePlot(true);
}
public void SetRectum(RectangleAnnotation rectangle, double xmin, double ymin, double xmax, double ymax)
{
rectangle.MinimumX = xmin;
rectangle.MinimumY = ymin;
rectangle.MaximumX = xmax;
rectangle.MaximumY = ymax;
}
public void ChangeAxis(PlotModel _plotmodel,int minimum,int maximum)
{
_plotmodel.Axes.Clear();
LinearAxis XAxis = new LinearAxis
{
Position = AxisPosition.Bottom,
Minimum=minimum,
Maximum=maximum
};
LinearAxis YAxis = new LinearAxis
{
Position = AxisPosition.Left,
Minimum=minimum,
Maximum=maximum,
IsPanEnabled = false
};
_plotmodel.Axes.Add(XAxis);
_plotmodel.Axes.Add(YAxis);
_plotmodel.InvalidatePlot(true);
}
public void ConvertOldRectangle(RectangleAnnotation _rectangle)
{
PlotModel.InvalidatePlot(true);
double temp1 = XAxis.Transform(this.MyMemento._rectangle.MaximumX);
double temp2 = XAxis.Transform(this.MyMemento._rectangle.MinimumX);
double temp3 = YAxis.Transform(this.MyMemento._rectangle.MaximumY);
double temp4 = YAxis.Transform(this.MyMemento._rectangle.MinimumY);
_rectangle.MaximumX = XAxis.InverseTransform(temp1);
_rectangle.MinimumX = XAxis.InverseTransform(temp2);
_rectangle.MaximumY = YAxis.InverseTransform(temp3);
_rectangle.MinimumY = YAxis.InverseTransform(temp4);
}
public void Revert()
{
Rectum = this.MyMemento._rectangle;
}
}
public class Memento
{
public readonly RectangleAnnotation _rectangle;
public Memento(RectangleAnnotation rectangle)
{
_rectangle = rectangle;
}
}
}
 

Answers (2)