using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; namespace Microsoft.Research.DynamicDataDisplay.DataSources { public static class DataSourceExtensions { public static RawDataSource AsDataSource(this IEnumerable points) { return new RawDataSource(points); } public static EnumerableDataSource AsDataSource(this IEnumerable collection) { return new EnumerableDataSource(collection); } public static EnumerableDataSource AsXDataSource(this IEnumerable collection) { if (typeof(T) == typeof(double)) { return ((IEnumerable)collection).AsXDataSource() as EnumerableDataSource; } else if (typeof(T) == typeof(float)) { return ((IEnumerable)collection).AsXDataSource() as EnumerableDataSource; } return new EnumerableXDataSource(collection); } public static EnumerableDataSource AsXDataSource(this IEnumerable collection) { EnumerableXDataSource ds = new EnumerableXDataSource(collection); ds.SetXMapping(f => (double)f); return ds; } public static EnumerableDataSource AsYDataSource(this IEnumerable collection) { if (typeof(T) == typeof(double)) { return ((IEnumerable)collection).AsYDataSource() as EnumerableDataSource; } else if (typeof(T) == typeof(float)) { return ((IEnumerable)collection).AsYDataSource() as EnumerableDataSource; } return new EnumerableYDataSource(collection); } public static EnumerableDataSource AsXDataSource(this IEnumerable collection) { EnumerableXDataSource ds = new EnumerableXDataSource(collection); ds.SetXMapping(x => x); return ds; } public static EnumerableDataSource AsYDataSource(this IEnumerable collection) { EnumerableYDataSource ds = new EnumerableYDataSource(collection); ds.SetYMapping(y => y); return ds; } public static EnumerableDataSource AsYDataSource(this IEnumerable collection) { EnumerableYDataSource ds = new EnumerableYDataSource(collection); ds.SetYMapping(f => (double)f); return ds; } public static CompositeDataSource Join(this IPointDataSource ds1, IPointDataSource ds2) { return new CompositeDataSource(ds1, ds2); } public static IEnumerable GetPoints(this IPointDataSource dataSource) { return DataSourceHelper.GetPoints(dataSource); } public static IEnumerable GetPoints(this IPointDataSource dataSource, DependencyObject context) { return DataSourceHelper.GetPoints(dataSource, context); } } }