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