Index: Core/Components/src/Core.Components.OxyPlot.Forms/ChartControl.cs =================================================================== diff -u -r271bd5ffd4d61da4324eb50957f062b14c4c6958 -r343449d430f43342f74677ff37ade9332080f966 --- Core/Components/src/Core.Components.OxyPlot.Forms/ChartControl.cs (.../ChartControl.cs) (revision 271bd5ffd4d61da4324eb50957f062b14c4c6958) +++ Core/Components/src/Core.Components.OxyPlot.Forms/ChartControl.cs (.../ChartControl.cs) (revision 343449d430f43342f74677ff37ade9332080f966) @@ -152,8 +152,7 @@ if (!extent.IsNaN) { Extent extentWithPadding = extent.AddPadding(0.01); - plotView.Model.DefaultXAxis.Zoom(extentWithPadding.XMin, extentWithPadding.XMax); - plotView.Model.DefaultYAxis.Zoom(extentWithPadding.YMin, extentWithPadding.YMax); + plotView.SetExtent(extentWithPadding); plotView.Refresh(); } } @@ -188,14 +187,14 @@ return extent; } - private Extent CreateExtentFor(XYAxisSeries ChartData) + private static Extent CreateExtentFor(XYAxisSeries chartData) { return new Extent ( - ChartData.MinX, - ChartData.MaxX, - ChartData.MinY, - ChartData.MaxY + chartData.MinX, + chartData.MaxX, + chartData.MinY, + chartData.MaxY ); } @@ -243,21 +242,21 @@ private static IEnumerable GetChartDataRecursively(ChartDataCollection chartDataCollection) { - var ChartDataList = new List(); + var chartDataList = new List(); foreach (ChartData chartData in chartDataCollection.Collection) { var nestedChartDataCollection = chartData as ChartDataCollection; if (nestedChartDataCollection != null) { - ChartDataList.AddRange(GetChartDataRecursively(nestedChartDataCollection)); + chartDataList.AddRange(GetChartDataRecursively(nestedChartDataCollection)); continue; } - ChartDataList.Add((ChartData) chartData); + chartDataList.Add(chartData); } - return ChartDataList; + return chartDataList; } private void HandleChartDataCollectionChange() Index: Core/Components/src/Core.Components.OxyPlot.Forms/LinearPlotView.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -r343449d430f43342f74677ff37ade9332080f966 --- Core/Components/src/Core.Components.OxyPlot.Forms/LinearPlotView.cs (.../LinearPlotView.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Components/src/Core.Components.OxyPlot.Forms/LinearPlotView.cs (.../LinearPlotView.cs) (revision 343449d430f43342f74677ff37ade9332080f966) @@ -110,6 +110,34 @@ InvalidatePlot(false); } + public void SetExtent(Extent extentWithPadding) + { + Axis xAxis = GetAxisOnPosition(AxisPosition.Bottom); + Axis yAxis = GetAxisOnPosition(AxisPosition.Left); + + double xMin = extentWithPadding.XMin; + double xMax = extentWithPadding.XMax; + double yMin = extentWithPadding.YMin; + double yMax = extentWithPadding.YMax; + + double xCorrection = AxisMinimumRangeCorrection(xAxis, xMin, xMax); + if (xCorrection > 0) + { + xMin -= xCorrection; + xMax += xCorrection; + } + + double yCorrection = AxisMinimumRangeCorrection(yAxis, yMin, yMax); + if (yCorrection > 0) + { + yMin -= yCorrection; + yMax += yCorrection; + } + + xAxis.Zoom(xMin, xMax); + yAxis.Zoom(yMin, yMax); + } + private void SetAxisTitle(AxisPosition axisPosition, string value) { Axis axis = GetAxisOnPosition(axisPosition); @@ -157,5 +185,10 @@ { return Model.Axes.First(a => a.Position == position); } + + private static double AxisMinimumRangeCorrection(Axis axis, double xMin, double xMax) + { + return (axis.MinimumRange - xMax + xMin) / 2; + } } } \ No newline at end of file Index: Core/Components/test/Core.Components.OxyPlot.Forms.Test/LinearPlotViewTest.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -r343449d430f43342f74677ff37ade9332080f966 --- Core/Components/test/Core.Components.OxyPlot.Forms.Test/LinearPlotViewTest.cs (.../LinearPlotViewTest.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Components/test/Core.Components.OxyPlot.Forms.Test/LinearPlotViewTest.cs (.../LinearPlotViewTest.cs) (revision 343449d430f43342f74677ff37ade9332080f966) @@ -106,6 +106,87 @@ } [Test] + public void SetExtent_RangeLargerThanMinimumRange_AxesUpdated() + { + // Setup + using (var form = new Form()) + using (var view = new LinearPlotView()) + { + form.Controls.Add(view); + + form.Show(); + + const int xMin = 3; + const int xMax = 5; + const int yMin = 1; + const int yMax = 2; + + // Call + view.SetExtent(new Extent(xMin, xMax, yMin, yMax)); + + // Assert + Assert.AreEqual(xMin, view.Model.Axes[0].ActualMinimum); + Assert.AreEqual(xMax, view.Model.Axes[0].ActualMaximum); + Assert.AreEqual(yMin, view.Model.Axes[1].ActualMinimum); + Assert.AreEqual(yMax, view.Model.Axes[1].ActualMaximum); + } + } + + [Test] + public void SetExtent_DataRangeInXSmallerThanMinimumRange_AxesUpdatedWithCorrectionForX() + { + // Setup + using (var form = new Form()) + using (var view = new LinearPlotView()) + { + form.Controls.Add(view); + + form.Show(); + + const double range = 0.02; + const int xMin = 3; + const int yMin = 1; + const int yMax = 4; + + // Call + view.SetExtent(new Extent(xMin, xMin + range, yMin, yMax)); + + // Assert + Assert.AreEqual(xMin - 0.04, view.Model.Axes[0].ActualMinimum); + Assert.AreEqual(xMin + 0.06, view.Model.Axes[0].ActualMaximum); + Assert.AreEqual(yMin, view.Model.Axes[1].ActualMinimum); + Assert.AreEqual(yMax, view.Model.Axes[1].ActualMaximum); + } + } + + [Test] + public void SetExtent_DataRangeInYSmallerThanMinimumRange_AxesUpdatedWithCorrectionForY() + { + // Setup + using (var form = new Form()) + using (var view = new LinearPlotView()) + { + form.Controls.Add(view); + + form.Show(); + + const double range = 0.02; + const int xMin = 3; + const int xMax = 7; + const int yMin = 1; + + // Call + view.SetExtent(new Extent(xMin, xMax, yMin, yMin + range)); + + // Assert + Assert.AreEqual(xMin, view.Model.Axes[0].ActualMinimum); + Assert.AreEqual(xMax, view.Model.Axes[0].ActualMaximum); + Assert.AreEqual(yMin - 0.04, view.Model.Axes[1].ActualMinimum); + Assert.AreEqual(yMin + 0.06, view.Model.Axes[1].ActualMaximum); + } + } + + [Test] [TestCase("Title")] [TestCase("Test")] [TestCase("Label")] Index: Core/Plugins/src/Core.Plugins.Chart/ChartPlugin.cs =================================================================== diff -u -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 -r343449d430f43342f74677ff37ade9332080f966 --- Core/Plugins/src/Core.Plugins.Chart/ChartPlugin.cs (.../ChartPlugin.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) +++ Core/Plugins/src/Core.Plugins.Chart/ChartPlugin.cs (.../ChartPlugin.cs) (revision 343449d430f43342f74677ff37ade9332080f966) @@ -110,7 +110,7 @@ if (chartView != null) { chartingRibbon.Chart = chartView.Chart; - chartLegendController.Update(chartView.Chart.Data); + chartLegendController.Update(chartView.Chart); } else { Index: Core/Plugins/src/Core.Plugins.Chart/Legend/ChartLegendController.cs =================================================================== diff -u -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 -r343449d430f43342f74677ff37ade9332080f966 --- Core/Plugins/src/Core.Plugins.Chart/Legend/ChartLegendController.cs (.../ChartLegendController.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) +++ Core/Plugins/src/Core.Plugins.Chart/Legend/ChartLegendController.cs (.../ChartLegendController.cs) (revision 343449d430f43342f74677ff37ade9332080f966) @@ -26,6 +26,7 @@ using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms.ViewHost; using Core.Components.Charting.Data; +using Core.Components.Charting.Forms; using Core.Plugins.Chart.Properties; namespace Core.Plugins.Chart.Legend @@ -43,7 +44,7 @@ /// public EventHandler OnOpenLegend; - private IView legendView; + private ChartLegendView legendView; /// /// Creates a new instance of . @@ -97,13 +98,13 @@ /// /// Updates the data for the if it is open. /// - /// The to show. If null the - /// data will be cleared. - public void Update(ChartData data) + /// The for which to show a + /// legend. If null the data will be cleared. + public void Update(IChartControl chartControl) { if (IsLegendViewOpen) { - legendView.Data = data; + legendView.ChartControl = chartControl; } }