Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Analysis/3.3/DataVisualization/IndexedDataRow.cs @ 15692

Last change on this file since 15692 was 15584, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers on stable

File size: 4.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Collections;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26using System;
27using System.Collections.Generic;
28using System.ComponentModel;
29using System.Linq;
30
31namespace HeuristicLab.Analysis {
32  [Item("IndexedDataRow", "A data row that contains a series of points.")]
33  [StorableClass]
34  public class IndexedDataRow<T> : NamedItem {
35
36    private DataRowVisualProperties visualProperties;
37    public DataRowVisualProperties VisualProperties {
38      get { return visualProperties; }
39      set {
40        if (visualProperties != value) {
41          if (value == null) throw new ArgumentNullException("VisualProperties");
42          if (visualProperties != null) visualProperties.PropertyChanged -= new PropertyChangedEventHandler(VisualProperties_PropertyChanged);
43          visualProperties = value;
44          visualProperties.PropertyChanged += new PropertyChangedEventHandler(VisualProperties_PropertyChanged);
45          OnVisualPropertiesChanged();
46        }
47      }
48    }
49    private ObservableList<Tuple<T, double>> values;
50    public ObservableList<Tuple<T, double>> Values {
51      get { return values; }
52    }
53
54    #region Persistence Properties
55    [Storable(Name = "visualProperties")]
56    private DataRowVisualProperties StorableVisualProperties {
57      get { return visualProperties; }
58      set { visualProperties = value; }
59    }
60    [Storable(Name = "values")]
61    private IEnumerable<Tuple<T, double>> StorableValues {
62      get { return values; }
63      set { values = new ObservableList<Tuple<T, double>>(value); }
64    }
65    #endregion
66
67    [StorableConstructor]
68    protected IndexedDataRow(bool deserializing) : base(deserializing) { }
69    protected IndexedDataRow(IndexedDataRow<T> original, Cloner cloner)
70      : base(original, cloner) {
71      values = new ObservableList<Tuple<T, double>>(original.values.Select(x => Tuple.Create<T, double>(x.Item1, x.Item2)).ToList());
72      VisualProperties = cloner.Clone(original.visualProperties);
73    }
74    public IndexedDataRow() {
75      values = new ObservableList<Tuple<T, double>>();
76      VisualProperties = new DataRowVisualProperties();
77    }
78    public IndexedDataRow(string name)
79      : base(name) {
80      values = new ObservableList<Tuple<T, double>>();
81      VisualProperties = new DataRowVisualProperties(name);
82    }
83    public IndexedDataRow(string name, string description)
84      : base(name, description) {
85      values = new ObservableList<Tuple<T, double>>();
86      VisualProperties = new DataRowVisualProperties(name);
87    }
88    public IndexedDataRow(string name, string description, IEnumerable<Tuple<T, double>> values)
89      : base(name, description) {
90      this.values = new ObservableList<Tuple<T, double>>(values);
91      VisualProperties = new DataRowVisualProperties(name);
92    }
93
94    public override IDeepCloneable Clone(Cloner cloner) {
95      return new IndexedDataRow<T>(this, cloner);
96    }
97
98    public event EventHandler VisualPropertiesChanged;
99    protected virtual void OnVisualPropertiesChanged() {
100      EventHandler handler = VisualPropertiesChanged;
101      if (handler != null) handler(this, EventArgs.Empty);
102    }
103
104    private void VisualProperties_PropertyChanged(object sender, PropertyChangedEventArgs e) {
105      OnVisualPropertiesChanged();
106    }
107    protected override void OnNameChanged() {
108      base.OnNameChanged();
109      VisualProperties.DisplayName = Name;
110    }
111  }
112}
Note: See TracBrowser for help on using the repository browser.