- Timestamp:
- 07/11/12 00:25:26 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Analysis/3.3/DataVisualization
- Files:
-
- 4 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Analysis/3.3/DataVisualization/DataTable.cs
r7259 r8280 59 59 public NamedItemCollection<DataRow> Rows { 60 60 get { return rows; } 61 private set { 62 if (rows != null) throw new InvalidOperationException("Rows already set"); 63 rows = value; 64 if (rows != null) RegisterRowsEvents(); 65 } 61 66 } 62 67 … … 73 78 private IEnumerable<DataRow> StorableRows { 74 79 get { return rows; } 75 set { rows = new NamedItemCollection<DataRow>(value); }80 set { Rows = new NamedItemCollection<DataRow>(value); } 76 81 } 77 82 #endregion … … 81 86 protected DataTable(DataTable original, Cloner cloner) 82 87 : base(original, cloner) { 83 this.VisualProperties = (DataTableVisualProperties)cloner.Clone(original.visualProperties); 84 this.rows = cloner.Clone(original.rows); 85 this.RegisterRowsEvents(); 88 VisualProperties = (DataTableVisualProperties)cloner.Clone(original.visualProperties); 89 Rows = cloner.Clone(original.rows); 86 90 } 87 91 public DataTable() 88 92 : base() { 89 93 VisualProperties = new DataTableVisualProperties(); 90 rows = new NamedItemCollection<DataRow>(); 91 this.RegisterRowsEvents(); 94 Rows = new NamedItemCollection<DataRow>(); 92 95 } 93 96 public DataTable(string name) 94 97 : base(name) { 95 98 VisualProperties = new DataTableVisualProperties(name); 96 rows = new NamedItemCollection<DataRow>(); 97 this.RegisterRowsEvents(); 99 Rows = new NamedItemCollection<DataRow>(); 98 100 } 99 101 public DataTable(string name, string description) 100 102 : base(name, description) { 101 103 VisualProperties = new DataTableVisualProperties(name); 102 rows = new NamedItemCollection<DataRow>(); 103 this.RegisterRowsEvents(); 104 Rows = new NamedItemCollection<DataRow>(); 104 105 } 105 106 … … 217 218 } 218 219 IEnumerable<string> IStringConvertibleMatrix.RowNames { 219 get { return new List<string>(); }220 get { return Enumerable.Empty<string>(); } 220 221 set { throw new NotSupportedException(); } 221 222 } -
trunk/sources/HeuristicLab.Analysis/3.3/DataVisualization/ScatterPlot.cs
r7829 r8280 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel; 24 25 using System.Drawing; 25 26 using System.Linq; … … 38 39 } 39 40 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; } 41 private ScatterPlotVisualProperties visualProperties; 42 public ScatterPlotVisualProperties VisualProperties { 43 get { return visualProperties; } 50 44 set { 51 if (value == xAxisName) return; 52 xAxisName = value; 53 OnAxesNameChanged(); 45 if (visualProperties != value) { 46 if (value == null) throw new ArgumentNullException("VisualProperties"); 47 if (visualProperties != null) visualProperties.PropertyChanged -= new PropertyChangedEventHandler(VisualProperties_PropertyChanged); 48 visualProperties = value; 49 visualProperties.PropertyChanged += new PropertyChangedEventHandler(VisualProperties_PropertyChanged); 50 OnVisualPropertiesChanged(); 51 } 54 52 } 55 53 } 56 54 57 [Storable] 58 private string yAxisName; 59 public string YAxisName { 60 get { return yAxisName; } 55 private NamedItemCollection<ScatterPlotDataRow> rows; 56 public NamedItemCollection<ScatterPlotDataRow> Rows { 57 get { return rows; } 58 private set { 59 if (rows != null) throw new InvalidOperationException("Rows already set"); 60 rows = value; 61 if (rows != null) RegisterRowsEvents(); 62 } 63 } 64 65 #region Persistence Properties 66 [Storable(Name = "VisualProperties")] 67 private ScatterPlotVisualProperties StorableVisualProperties { 68 get { return visualProperties; } 61 69 set { 62 if (value == yAxisName) return; 63 yAxisName = value; 64 OnAxesNameChanged(); 70 visualProperties = value; 71 visualProperties.PropertyChanged += new PropertyChangedEventHandler(VisualProperties_PropertyChanged); 65 72 } 66 73 } 74 [Storable(Name = "Rows")] 75 private IEnumerable<ScatterPlotDataRow> StorableRows { 76 get { return rows; } 77 set { Rows = new NamedItemCollection<ScatterPlotDataRow>(value); } 78 } 79 #endregion 67 80 68 81 [StorableConstructor] … … 70 83 protected ScatterPlot(ScatterPlot original, Cloner cloner) 71 84 : base(original, cloner) { 72 points = new ObservableList<PointF>(original.points); 73 xAxisName = original.xAxisName; 74 yAxisName = original.yAxisName; 85 VisualProperties = cloner.Clone(original.visualProperties); 86 Rows = cloner.Clone(original.rows); 75 87 } 76 88 public ScatterPlot() 77 89 : base() { 78 this.points = new ObservableList<PointF>(); 79 } 80 public ScatterPlot(string name) 81 : base(name) { 82 this.points = new ObservableList<PointF>(); 90 VisualProperties = new ScatterPlotVisualProperties(); 91 Rows = new NamedItemCollection<ScatterPlotDataRow>(); 83 92 } 84 93 public ScatterPlot(string name, string description) 85 94 : base(name, description) { 86 this.points = new ObservableList<PointF>(); 87 } 88 public ScatterPlot(string name, string description, string xAxisName, string yAxisName) 95 VisualProperties = new ScatterPlotVisualProperties(name); 96 Rows = new NamedItemCollection<ScatterPlotDataRow>(); 97 } 98 public ScatterPlot(string name, string description, ScatterPlotVisualProperties visualProperties) 89 99 : 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 } 100 VisualProperties = visualProperties; 101 Rows = new NamedItemCollection<ScatterPlotDataRow>(); 102 } 103 104 // BackwardsCompatibility3.3 105 #region Backwards compatible code, remove with 3.4 106 private ObservableList<PointF> points; 107 [Storable(Name = "points")] 108 private ObservableList<PointF> StorablePoints { 109 set { points = value; } 110 } 111 private string xAxisName; 112 [Storable(Name = "xAxisName")] 113 private string StorableXAxisName { 114 set { xAxisName = value; } 115 } 116 private string yAxisName; 117 [Storable(Name = "yAxisName")] 118 private string StorableYAxisName { 119 set { yAxisName = value; } 120 } 121 [StorableHook(HookType.AfterDeserialization)] 122 private void AfterDeserialization() { 123 if (VisualProperties == null) VisualProperties = new ScatterPlotVisualProperties(name); 124 if (string.IsNullOrEmpty(VisualProperties.XAxisTitle) && !string.IsNullOrEmpty(xAxisName)) VisualProperties.XAxisTitle = xAxisName; 125 if (string.IsNullOrEmpty(VisualProperties.YAxisTitle) && !string.IsNullOrEmpty(yAxisName)) VisualProperties.YAxisTitle = yAxisName; 126 if (rows == null) Rows = new NamedItemCollection<ScatterPlotDataRow>(); 127 if ((Rows.Count == 0) && (points != null)) Rows.Add(new ScatterPlotDataRow(name, null, points.Select(p => new Point2D<double>(p.X, p.Y)))); 128 } 129 #endregion 112 130 113 131 public override IDeepCloneable Clone(Cloner cloner) { … … 115 133 } 116 134 117 public event EventHandler AxisNameChanged; 118 protected virtual void OnAxesNameChanged() { 119 EventHandler handler = AxisNameChanged; 120 if (handler != null) 121 handler(this, EventArgs.Empty); 135 public event EventHandler VisualPropertiesChanged; 136 protected virtual void OnVisualPropertiesChanged() { 137 EventHandler handler = VisualPropertiesChanged; 138 if (handler != null) handler(this, EventArgs.Empty); 139 } 140 141 private void VisualProperties_PropertyChanged(object sender, PropertyChangedEventArgs e) { 142 OnVisualPropertiesChanged(); 143 } 144 145 protected virtual void RegisterRowsEvents() { 146 rows.ItemsAdded += new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(rows_ItemsAdded); 147 rows.ItemsRemoved += new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(rows_ItemsRemoved); 148 rows.ItemsReplaced += new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(rows_ItemsReplaced); 149 rows.CollectionReset += new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(rows_CollectionReset); 150 } 151 private void rows_ItemsAdded(object sender, CollectionItemsChangedEventArgs<ScatterPlotDataRow> e) { 152 foreach (ScatterPlotDataRow row in e.Items) 153 this.RegisterRowEvents(row); 154 155 this.OnColumnsChanged(); 156 this.OnColumnNamesChanged(); 157 this.OnReset(); 158 } 159 private void rows_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<ScatterPlotDataRow> e) { 160 foreach (ScatterPlotDataRow row in e.Items) 161 this.DeregisterRowEvents(row); 162 163 this.OnColumnsChanged(); 164 this.OnColumnNamesChanged(); 165 this.OnReset(); 166 } 167 private void rows_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<ScatterPlotDataRow> e) { 168 foreach (ScatterPlotDataRow row in e.OldItems) 169 this.DeregisterRowEvents(row); 170 foreach (ScatterPlotDataRow row in e.Items) 171 this.RegisterRowEvents(row); 172 173 this.OnColumnsChanged(); 174 this.OnColumnNamesChanged(); 175 this.OnReset(); 176 } 177 private void rows_CollectionReset(object sender, CollectionItemsChangedEventArgs<ScatterPlotDataRow> e) { 178 foreach (ScatterPlotDataRow row in e.OldItems) 179 this.DeregisterRowEvents(row); 180 foreach (ScatterPlotDataRow row in e.Items) 181 this.RegisterRowEvents(row); 182 183 if (e.OldItems.Count() != e.Items.Count()) 184 this.OnColumnsChanged(); 185 this.OnColumnNamesChanged(); 186 this.OnReset(); 187 } 188 189 protected virtual void RegisterRowEvents(ScatterPlotDataRow row) { 190 row.Points.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsAdded); 191 row.Points.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsMoved); 192 row.Points.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsRemoved); 193 row.Points.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsReplaced); 194 row.Points.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_CollectionReset); 195 } 196 protected virtual void DeregisterRowEvents(ScatterPlotDataRow row) { 197 row.Points.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsAdded); 198 row.Points.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsMoved); 199 row.Points.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsRemoved); 200 row.Points.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsReplaced); 201 row.Points.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_CollectionReset); 202 } 203 204 private void Points_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<Point2D<double>>> e) { 205 this.OnReset(); 206 } 207 private void Points_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<Point2D<double>>> e) { 208 this.OnReset(); 209 } 210 private void Points_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<Point2D<double>>> e) { 211 this.OnReset(); 212 } 213 private void Points_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<Point2D<double>>> e) { 214 this.OnReset(); 215 } 216 private void Points_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<Point2D<double>>> e) { 217 this.OnReset(); 122 218 } 123 219 124 220 #region IStringConvertibleMatrix Members 125 126 221 int IStringConvertibleMatrix.Rows { 127 get { return points.Count; }222 get { return rows.Count == 0 ? 0 : rows.Max(r => r.Points.Count); } 128 223 set { throw new NotSupportedException(); } 129 224 } 130 225 int IStringConvertibleMatrix.Columns { 131 get { return 2; }226 get { return rows.Count; } 132 227 set { throw new NotSupportedException(); } 133 228 } 134 229 IEnumerable<string> IStringConvertibleMatrix.ColumnNames { 135 get { return new string[] { xAxisName, yAxisName }; }230 get { return rows.Select(r => r.Name); } 136 231 set { throw new NotSupportedException(); } 137 232 } … … 142 237 143 238 bool IStringConvertibleMatrix.SortableView { 144 get { return false; }239 get { return true; } 145 240 set { throw new NotSupportedException(); } 146 241 } … … 150 245 151 246 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(); 247 if (columnIndex < rows.Count) { 248 string columnName = ((IStringConvertibleMatrix)this).ColumnNames.ElementAt(columnIndex); 249 if (rows.ContainsKey(columnName) && rowIndex < rows[columnName].Points.Count) 250 return string.Format("{0};{1}", rows[columnName].Points[rowIndex].X, rows[columnName].Points[rowIndex].Y); 154 251 } 155 252 return string.Empty;
Note: See TracChangeset
for help on using the changeset viewer.