Index: Core/Components/src/Core.Components.Charting.Forms/IChartControl.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Components/src/Core.Components.Charting.Forms/IChartControl.cs (.../IChartControl.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Components/src/Core.Components.Charting.Forms/IChartControl.cs (.../IChartControl.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using Core.Components.Charting.Data; namespace Core.Components.Charting.Forms @@ -71,6 +72,14 @@ /// /// Zooms to a level so that everything is in view. /// - void ZoomToAll(); + void ZoomToAllVisibleLayers(); + + /// + /// Zooms to a level such that the given chart data is in view. + /// + /// The data to zoom to. + /// Thrown when + /// is not part of . + void ZoomToAllVisibleLayers(ChartData layerData); } } \ No newline at end of file Index: Core/Components/src/Core.Components.Charting/Data/ChartData.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Components/src/Core.Components.Charting/Data/ChartData.cs (.../ChartData.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Components/src/Core.Components.Charting/Data/ChartData.cs (.../ChartData.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -66,5 +66,10 @@ /// Gets or sets a value indicating whether the is visible. /// public bool IsVisible { get; set; } + + /// + /// Gets a value indicating whether the has data. + /// + public virtual bool HasData { get; } } } \ No newline at end of file Index: Core/Components/src/Core.Components.Charting/Data/ChartDataCollection.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Components/src/Core.Components.Charting/Data/ChartDataCollection.cs (.../ChartDataCollection.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Components/src/Core.Components.Charting/Data/ChartDataCollection.cs (.../ChartDataCollection.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; +using System.Linq; namespace Core.Components.Charting.Data { @@ -99,5 +100,13 @@ { chartDataList.Clear(); } + + public override bool HasData + { + get + { + return chartDataList.Any(c => c.HasData); + } + } } } \ No newline at end of file Index: Core/Components/src/Core.Components.Charting/Data/ChartMultipleAreaData.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Components/src/Core.Components.Charting/Data/ChartMultipleAreaData.cs (.../ChartMultipleAreaData.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Components/src/Core.Components.Charting/Data/ChartMultipleAreaData.cs (.../ChartMultipleAreaData.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -76,5 +76,13 @@ /// Gets or sets the style of the . /// public ChartAreaStyle Style { get; set; } + + public override bool HasData + { + get + { + return areas.Any(l => l.Any()); + } + } } } \ No newline at end of file Index: Core/Components/src/Core.Components.Charting/Data/ChartMultipleLineData.cs =================================================================== diff -u -r88f6d73b4d5d1e7e6a2f75d700e552c3cb7719ae -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Components/src/Core.Components.Charting/Data/ChartMultipleLineData.cs (.../ChartMultipleLineData.cs) (revision 88f6d73b4d5d1e7e6a2f75d700e552c3cb7719ae) +++ Core/Components/src/Core.Components.Charting/Data/ChartMultipleLineData.cs (.../ChartMultipleLineData.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -78,5 +78,13 @@ /// Gets or sets the style of the . /// public ChartLineStyle Style { get; set; } + + public override bool HasData + { + get + { + return lines.Any(l => l.Any()); + } + } } } Index: Core/Components/src/Core.Components.Charting/Data/PointBasedChartData.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Components/src/Core.Components.Charting/Data/PointBasedChartData.cs (.../PointBasedChartData.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Components/src/Core.Components.Charting/Data/PointBasedChartData.cs (.../PointBasedChartData.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Linq; using Core.Common.Base.Geometry; namespace Core.Components.Charting.Data @@ -62,5 +63,13 @@ points = value; } } + + public override bool HasData + { + get + { + return Points.Any(); + } + } } } \ No newline at end of file Index: Core/Components/src/Core.Components.OxyPlot.Forms/ChartControl.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Components/src/Core.Components.OxyPlot.Forms/ChartControl.cs (.../ChartControl.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Components/src/Core.Components.OxyPlot.Forms/ChartControl.cs (.../ChartControl.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -140,11 +141,81 @@ plotController.ToggleRectangleZooming(); } - public void ZoomToAll() + public void ZoomToAllVisibleLayers() { - plotView.ZoomToAll(); + ZoomToAllVisibleLayers(Data); } + public void ZoomToAllVisibleLayers(ChartData layerData) + { + Extent extent = CreateEnvelopeForAllVisibleLayers(layerData); + 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.Refresh(); + } + } + + /// + /// Defines the area taken up by the visible map-data based on the provided map-data. + /// + /// The data to determine the visible extent for. + /// The area definition. + /// Thrown when is + /// not part of the drawn map features. + private Extent CreateEnvelopeForAllVisibleLayers(ChartData chartData) + { + var collection = chartData as ChartDataCollection; + if (collection != null) + { + return CreateEnvelopeForAllVisibleLayers(collection); + } + + DrawnChartData drawnMapData = drawnChartDataList.FirstOrDefault(dmd => dmd.ItemBasedChartData.Equals(chartData)); + if (drawnMapData == null) + { + throw new ArgumentException($@"Can only zoom to {typeof(ChartData).Name} that is part of this {typeof(ChartControl).Name}s drawn {nameof(chartData)}.", + nameof(chartData)); + } + + Extent extent = new Extent(); + if (drawnMapData.ItemBasedChartData.IsVisible) + { + extent.ExpandToInclude(CreateExtentFor(drawnMapData.ItemBasedChartDataSeries as XYAxisSeries)); + } + return extent; + } + + private Extent CreateExtentFor(XYAxisSeries itemBasedChartData) + { + return new Extent + ( + itemBasedChartData.MinX, + itemBasedChartData.MaxX, + itemBasedChartData.MinY, + itemBasedChartData.MaxY + ); + } + + /// + /// Defines the area taken up by the visible map-data based on the provided map-data. + /// + /// The data to determine the visible extent for. + /// The area definition. + /// Thrown when or + /// any of its children is not part of the drawn map features. + private Extent CreateEnvelopeForAllVisibleLayers(ChartDataCollection chartData) + { + var envelope = new Extent(); + foreach (ChartData childMapData in chartData.Collection) + { + envelope.ExpandToInclude(CreateEnvelopeForAllVisibleLayers(childMapData)); + } + return envelope; + } + protected override void Dispose(bool disposing) { plotView.Dispose(); Index: Core/Components/src/Core.Components.OxyPlot.Forms/Core.Components.OxyPlot.Forms.csproj =================================================================== diff -u -r23d1e296e2da4364fbfe346e68d582dfcf966bb0 -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Components/src/Core.Components.OxyPlot.Forms/Core.Components.OxyPlot.Forms.csproj (.../Core.Components.OxyPlot.Forms.csproj) (revision 23d1e296e2da4364fbfe346e68d582dfcf966bb0) +++ Core/Components/src/Core.Components.OxyPlot.Forms/Core.Components.OxyPlot.Forms.csproj (.../Core.Components.OxyPlot.Forms.csproj) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -56,6 +56,7 @@ Component + Component Index: Core/Components/src/Core.Components.OxyPlot.Forms/Extent.cs =================================================================== diff -u --- Core/Components/src/Core.Components.OxyPlot.Forms/Extent.cs (revision 0) +++ Core/Components/src/Core.Components.OxyPlot.Forms/Extent.cs (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -0,0 +1,112 @@ +using System; + +namespace Core.Components.OxyPlot.Forms +{ + /// + /// Class for helping determine new extents for the plot view. + /// + internal class Extent + { + /// + /// Creates a new instance of . + /// + /// The smallest x value. + /// The largest x value. + /// The smallest y value. + /// The largest y value. + public Extent(double xMin, double xMax, double yMin, double yMax) + { + XMin = xMin; + XMax = xMax; + YMin = yMin; + YMax = yMax; + } + + /// + /// Creates a new instance of without values for + /// the properties. + /// + public Extent() + { + XMin = double.NaN; + XMax = double.NaN; + YMin = double.NaN; + YMax = double.NaN; + } + + /// + /// Gets the smallest x value. + /// + public double XMin { get; private set; } + + /// + /// Gets the largest x value. + /// + public double XMax { get; private set; } + + /// + /// Gets the smallest y value. + /// + public double YMin { get; private set; } + + /// + /// Gets the largest y value. + /// + public double YMax { get; private set; } + + /// + /// Adds padding to the extent and returns the new + /// extent. + /// + /// The padding to add. + /// A new extent with padding added + /// to the property values. + public Extent AddPadding(double padding) + { + double xPadding = (XMax - XMin) * padding; + double yPadding = (YMax - YMin) * padding; + + return new Extent + { + XMin = XMin - xPadding, + XMax = XMax + xPadding, + YMin = YMin - yPadding, + YMax = YMax + yPadding, + }; + } + + /// + /// Gets a value indicating whether values were + /// given to the properties. + /// + public bool IsNaN + { + get + { + return double.IsNaN(XMin) + || double.IsNaN(XMax) + || double.IsNaN(YMin) + || double.IsNaN(YMax); + } + } + + /// + /// Assigns new values to the properties in such a way + /// that the the new values include both the + /// and the . + /// + /// The other extent to include in + /// the . + public void ExpandToInclude(Extent otherExtent) + { + if (otherExtent.IsNaN) + { + return; + } + XMin = double.IsNaN(XMin) ? otherExtent.XMin : Math.Min(XMin, otherExtent.XMin); + XMax = double.IsNaN(XMax) ? otherExtent.XMax : Math.Max(XMax, otherExtent.XMax); + YMin = double.IsNaN(YMin) ? otherExtent.YMin : Math.Min(YMin, otherExtent.YMin); + YMax = double.IsNaN(YMax) ? otherExtent.YMax : Math.Max(YMax, otherExtent.YMax); + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.OxyPlot.Forms.Test/ChartControlTest.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Components/test/Core.Components.OxyPlot.Forms.Test/ChartControlTest.cs (.../ChartControlTest.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Components/test/Core.Components.OxyPlot.Forms.Test/ChartControlTest.cs (.../ChartControlTest.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -329,7 +329,13 @@ using (var form = new Form()) { var chart = new ChartControl(); - var testData = new ChartLineData("test data"); + var testData = new ChartLineData("test data") + { + Points = new[] + { + new Point2D(2, 3) + } + }; var collection = new ChartDataCollection("collection"); var view = TypeUtils.GetField(chart, "plotView"); var invalidated = 0; @@ -344,9 +350,10 @@ view.Invalidated += (sender, args) => invalidated++; form.Show(); + view.Update(); // Call - chart.ZoomToAll(); + chart.ZoomToAllVisibleLayers(); // Assert Assert.AreEqual(1, invalidated); @@ -355,6 +362,39 @@ } [Test] + public void ZoomToAll_ChartWithoutDataInForm_ViewNotInvalidated() + { + // Setup + using (var form = new Form()) + { + var chart = new ChartControl(); + var testData = new ChartLineData("test data"); + var collection = new ChartDataCollection("collection"); + var view = TypeUtils.GetField(chart, "plotView"); + var invalidated = 0; + + collection.Add(testData); + + chart.Data = collection; + + List series = view.Model.Series.ToList(); + + form.Controls.Add(chart); + view.Invalidated += (sender, args) => invalidated++; + + form.Show(); + view.Update(); + + // Call + chart.ZoomToAllVisibleLayers(); + + // Assert + Assert.AreEqual(0, invalidated); + CollectionAssert.AreEqual(series, view.Model.Series); + } + } + + [Test] [TestCase("Title")] [TestCase("Test")] [TestCase("Label")] Index: Core/Plugins/src/Core.Plugins.Chart/ChartPlugin.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Plugins/src/Core.Plugins.Chart/ChartPlugin.cs (.../ChartPlugin.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Plugins/src/Core.Plugins.Chart/ChartPlugin.cs (.../ChartPlugin.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -76,7 +76,7 @@ /// A new instance. private ChartLegendController CreateLegendController(IViewController viewController) { - var controller = new ChartLegendController(viewController); + var controller = new ChartLegendController(viewController, Gui); controller.OnOpenLegend += (s, e) => UpdateComponentsForActiveDocumentView(); return controller; } Index: Core/Plugins/src/Core.Plugins.Chart/ChartingRibbon.xaml.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Plugins/src/Core.Plugins.Chart/ChartingRibbon.xaml.cs (.../ChartingRibbon.xaml.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Plugins/src/Core.Plugins.Chart/ChartingRibbon.xaml.cs (.../ChartingRibbon.xaml.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -119,7 +119,7 @@ private void ButtonZoomToAll_Click(object sender, RoutedEventArgs e) { - Chart.ZoomToAll(); + Chart.ZoomToAllVisibleLayers(); } } } \ No newline at end of file Index: Core/Plugins/src/Core.Plugins.Chart/Legend/ChartLegendController.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Plugins/src/Core.Plugins.Chart/Legend/ChartLegendController.cs (.../ChartLegendController.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Plugins/src/Core.Plugins.Chart/Legend/ChartLegendController.cs (.../ChartLegendController.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -23,6 +23,7 @@ using System.Linq; using Core.Common.Controls.Views; using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms.ViewHost; using Core.Components.Charting.Data; using Core.Plugins.Chart.Properties; @@ -35,6 +36,7 @@ public class ChartLegendController { private readonly IViewController viewController; + private readonly IContextMenuBuilderProvider contextMenuBuilderProvider; /// /// Fired when the chart legend has been opened. @@ -47,13 +49,23 @@ /// Creates a new instance of . /// /// The to invoke actions upon. - public ChartLegendController(IViewController viewController) + /// The to create context menus. + /// Thrown when + /// or is null. + public ChartLegendController(IViewController viewController, IContextMenuBuilderProvider contextMenuBuilderProvider) { if (viewController == null) { - throw new ArgumentNullException(nameof(viewController), @"Cannot create a ChartLegendController when the view controller is null."); + throw new ArgumentNullException(nameof(viewController), + $@"Cannot create a {typeof(ChartLegendController).Name} when the view controller is null."); } + if (contextMenuBuilderProvider == null) + { + throw new ArgumentNullException(nameof(contextMenuBuilderProvider), + $@"Cannot create a {typeof(ChartLegendController).Name} when the context menu builder provider is null."); + } this.viewController = viewController; + this.contextMenuBuilderProvider = contextMenuBuilderProvider; } /// @@ -100,7 +112,7 @@ /// private void OpenLegendView() { - legendView = new ChartLegendView(); + legendView = new ChartLegendView(contextMenuBuilderProvider); viewController.ViewHost.AddToolView(legendView, ToolViewLocation.Left); viewController.ViewHost.SetImage(legendView, Resources.ChartIcon); Index: Core/Plugins/src/Core.Plugins.Chart/Legend/ChartLegendView.cs =================================================================== diff -u -rfa07631b4d1fac0c9d34aedfc19de6afc1e01f59 -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Plugins/src/Core.Plugins.Chart/Legend/ChartLegendView.cs (.../ChartLegendView.cs) (revision fa07631b4d1fac0c9d34aedfc19de6afc1e01f59) +++ Core/Plugins/src/Core.Plugins.Chart/Legend/ChartLegendView.cs (.../ChartLegendView.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -19,12 +19,15 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; +using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Windows.Forms; using Core.Common.Base; using Core.Common.Controls.TreeView; using Core.Common.Controls.Views; +using Core.Common.Gui.ContextMenu; using Core.Components.Charting.Data; using Core.Components.Charting.Forms; using Core.Plugins.Chart.PresentationObjects; @@ -38,17 +41,42 @@ /// public sealed partial class ChartLegendView : UserControl, IView { + private readonly IContextMenuBuilderProvider contextMenuBuilderProvider; + private IChartControl chartControl; + /// /// Creates a new instance of . /// - public ChartLegendView() + /// The to create context menus. + /// Thrown when is null. + public ChartLegendView(IContextMenuBuilderProvider contextMenuBuilderProvider) { + if (contextMenuBuilderProvider == null) + { + throw new ArgumentNullException(nameof(contextMenuBuilderProvider), + $@"Cannot create a {typeof(ChartLegendView).Name} when the context menu builder provider is null."); + } + + this.contextMenuBuilderProvider = contextMenuBuilderProvider; InitializeComponent(); Text = ChartResources.General_Chart; RegisterTreeNodeInfos(); } + public IChartControl ChartControl + { + get + { + return chartControl; + } + set + { + chartControl = value; + Data = value?.Data; + } + } + public object Data { get @@ -74,7 +102,10 @@ OnNodeChecked = ChartDataContextOnNodeChecked, CanDrop = ChartDataContextCanDropAndInsert, CanInsert = ChartDataContextCanDropAndInsert, - OnDrop = ChartDataContextOnDrop + OnDrop = ChartDataContextOnDrop, + ContextMenuStrip = (nodeData, parentData, treeView) => contextMenuBuilderProvider.Get(nodeData, treeView) + .AddCustomItem(CreateZoomToExtentsItem(nodeData.WrappedData)) + .Build() }); treeViewControl.RegisterTreeNodeInfo(new TreeNodeInfo @@ -85,10 +116,116 @@ CanDrag = (multipleAreaData, parentData) => true, CanDrop = ChartDataCollectionCanDropAndInsert, CanInsert = ChartDataCollectionCanDropAndInsert, - OnDrop = ChartDataCollectionOnDrop + OnDrop = ChartDataCollectionOnDrop, + ContextMenuStrip = (nodeData, parentData, treeView) => contextMenuBuilderProvider.Get(nodeData, treeView) + .AddCustomItem(CreateZoomToExtentsItem(nodeData)) + .Build() }); } + private StrictContextMenuItem CreateZoomToExtentsItem(ChartData nodeData) + { + bool hasFeatures = nodeData.HasData; + bool enabled = nodeData.IsVisible && hasFeatures; + string toolTip; + + if (nodeData.IsVisible) + { + toolTip = hasFeatures + ? ChartResources.ChartLegendView_CreateZoomToExtentsItem_ZoomToAll_Tooltip + : ChartResources.ChartLegendView_CreateZoomToExtentsItem_NoFeatures_ZoomToAllDisabled_Tooltip; + } + else + { + toolTip = ChartResources.ChartLegendView_CreateZoomToExtentsItem_ZoomToAllDisabled_Tooltip; + } + + return CreateZoomToExtentsItem(nodeData, toolTip, enabled); + } + + private StrictContextMenuItem CreateZoomToExtentsItem(ChartData nodeData, string toolTip, bool isEnabled) + { + return new StrictContextMenuItem($"&{ChartResources.Ribbon_ZoomToAll}", + toolTip, + ChartResources.ZoomToAllIcon, + (sender, args) => + { + ChartControl?.ZoomToAllVisibleLayers(nodeData); + }) + { + Enabled = isEnabled + }; + } + + private StrictContextMenuItem CreateZoomToExtentsItem(ChartDataCollection nodeData) + { + ChartData[] chartDatas = GetChartDataRecursively(nodeData).ToArray(); + var isVisible = false; + var hasFeatures = false; + foreach (ChartData chartData in chartDatas) + { + + if (chartData.IsVisible) + { + isVisible = true; + + if (chartData.HasData) + { + hasFeatures = true; + break; + } + } + } + + bool enabled = isVisible && hasFeatures; + + string toolTip; + + if (isVisible) + { + toolTip = hasFeatures + ? ChartResources.ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_ZoomToAll_Tooltip + : ChartResources.ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_NoData_ZoomToAllDisabled_Tooltip; + } + else + { + toolTip = ChartResources.ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_ZoomToAllDisabled_Tooltip; + } + + return CreateZoomToExtentsItem(nodeData, toolTip, enabled); + } + + + /// + /// Gets all the recursively in the given . + /// + /// The collection to get all from. + /// An of . + /// Thrown when is null. + public static IEnumerable GetChartDataRecursively(ChartDataCollection chartDataCollection) + { + if (chartDataCollection == null) + { + throw new ArgumentNullException(nameof(chartDataCollection)); + } + + var chartDataList = new List(); + + foreach (ChartData chartData in chartDataCollection.Collection) + { + var nestedChartDataCollection = chartData as ChartDataCollection; + if (nestedChartDataCollection != null) + { + chartDataList.AddRange(GetChartDataRecursively(nestedChartDataCollection)); + continue; + } + + chartDataList.Add(chartData); + } + + return chartDataList; + } + private static object[] GetChildNodeObjects(ChartDataCollection chartDataCollection) { return chartDataCollection.Collection.Reverse().Select(chartData => new ChartDataContext(chartData, chartDataCollection)).Cast().ToArray(); Index: Core/Plugins/src/Core.Plugins.Chart/Properties/Resources.Designer.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Plugins/src/Core.Plugins.Chart/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Plugins/src/Core.Plugins.Chart/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -1,28 +1,7 @@ -// Copyright (C) Stichting Deltares 2017. All rights reserved. -// -// This file is part of Ringtoets. -// -// Ringtoets is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see . -// -// All names, logos, and references to "Deltares" are registered trademarks of -// Stichting Deltares and remain full property of Stichting Deltares at all times. -// All rights reserved. - -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.17929 +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -102,6 +81,62 @@ } /// + /// Looks up a localized string similar to Om het zoomniveau aan te passen moet minstens één van de zichtbare gegevensreeksen in deze map met gegevensreeksen elementen bevatten.. + /// + public static string ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_NoData_ZoomToAllDisabled_Tooltip { + get { + return ResourceManager.GetString("ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_NoData_ZoomToAllDisab" + + "led_Tooltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Zet het zoomniveau van de grafiek dusdanig dat alle zichtbare gegevensreeksen in deze map met gegevensreeksen precies in het beeld passen.. + /// + public static string ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_ZoomToAll_Tooltip { + get { + return ResourceManager.GetString("ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_ZoomToAll_Tooltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Om het zoomniveau aan te passen moet er minstens één gegevensreeks in deze map met gegevensreeksen zichtbaar zijn.. + /// + public static string ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_ZoomToAllDisabled_Tooltip { + get { + return ResourceManager.GetString("ChartLegendView_CreateZoomToExtentsItem_ChartDataCollection_ZoomToAllDisabled_Too" + + "ltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Om het zoomniveau aan te passen moet de gegevensreeks elementen bevatten.. + /// + public static string ChartLegendView_CreateZoomToExtentsItem_NoFeatures_ZoomToAllDisabled_Tooltip { + get { + return ResourceManager.GetString("ChartLegendView_CreateZoomToExtentsItem_NoFeatures_ZoomToAllDisabled_Tooltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Zet het zoomniveau van de grafiek dusdanig dat deze gegevensreeks precies in het beeld past.. + /// + public static string ChartLegendView_CreateZoomToExtentsItem_ZoomToAll_Tooltip { + get { + return ResourceManager.GetString("ChartLegendView_CreateZoomToExtentsItem_ZoomToAll_Tooltip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Om het zoomniveau aan te passen moet de gegevensreeks zichtbaar zijn.. + /// + public static string ChartLegendView_CreateZoomToExtentsItem_ZoomToAllDisabled_Tooltip { + get { + return ResourceManager.GetString("ChartLegendView_CreateZoomToExtentsItem_ZoomToAllDisabled_Tooltip", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Grafiek. /// public static string General_Chart { Index: Core/Plugins/src/Core.Plugins.Chart/Properties/Resources.resx =================================================================== diff -u -r31d4921763c045040f9300542aed356147966cc8 -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Plugins/src/Core.Plugins.Chart/Properties/Resources.resx (.../Resources.resx) (revision 31d4921763c045040f9300542aed356147966cc8) +++ Core/Plugins/src/Core.Plugins.Chart/Properties/Resources.resx (.../Resources.resx) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -175,4 +175,22 @@ Diagram + + Zet het zoomniveau van de grafiek dusdanig dat deze gegevensreeks precies in het beeld past. + + + Om het zoomniveau aan te passen moet de gegevensreeks elementen bevatten. + + + Om het zoomniveau aan te passen moet de gegevensreeks zichtbaar zijn. + + + Om het zoomniveau aan te passen moet minstens één van de zichtbare gegevensreeksen in deze map met gegevensreeksen elementen bevatten. + + + Om het zoomniveau aan te passen moet er minstens één gegevensreeks in deze map met gegevensreeksen zichtbaar zijn. + + + Zet het zoomniveau van de grafiek dusdanig dat alle zichtbare gegevensreeksen in deze map met gegevensreeksen precies in het beeld passen. + \ No newline at end of file Index: Core/Plugins/test/Core.Plugins.Chart.Test/ChartingRibbonTest.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Plugins/test/Core.Plugins.Chart.Test/ChartingRibbonTest.cs (.../ChartingRibbonTest.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Plugins/test/Core.Plugins.Chart.Test/ChartingRibbonTest.cs (.../ChartingRibbonTest.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -139,7 +139,7 @@ chart.Expect(c => c.IsPanningEnabled).Return(true); chart.Expect(c => c.IsRectangleZoomingEnabled).Return(true); - chart.Expect(c => c.ZoomToAll()); + chart.Expect(c => c.ZoomToAllVisibleLayers()); mocks.ReplayAll(); Index: Core/Plugins/test/Core.Plugins.Chart.Test/Commands/ToggleLegendViewCommandTest.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Plugins/test/Core.Plugins.Chart.Test/Commands/ToggleLegendViewCommandTest.cs (.../ToggleLegendViewCommandTest.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Plugins/test/Core.Plugins.Chart.Test/Commands/ToggleLegendViewCommandTest.cs (.../ToggleLegendViewCommandTest.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -23,6 +23,7 @@ using Core.Common.Controls.Commands; using Core.Common.Controls.Views; using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms.ViewHost; using Core.Plugins.Chart.Commands; using Core.Plugins.Chart.Legend; @@ -51,6 +52,7 @@ { // Setup var mocks = new MockRepository(); + var contextMenuBuilderProvider = mocks.StrictMock(); var viewController = mocks.StrictMock(); if (open) @@ -67,7 +69,7 @@ mocks.ReplayAll(); - var controller = new ChartLegendController(viewController); + var controller = new ChartLegendController(viewController, contextMenuBuilderProvider); var command = new ToggleLegendViewCommand(controller); if (open) @@ -88,6 +90,7 @@ { // Setup var mocks = new MockRepository(); + var contextMenuBuilderProvider = mocks.StrictMock(); var viewController = mocks.StrictMock(); var viewHost = mocks.Stub(); var toolViewList = new List(); @@ -104,7 +107,7 @@ mocks.ReplayAll(); - var controller = new ChartLegendController(viewController); + var controller = new ChartLegendController(viewController, contextMenuBuilderProvider); var command = new ToggleLegendViewCommand(controller); // Call Index: Core/Plugins/test/Core.Plugins.Chart.Test/Core.Plugins.Chart.Test.csproj =================================================================== diff -u -r6a5d7b40b7ba4dcb73e393075338352d194e97c2 -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Plugins/test/Core.Plugins.Chart.Test/Core.Plugins.Chart.Test.csproj (.../Core.Plugins.Chart.Test.csproj) (revision 6a5d7b40b7ba4dcb73e393075338352d194e97c2) +++ Core/Plugins/test/Core.Plugins.Chart.Test/Core.Plugins.Chart.Test.csproj (.../Core.Plugins.Chart.Test.csproj) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -109,6 +109,10 @@ {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98} Core.Common.Utils + + {26214BD0-DAFB-4CFC-8EB2-80C5D53C859E} + Core.Common.Gui.TestUtil + {D749EE4C-CE50-4C17-BF01-9A953028C126} Core.Common.TestUtil Index: Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataCollectionTreeNodeInfoTest.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataCollectionTreeNodeInfoTest.cs (.../ChartDataCollectionTreeNodeInfoTest.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataCollectionTreeNodeInfoTest.cs (.../ChartDataCollectionTreeNodeInfoTest.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -25,6 +25,7 @@ using System.Linq; using Core.Common.Base; using Core.Common.Controls.TreeView; +using Core.Common.Gui.ContextMenu; using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Charting.Data; @@ -42,12 +43,17 @@ { private ChartLegendView chartLegendView; private TreeNodeInfo info; + private MockRepository mocks; [SetUp] public void SetUp() { - chartLegendView = new ChartLegendView(); + mocks = new MockRepository(); + var contextMenuBuilderProvider = mocks.Stub(); + mocks.ReplayAll(); + chartLegendView = new ChartLegendView(contextMenuBuilderProvider); + var treeViewControl = TypeUtils.GetField(chartLegendView, "treeViewControl"); var treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); @@ -58,6 +64,7 @@ public void TearDown() { chartLegendView.Dispose(); + mocks.VerifyAll(); } [Test] @@ -67,7 +74,7 @@ Assert.IsNotNull(info.Text); Assert.IsNull(info.ForeColor); Assert.IsNotNull(info.Image); - Assert.IsNull(info.ContextMenuStrip); + Assert.IsNotNull(info.ContextMenuStrip); Assert.IsNull(info.EnsureVisibleOnCreate); Assert.IsNull(info.ExpandOnCreate); Assert.IsNotNull(info.ChildNodeObjects); Index: Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataContextTreeNodeInfoTest.cs =================================================================== diff -u -rb28507193a2799b3e4a4e5e447693e17e1e121b5 -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataContextTreeNodeInfoTest.cs (.../ChartDataContextTreeNodeInfoTest.cs) (revision b28507193a2799b3e4a4e5e447693e17e1e121b5) +++ Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartDataContextTreeNodeInfoTest.cs (.../ChartDataContextTreeNodeInfoTest.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -23,8 +23,12 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; +using System.Windows.Forms; using Core.Common.Base; +using Core.Common.Base.Geometry; using Core.Common.Controls.TreeView; +using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.TestUtil.ContextMenu; using Core.Common.TestUtil; using Core.Common.Utils.Reflection; using Core.Components.Charting.Data; @@ -41,8 +45,12 @@ [TestFixture] public class ChartDataContextTreeNodeInfoTest { + private const int contextMenuZoomToAllIndex = 0; + private ChartLegendView chartLegendView; private TreeNodeInfo info; + private MockRepository mocks; + private IContextMenuBuilderProvider contextMenuBuilderProvider; private static IEnumerable ChartDataLegendImages { @@ -107,8 +115,12 @@ [SetUp] public void SetUp() { - chartLegendView = new ChartLegendView(); + mocks = new MockRepository(); + contextMenuBuilderProvider = mocks.StrictMock(); + mocks.ReplayAll(); + chartLegendView = new ChartLegendView(contextMenuBuilderProvider); + var treeViewControl = TypeUtils.GetField(chartLegendView, "treeViewControl"); var treeNodeInfoLookup = TypeUtils.GetField>(treeViewControl, "tagTypeTreeNodeInfoLookup"); @@ -119,6 +131,7 @@ public void TearDown() { chartLegendView.Dispose(); + mocks.VerifyAll(); } [Test] @@ -128,7 +141,7 @@ Assert.IsNotNull(info.Text); Assert.IsNull(info.ForeColor); Assert.IsNotNull(info.Image); - Assert.IsNull(info.ContextMenuStrip); + Assert.IsNotNull(info.ContextMenuStrip); Assert.IsNull(info.EnsureVisibleOnCreate); Assert.IsNull(info.ExpandOnCreate); Assert.IsNotNull(info.ChildNodeObjects); @@ -289,7 +302,6 @@ public void OnNodeChecked_Always_SetsPointDataVisibilityAndNotifiesParentObservers(ChartData chartData, bool initialVisibleState) { // Setup - var mocks = new MockRepository(); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); @@ -418,7 +430,6 @@ public void OnDrop_ChartDataMovedToPositionInsideRange_SetsNewReverseOrder(int position) { // Setup - var mocks = new MockRepository(); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); @@ -459,7 +470,6 @@ public void OnDrop_ChartDataMovedToPositionOutsideRange_ThrowsException(int position) { // Setup - var mocks = new MockRepository(); var observer = mocks.StrictMock(); mocks.ReplayAll(); @@ -479,23 +489,125 @@ chartDataCollection.Attach(observer); chartLegendView.Data = chartDataCollection; - ChartDataContext context1 = GetContext(chartData1); + ChartDataContext context = GetContext(chartData1); ChartDataContext collectionContext = GetContext(chartDataCollection); chartDataCollection.Attach(observer); using (var treeViewControl = new TreeViewControl()) { // Call - TestDelegate test = () => info.OnDrop(context1, collectionContext, collectionContext, position, treeViewControl); + TestDelegate test = () => info.OnDrop(context, collectionContext, collectionContext, position, treeViewControl); // Assert Assert.Throws(test); mocks.VerifyAll(); // Expect no update observer. } } + [Test] + [TestCaseSource(nameof(NoChartDataCollection))] + public void ContextMenuStrip_DifferentTypesOfChartData_CallsBuilder(ChartData chartData) + { + // Setup + var builder = mocks.StrictMock(); + using (mocks.Ordered()) + { + builder.Expect(mb => mb.AddCustomItem(Arg.Is.NotNull)).Return(builder); + builder.Expect(mb => mb.Build()).Return(null); + } + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + mocks.ReplayAll(); + + // Call + info.ContextMenuStrip(GetContext(chartData), null, null); + + // Assert + // Assert expectancies are called in TearDown() + } + + [Test] + public void ContextMenuStrip_VisibleMapData_ZoomToAllItemEnabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + var mapData = new ChartLineData("A") + { + IsVisible = true, + Points = new[] + { + new Point2D(0, 1) + } + }; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapData), null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Zet het zoomniveau van de grafiek dusdanig dat deze gegevensreeks precies in het beeld past.", + Resources.ZoomToAllIcon); + } + } + + [Test] + public void ContextMenuStrip_InvisibleMapData_ZoomToAllItemDisabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + var mapData = new ChartLineData("A") + { + IsVisible = false + }; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapData), null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Om het zoomniveau aan te passen moet de gegevensreeks zichtbaar zijn.", + Resources.ZoomToAllIcon, + false); + } + } + + [Test] + public void ContextMenuStrip_MapDataWithoutFeatures_ZoomToAllItemDisabled() + { + // Setup + var builder = new CustomItemsOnlyContextMenuBuilder(); + contextMenuBuilderProvider.Expect(p => p.Get(null, null)).IgnoreArguments().Return(builder); + + mocks.ReplayAll(); + + var mapData = new ChartLineData("A") + { + IsVisible = true + }; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(GetContext(mapData), null, null)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuZoomToAllIndex, + "&Zoom naar alles", + "Om het zoomniveau aan te passen moet de gegevensreeks elementen bevatten.", + Resources.ZoomToAllIcon, + false); + } + } + private static ChartDataContext GetContext(ChartData chartData, ChartDataCollection chartDataCollection = null) { return new ChartDataContext(chartData, chartDataCollection ?? new ChartDataCollection("test")); Index: Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartLegendControllerTest.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartLegendControllerTest.cs (.../ChartLegendControllerTest.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartLegendControllerTest.cs (.../ChartLegendControllerTest.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -23,6 +23,7 @@ using System.Collections.Generic; using Core.Common.Controls.Views; using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms.ViewHost; using Core.Plugins.Chart.Legend; using NUnit.Framework; @@ -34,26 +35,50 @@ public class ChartLegendControllerTest { [Test] - public void Constructor_WithoutPlugin_ThrowsArgumentNullException() + public void Constructor_WithoutViewController_ThrowsArgumentNullException() { + // Setup + var mocks = new MockRepository(); + var menuBuilderProvider = mocks.Stub(); + + mocks.ReplayAll(); // Call - TestDelegate test = () => new ChartLegendController(null); + TestDelegate test = () => new ChartLegendController(null, menuBuilderProvider); // Assert - Assert.Throws(test); + var exception = Assert.Throws(test); + Assert.AreEqual("viewController", exception.ParamName); } [Test] + public void Constructor_WithoutContextMenuBuilderProvider_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var viewController = mocks.StrictMock(); + + mocks.ReplayAll(); + + // Call + TestDelegate test = () => new ChartLegendController(viewController, null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("contextMenuBuilderProvider", exception.ParamName); + } + + [Test] public void Constructor_WithViewController_DoesNotThrow() { // Setup var mocks = new MockRepository(); var viewController = mocks.StrictMock(); + var menuBuilderProvider = mocks.Stub(); mocks.ReplayAll(); // Call - TestDelegate test = () => new ChartLegendController(viewController); + TestDelegate test = () => new ChartLegendController(viewController, menuBuilderProvider); // Assert Assert.DoesNotThrow(test); @@ -68,6 +93,7 @@ // Setup var mocks = new MockRepository(); var viewController = mocks.StrictMock(); + var menuBuilderProvider = mocks.Stub(); if (open) { @@ -82,7 +108,7 @@ mocks.ReplayAll(); - var controller = new ChartLegendController(viewController); + var controller = new ChartLegendController(viewController, menuBuilderProvider); if (open) { @@ -104,6 +130,7 @@ { // Setup var mocks = new MockRepository(); + var menuBuilderProvider = mocks.Stub(); var viewController = mocks.StrictMock(); var viewHost = mocks.StrictMock(); @@ -122,7 +149,7 @@ mocks.ReplayAll(); - var controller = new ChartLegendController(viewController); + var controller = new ChartLegendController(viewController, menuBuilderProvider); if (open) { Index: Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartLegendViewTest.cs =================================================================== diff -u -r67284323e2785c651633d9c52049ba12a9c70e6a -rc349a104ffe6e2b39878cd0169cace7eea4fddb6 --- Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartLegendViewTest.cs (.../ChartLegendViewTest.cs) (revision 67284323e2785c651633d9c52049ba12a9c70e6a) +++ Core/Plugins/test/Core.Plugins.Chart.Test/Legend/ChartLegendViewTest.cs (.../ChartLegendViewTest.cs) (revision c349a104ffe6e2b39878cd0169cace7eea4fddb6) @@ -25,37 +25,60 @@ using System.Windows.Forms; using Core.Common.Controls.TreeView; using Core.Common.Controls.Views; +using Core.Common.Gui.ContextMenu; using Core.Common.Utils.Reflection; using Core.Components.Charting.Data; using Core.Plugins.Chart.Legend; using Core.Plugins.Chart.PresentationObjects; using Core.Plugins.Chart.Properties; using NUnit.Framework; +using Rhino.Mocks; namespace Core.Plugins.Chart.Test.Legend { [TestFixture] public class ChartLegendViewTest { [Test] - public void DefaultConstructor_CreatesUserControl() + public void Constructor_WithoutContextMenuBuilderProvider_CreatesUserControl() { // Call - using (var view = new ChartLegendView()) + var exception = Assert.Throws(() => new ChartLegendView(null)); + + // Assert + Assert.AreEqual("contextMenuBuilderProvider", exception.ParamName); + } + + [Test] + public void Constructor_WithBuilderProvider_CreatesUserControl() + { + // Setup + var mocks = new MockRepository(); + var menuBuilderProvider = mocks.Stub(); + mocks.ReplayAll(); + + // Call + using (var view = new ChartLegendView(menuBuilderProvider)) { // Assert Assert.IsInstanceOf(view); Assert.IsInstanceOf(view); Assert.IsNull(view.Data); Assert.AreEqual(Resources.General_Chart, view.Text); } + + mocks.VerifyAll(); } [Test] public void Data_ChartControl_DataSet() { // Setup - using (var view = new ChartLegendView()) + var mocks = new MockRepository(); + var menuBuilderProvider = mocks.Stub(); + mocks.ReplayAll(); + + using (var view = new ChartLegendView(menuBuilderProvider)) { var chartDataCollection = new ChartDataCollection("test data"); @@ -65,34 +88,48 @@ // Assert Assert.AreSame(chartDataCollection, view.Data); } + + mocks.VerifyAll(); } [Test] public void Data_ForNull_NullSet() { // Setup - using (var view = new ChartLegendView()) + var mocks = new MockRepository(); + var menuBuilderProvider = mocks.Stub(); + mocks.ReplayAll(); + + using (var view = new ChartLegendView(menuBuilderProvider)) { // Call view.Data = null; // Assert Assert.IsNull(view.Data); } + + mocks.VerifyAll(); } [Test] public void Data_OtherObject_ThrowsInvalidCastException() { // Setup - using (var view = new ChartLegendView()) + var mocks = new MockRepository(); + var menuBuilderProvider = mocks.Stub(); + mocks.ReplayAll(); + + using (var view = new ChartLegendView(menuBuilderProvider)) { // Call TestDelegate test = () => view.Data = new object(); // Assert Assert.Throws(test); } + + mocks.VerifyAll(); } [Test] @@ -102,14 +139,18 @@ public void GivenChartDataContainingCollection_WhenDragDroppingFromRootToRoot_ThenDataPositionChanged(int index) { // Given + var mocks = new MockRepository(); + var menuBuilderProvider = mocks.Stub(); + mocks.ReplayAll(); + ChartData chartLineData = CreateChartLineData(); var rootCollection = new ChartDataCollection("test data"); rootCollection.Add(chartLineData); rootCollection.Add(CreateChartLineData()); rootCollection.Add(CreateChartLineData()); - using (var chartLegendView = new ChartLegendView + using (var chartLegendView = new ChartLegendView(menuBuilderProvider) { Data = rootCollection }) @@ -126,6 +167,8 @@ // Then Assert.AreEqual(2 - index, rootCollection.Collection.ToList().IndexOf(chartLineData)); } + + mocks.VerifyAll(); } private ChartData CreateChartLineData()