0
Strange axis working?
I have strange problem with Axis how i think. I am trying to save Rectangle size and place with any axis. At first I am converting data points to screen points using Transform, then I save them converted points, after axis changing I am making Inversetransform of saved point's.
ChangeAxis- Transforms, saves, changing axes.
SetNewRectangle - Set new rectangle from saved points using InverseTransform.
The main question is why it's working when I am clicking ChangeAxis and then OldRectangle and not working when I am clicking on button "MakeAll" (encapsulates ChangeAxis,OldRectangle).
using OxyPlot;using OxyPlot.Annotations;
using OxyPlot.Axes;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication33
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
StrangeWithAxes swa = new StrangeWithAxes();
public MainWindow()
{
InitializeComponent();
DataContext = swa;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
swa.ChangeAxis();
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
swa.SetNewRectangle();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
swa.MakeAll();
}
}
public class StrangeWithAxes
{
public PlotModel PlotModel { get; set; }
LinearAxis XAxis { get; set; }
LinearAxis YAxis { get; set; }
RectangleAnnotation Rectangle { get; set; }
RectangleAnnotation TempRectangle { get; set; }
double xmin;
double xmax;
double ymin;
double ymax;
public StrangeWithAxes()
{
Rectangle = new RectangleAnnotation();
Rectangle.MinimumX = 10;
Rectangle.MinimumY = 10;
Rectangle.MaximumX = 20;
Rectangle.MaximumY = 20;
PlotModel = new PlotModel();
XAxis = new LinearAxis
{
Position=AxisPosition.Bottom,
Minimum=0,
Maximum=50,
};
YAxis = new LinearAxis
{
Position=AxisPosition.Left,
Minimum=0,
Maximum=50,
IsPanEnabled=false
};
PlotModel.Axes.Add(XAxis);
PlotModel.Axes.Add(YAxis);
PlotModel.Annotations.Add(Rectangle);
PlotModel.InvalidatePlot(true);
}
public void MakeAll()
{
ChangeAxis();
SetNewRectangle();
}
public void ChangeAxis()
{
TempRectangle = Rectangle;
xmin=XAxis.Transform(TempRectangle.MinimumX);
xmax=XAxis.Transform(TempRectangle.MaximumX);
ymin=YAxis.Transform(TempRectangle.MinimumY);
ymax=YAxis.Transform(TempRectangle.MaximumY);
XAxis = new LinearAxis
{
Position = AxisPosition.Bottom,
Minimum = 0,
Maximum = 100,
};
YAxis = new LinearAxis
{
Position = AxisPosition.Left,
Minimum = 0,
Maximum = 100,
IsPanEnabled = false
};
PlotModel.Axes.Clear();
PlotModel.Axes.Add(XAxis);
PlotModel.Axes.Add(YAxis);
PlotModel.InvalidatePlot(true);
}
public void SetNewRectangle()
{
PlotModel.Annotations.Clear();
Debug.WriteLine(xmin);
Debug.WriteLine(ymin);
Debug.WriteLine(xmax);
Debug.WriteLine(ymax);
Rectangle.MinimumX = XAxis.InverseTransform(xmin);
Rectangle.MinimumY = YAxis.InverseTransform(ymin);
Rectangle.MaximumX = XAxis.InverseTransform(xmax);
Rectangle.MaximumY = YAxis.InverseTransform(ymax);
PlotModel.Annotations.Add(Rectangle);
PlotModel.InvalidatePlot(false);
}
}
}
And xaml code:
http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:oxy="http://oxyplot.org/wpf"
Title="MainWindow" Height="350" Width="525">
<Grid Margin="83,0,0,0">
<oxy:Plot Model="{Binding PlotModel}"></oxy:Plot>
<Button Content="ChangeAxis" HorizontalAlignment="Left" Margin="-80,36,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
<Button Content="SetNewRectangle" HorizontalAlignment="Left" Margin="-80,61,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_2"/>
<Button Content="MakeAll" HorizontalAlignment="Left" Margin="-80,11,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
</Grid>
</Window>
ChangeAxis- Transforms, saves, changing axes.
SetNewRectangle - Set new rectangle from saved points using InverseTransform.
The main question is why it's working when I am clicking ChangeAxis and then OldRectangle and not working when I am clicking on button "MakeAll" (encapsulates ChangeAxis,OldRectangle).
using OxyPlot;using OxyPlot.Annotations;
using OxyPlot.Axes;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication33
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
StrangeWithAxes swa = new StrangeWithAxes();
public MainWindow()
{
InitializeComponent();
DataContext = swa;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
swa.ChangeAxis();
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
swa.SetNewRectangle();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
swa.MakeAll();
}
}
public class StrangeWithAxes
{
public PlotModel PlotModel { get; set; }
LinearAxis XAxis { get; set; }
LinearAxis YAxis { get; set; }
RectangleAnnotation Rectangle { get; set; }
RectangleAnnotation TempRectangle { get; set; }
double xmin;
double xmax;
double ymin;
double ymax;
public StrangeWithAxes()
{
Rectangle = new RectangleAnnotation();
Rectangle.MinimumX = 10;
Rectangle.MinimumY = 10;
Rectangle.MaximumX = 20;
Rectangle.MaximumY = 20;
PlotModel = new PlotModel();
XAxis = new LinearAxis
{
Position=AxisPosition.Bottom,
Minimum=0,
Maximum=50,
};
YAxis = new LinearAxis
{
Position=AxisPosition.Left,
Minimum=0,
Maximum=50,
IsPanEnabled=false
};
PlotModel.Axes.Add(XAxis);
PlotModel.Axes.Add(YAxis);
PlotModel.Annotations.Add(Rectangle);
PlotModel.InvalidatePlot(true);
}
public void MakeAll()
{
ChangeAxis();
SetNewRectangle();
}
public void ChangeAxis()
{
TempRectangle = Rectangle;
xmin=XAxis.Transform(TempRectangle.MinimumX);
xmax=XAxis.Transform(TempRectangle.MaximumX);
ymin=YAxis.Transform(TempRectangle.MinimumY);
ymax=YAxis.Transform(TempRectangle.MaximumY);
XAxis = new LinearAxis
{
Position = AxisPosition.Bottom,
Minimum = 0,
Maximum = 100,
};
YAxis = new LinearAxis
{
Position = AxisPosition.Left,
Minimum = 0,
Maximum = 100,
IsPanEnabled = false
};
PlotModel.Axes.Clear();
PlotModel.Axes.Add(XAxis);
PlotModel.Axes.Add(YAxis);
PlotModel.InvalidatePlot(true);
}
public void SetNewRectangle()
{
PlotModel.Annotations.Clear();
Debug.WriteLine(xmin);
Debug.WriteLine(ymin);
Debug.WriteLine(xmax);
Debug.WriteLine(ymax);
Rectangle.MinimumX = XAxis.InverseTransform(xmin);
Rectangle.MinimumY = YAxis.InverseTransform(ymin);
Rectangle.MaximumX = XAxis.InverseTransform(xmax);
Rectangle.MaximumY = YAxis.InverseTransform(ymax);
PlotModel.Annotations.Add(Rectangle);
PlotModel.InvalidatePlot(false);
}
}
}
And xaml code:
http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:oxy="http://oxyplot.org/wpf"
Title="MainWindow" Height="350" Width="525">
<Grid Margin="83,0,0,0">
<oxy:Plot Model="{Binding PlotModel}"></oxy:Plot>
<Button Content="ChangeAxis" HorizontalAlignment="Left" Margin="-80,36,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
<Button Content="SetNewRectangle" HorizontalAlignment="Left" Margin="-80,61,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_2"/>
<Button Content="MakeAll" HorizontalAlignment="Left" Margin="-80,11,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
</Grid>
</Window>
Customer support service by UserEcho