// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
using System.Collections.Generic;
using System.Linq;
namespace System.Windows.Controls.DataVisualization.Charting
{
///
/// Extension methods for series hosts.
///
internal static class ISeriesHostExtensions
{
///
/// Gets all series that track their global indexes recursively.
///
/// The root series host.
/// A sequence of series.
public static IEnumerable GetDescendentSeries(this ISeriesHost rootSeriesHost)
{
Queue series = new Queue(rootSeriesHost.Series);
while (series.Count != 0)
{
ISeries currentSeries = series.Dequeue();
yield return currentSeries;
ISeriesHost seriesHost = currentSeries as ISeriesHost;
if (seriesHost != null)
{
foreach (ISeries childSeries in seriesHost.Series)
{
series.Enqueue(childSeries);
}
}
}
}
///
/// Gets a value indicating whether an axis is in use by the series
/// host.
///
/// The series host.
/// The axis that may or may not be used by a
/// series.
/// A value indicating whether an axis is in use by the series
/// host.
public static bool IsUsedByASeries(this ISeriesHost that, IAxis axis)
{
return axis.RegisteredListeners.OfType().Intersect(that.Series).Any();
}
}
}