using System; using System.Collections.Generic; using Core.Components.Charting.Data; using OxyPlot; using OxyPlot.Series; namespace Core.Components.OxyPlot.Converter { /// /// Provides an abstract base class for transforming in specific /// instances. /// public abstract class ChartDataConverter : IChartDataConverter where T : ChartData { public bool CanConvertSeries(ChartData data) { return data.GetType() == typeof(T); } public IList Convert(ChartData data) { if (data == null) { throw new ArgumentNullException("Null data cannot be converted into series."); } if (!CanConvertSeries(data)) { var message = string.Format("The data of type {0} cannot be converted by this converter.", data.GetType()); throw new ArgumentException(message); } return Convert((T) data); } /// /// Transforms a given object into a . Can be used as a /// . /// /// The object to convert into a . /// A new based on . /// Thrown when is not /// of type of . protected static DataPoint TupleToDataPoint(object obj) { var point = (Tuple) obj; return new DataPoint(point.Item1, point.Item2); } /// /// Creates one or more based on the that was given. /// /// The data to transform into a . /// A new of . protected abstract IList Convert(T data); } }