Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/DataSources/OneDimensional/DataSourceExtensions.cs @ 13792

Last change on this file since 13792 was 12503, checked in by aballeit, 9 years ago

#2283 added GUI and charts; fixed MCTS

File size: 2.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows;
6
7namespace Microsoft.Research.DynamicDataDisplay.DataSources
8{
9  public static class DataSourceExtensions
10  {
11    public static RawDataSource AsDataSource(this IEnumerable<Point> points)
12    {
13      return new RawDataSource(points);
14    }
15
16    public static EnumerableDataSource<T> AsDataSource<T>(this IEnumerable<T> collection)
17    {
18      return new EnumerableDataSource<T>(collection);
19    }
20
21    public static EnumerableDataSource<T> AsXDataSource<T>(this IEnumerable<T> collection)
22    {
23      if (typeof(T) == typeof(double))
24      {
25        return ((IEnumerable<double>)collection).AsXDataSource() as EnumerableDataSource<T>;
26      }
27      else if (typeof(T) == typeof(float))
28      {
29        return ((IEnumerable<float>)collection).AsXDataSource() as EnumerableDataSource<T>;
30      }
31
32      return new EnumerableXDataSource<T>(collection);
33    }
34
35    public static EnumerableDataSource<float> AsXDataSource(this IEnumerable<float> collection)
36    {
37      EnumerableXDataSource<float> ds = new EnumerableXDataSource<float>(collection);
38      ds.SetXMapping(f => (double)f);
39      return ds;
40    }
41
42    public static EnumerableDataSource<T> AsYDataSource<T>(this IEnumerable<T> collection)
43    {
44      if (typeof(T) == typeof(double))
45      {
46        return ((IEnumerable<double>)collection).AsYDataSource() as EnumerableDataSource<T>;
47      }
48      else if (typeof(T) == typeof(float))
49      {
50        return ((IEnumerable<float>)collection).AsYDataSource() as EnumerableDataSource<T>;
51      }
52
53      return new EnumerableYDataSource<T>(collection);
54    }
55
56    public static EnumerableDataSource<double> AsXDataSource(this IEnumerable<double> collection)
57    {
58      EnumerableXDataSource<double> ds = new EnumerableXDataSource<double>(collection);
59      ds.SetXMapping(x => x);
60      return ds;
61    }
62
63    public static EnumerableDataSource<double> AsYDataSource(this IEnumerable<double> collection)
64    {
65      EnumerableYDataSource<double> ds = new EnumerableYDataSource<double>(collection);
66      ds.SetYMapping(y => y);
67      return ds;
68    }
69
70    public static EnumerableDataSource<float> AsYDataSource(this IEnumerable<float> collection)
71    {
72      EnumerableYDataSource<float> ds = new EnumerableYDataSource<float>(collection);
73      ds.SetYMapping(f => (double)f);
74      return ds;
75    }
76
77    public static CompositeDataSource Join(this IPointDataSource ds1, IPointDataSource ds2)
78    {
79      return new CompositeDataSource(ds1, ds2);
80    }
81
82    public static IEnumerable<Point> GetPoints(this IPointDataSource dataSource)
83    {
84      return DataSourceHelper.GetPoints(dataSource);
85    }
86
87    public static IEnumerable<Point> GetPoints(this IPointDataSource dataSource, DependencyObject context)
88    {
89      return DataSourceHelper.GetPoints(dataSource, context);
90    }
91  }
92}
Note: See TracBrowser for help on using the repository browser.