Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Analysis/3.3/DataVisualization/ScatterPlot.cs @ 9324

Last change on this file since 9324 was 7829, checked in by abeham, 13 years ago

#1850: added and modified the scatter plot from the FLA branch

File size: 6.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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 System;
23using System.Collections.Generic;
24using System.Drawing;
25using System.Linq;
26using HeuristicLab.Collections;
27using HeuristicLab.Common;
28using HeuristicLab.Core;
29using HeuristicLab.Data;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32namespace HeuristicLab.Analysis {
33  [Item("ScatterPlot", "A scatter plot of 2D data")]
34  [StorableClass]
35  public class ScatterPlot : NamedItem, IStringConvertibleMatrix {
36    public static new Image StaticItemImage {
37      get { return HeuristicLab.Common.Resources.VSImageLibrary.Performance; }
38    }
39
40    [Storable]
41    private ObservableList<PointF> points;
42    public ObservableList<PointF> Points {
43      get { return points; }
44    }
45
46    [Storable]
47    private string xAxisName;
48    public string XAxisName {
49      get { return xAxisName; }
50      set {
51        if (value == xAxisName) return;
52        xAxisName = value;
53        OnAxesNameChanged();
54      }
55    }
56
57    [Storable]
58    private string yAxisName;
59    public string YAxisName {
60      get { return yAxisName; }
61      set {
62        if (value == yAxisName) return;
63        yAxisName = value;
64        OnAxesNameChanged();
65      }
66    }
67
68    [StorableConstructor]
69    protected ScatterPlot(bool deserializing) : base(deserializing) { }
70    protected ScatterPlot(ScatterPlot original, Cloner cloner)
71      : base(original, cloner) {
72      points = new ObservableList<PointF>(original.points);
73      xAxisName = original.xAxisName;
74      yAxisName = original.yAxisName;
75    }
76    public ScatterPlot()
77      : base() {
78      this.points = new ObservableList<PointF>();
79    }
80    public ScatterPlot(string name)
81      : base(name) {
82      this.points = new ObservableList<PointF>();
83    }
84    public ScatterPlot(string name, string description)
85      : base(name, description) {
86      this.points = new ObservableList<PointF>();
87    }
88    public ScatterPlot(string name, string description, string xAxisName, string yAxisName)
89      : base(name, description) {
90      this.points = new ObservableList<PointF>();
91      this.xAxisName = xAxisName;
92      this.yAxisName = yAxisName;
93    }
94    public ScatterPlot(IEnumerable<PointF> points)
95      : base() {
96      this.points = new ObservableList<PointF>(points);
97    }
98    public ScatterPlot(IEnumerable<PointF> points, string name)
99      : base(name) {
100      this.points = new ObservableList<PointF>(points);
101    }
102    public ScatterPlot(IEnumerable<PointF> points, string name, string description)
103      : base(name, description) {
104      this.points = new ObservableList<PointF>(points);
105    }
106    public ScatterPlot(IEnumerable<PointF> points, string name, string description, string xAxisName, string yAxisName)
107      : base(name, description) {
108      this.points = new ObservableList<PointF>(points);
109      this.xAxisName = xAxisName;
110      this.yAxisName = yAxisName;
111    }
112
113    public override IDeepCloneable Clone(Cloner cloner) {
114      return new ScatterPlot(this, cloner);
115    }
116
117    public event EventHandler AxisNameChanged;
118    protected virtual void OnAxesNameChanged() {
119      EventHandler handler = AxisNameChanged;
120      if (handler != null)
121        handler(this, EventArgs.Empty);
122    }
123
124    #region IStringConvertibleMatrix Members
125
126    int IStringConvertibleMatrix.Rows {
127      get { return points.Count; }
128      set { throw new NotSupportedException(); }
129    }
130    int IStringConvertibleMatrix.Columns {
131      get { return 2; }
132      set { throw new NotSupportedException(); }
133    }
134    IEnumerable<string> IStringConvertibleMatrix.ColumnNames {
135      get { return new string[] { xAxisName, yAxisName }; }
136      set { throw new NotSupportedException(); }
137    }
138    IEnumerable<string> IStringConvertibleMatrix.RowNames {
139      get { return Enumerable.Empty<string>(); }
140      set { throw new NotSupportedException(); }
141    }
142
143    bool IStringConvertibleMatrix.SortableView {
144      get { return false; }
145      set { throw new NotSupportedException(); }
146    }
147    bool IStringConvertibleMatrix.ReadOnly {
148      get { return true; }
149    }
150
151    string IStringConvertibleMatrix.GetValue(int rowIndex, int columnIndex) {
152      if (rowIndex < points.Count && columnIndex < 2) {
153        return columnIndex == 0 ? points[rowIndex].X.ToString() : points[rowIndex].Y.ToString();
154      }
155      return string.Empty;
156    }
157
158    bool IStringConvertibleMatrix.Validate(string value, out string errorMessage) {
159      throw new NotSupportedException();
160    }
161    bool IStringConvertibleMatrix.SetValue(string value, int rowIndex, int columnIndex) {
162      throw new NotSupportedException();
163    }
164
165    public event EventHandler<EventArgs<int, int>> ItemChanged;
166    protected virtual void OnItemChanged(int rowIndex, int columnIndex) {
167      var handler = ItemChanged;
168      if (handler != null) handler(this, new EventArgs<int, int>(rowIndex, columnIndex));
169      OnToStringChanged();
170    }
171    public event EventHandler Reset;
172    protected virtual void OnReset() {
173      var handler = Reset;
174      if (handler != null) handler(this, EventArgs.Empty);
175    }
176    public event EventHandler ColumnsChanged;
177    protected virtual void OnColumnsChanged() {
178      var handler = ColumnsChanged;
179      if (handler != null) handler(this, EventArgs.Empty);
180    }
181    public event EventHandler RowsChanged;
182    protected virtual void OnRowsChanged() {
183      var handler = RowsChanged;
184      if (handler != null) handler(this, EventArgs.Empty);
185    }
186    public event EventHandler ColumnNamesChanged;
187    protected virtual void OnColumnNamesChanged() {
188      var handler = ColumnNamesChanged;
189      if (handler != null) handler(this, EventArgs.Empty);
190    }
191    public event EventHandler RowNamesChanged;
192    protected virtual void OnRowNamesChanged() {
193      var handler = RowNamesChanged;
194      if (handler != null) handler(this, EventArgs.Empty);
195    }
196    public event EventHandler SortableViewChanged;
197    protected virtual void OnSortableViewChanged() {
198      var handler = SortableViewChanged;
199      if (handler != null) handler(this, EventArgs.Empty);
200    }
201    #endregion
202  }
203}
Note: See TracBrowser for help on using the repository browser.