06-10-2013 07:39 AM
I need to make ScatterGraph with perfectly square axes, which also should fill its container. It will display the unit circle (radius 1, positioned at 0), so non-square axes are very annoying.
What I do now, is something li this, but it doesn't make perfectly square axes.
private void graphWrapper_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (squareArea)
{
int size = (int)Math.Max(0, Math.Min(graphWrapper.ActualWidth, graphWrapper.ActualHeight) - 10);
graph.Width = size + 35;
graph.Height = size;
graph.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
}
}
Solved! Go to Solution.
06-10-2013 02:52 PM
You can use the following SizeChanged
event handler on a graph to maintain a square plot area:
private void OnGraphSizeChanged( object sender, SizeChangedEventArgs e ) {
Thickness margin = graph.Margin;
Size plotAreaSize = graph.GetPlotAreaSize( );
Size current = new Size(
plotAreaSize.Width + margin.Left + margin.Right,
plotAreaSize.Height + margin.Top + margin.Bottom );
double ideal = Math.Floor( Math.Min( current.Width, current.Height ) );
graph.Margin = new Thickness {
Right = Math.Floor( current.Width - ideal ),
Bottom = Math.Floor( current.Height - ideal )
};