1 | using System;
|
---|
2 | using System.Collections;
|
---|
3 | using System.Collections.Generic;
|
---|
4 | using System.Collections.Specialized;
|
---|
5 | using System.Diagnostics;
|
---|
6 | using System.Windows;
|
---|
7 |
|
---|
8 | namespace Microsoft.Research.DynamicDataDisplay.DataSources
|
---|
9 | {
|
---|
10 | /// <summary>Base class for all sources who receive data for charting
|
---|
11 | /// from any IEnumerable of T</summary>
|
---|
12 | /// <typeparam name="T">Type of items in IEnumerable</typeparam>
|
---|
13 | public abstract class EnumerableDataSourceBase<T> : IPointDataSource {
|
---|
14 | private IEnumerable data;
|
---|
15 |
|
---|
16 | /// <summary>
|
---|
17 | /// Gets or sets the data.
|
---|
18 | /// </summary>
|
---|
19 | /// <value>The data.</value>
|
---|
20 | public IEnumerable Data {
|
---|
21 | get { return data; }
|
---|
22 | set {
|
---|
23 | if (value == null)
|
---|
24 | throw new ArgumentNullException("value");
|
---|
25 |
|
---|
26 | data = value;
|
---|
27 |
|
---|
28 | var observableCollection = data as INotifyCollectionChanged;
|
---|
29 | if (observableCollection != null) {
|
---|
30 | observableCollection.CollectionChanged += observableCollection_CollectionChanged;
|
---|
31 | }
|
---|
32 | }
|
---|
33 | }
|
---|
34 |
|
---|
35 | protected EnumerableDataSourceBase(IEnumerable<T> data) : this((IEnumerable)data) { }
|
---|
36 |
|
---|
37 | protected EnumerableDataSourceBase(IEnumerable data) {
|
---|
38 | if (data == null)
|
---|
39 | throw new ArgumentNullException("data");
|
---|
40 | Data = data;
|
---|
41 | }
|
---|
42 |
|
---|
43 | private void observableCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) {
|
---|
44 | RaiseDataChanged();
|
---|
45 | }
|
---|
46 |
|
---|
47 | public event EventHandler DataChanged;
|
---|
48 | public void RaiseDataChanged() {
|
---|
49 | if (DataChanged != null) {
|
---|
50 | DataChanged(this, EventArgs.Empty);
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | public abstract IPointEnumerator GetEnumerator(DependencyObject context);
|
---|
55 | }
|
---|
56 | }
|
---|