Changeset 3703 for trunk/sources
- Timestamp:
- 05/07/10 15:32:20 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Analysis.Views/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Analysis.Views/3.3/DataTableView.Designer.cs
r3530 r3703 88 88 this.chart.TabIndex = 4; 89 89 this.chart.Text = "chart1"; 90 this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove); 91 this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown); 92 this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend); 90 93 // 91 94 // DataTableView -
trunk/sources/HeuristicLab.Analysis.Views/3.3/DataTableView.cs
r3566 r3703 21 21 22 22 using System; 23 using System.Linq; 23 24 using System.Collections.Generic; 24 25 using System.Windows.Forms.DataVisualization.Charting; … … 26 27 using HeuristicLab.Core.Views; 27 28 using HeuristicLab.MainForm; 29 using System.Windows.Forms; 30 using System.Drawing; 28 31 29 32 namespace HeuristicLab.Analysis.Views { … … 34 37 [Content(typeof(DataTable), true)] 35 38 public sealed partial class DataTableView : NamedItemView { 36 Dictionary<IObservableList<double>, DataRow> valuesRowsTable; 39 private List<Series> invisibleSeries; 40 private Dictionary<IObservableList<double>, DataRow> valuesRowsTable; 37 41 /// <summary> 38 42 /// Gets or sets the variable to represent visually. … … 52 56 Caption = "DataTable"; 53 57 valuesRowsTable = new Dictionary<IObservableList<double>, DataRow>(); 58 invisibleSeries = new List<Series>(); 54 59 } 55 60 … … 84 89 protected override void OnContentChanged() { 85 90 base.OnContentChanged(); 91 invisibleSeries.Clear(); 86 92 chart.Titles.Clear(); 87 93 chart.Series.Clear(); … … 109 115 series.ChartType = SeriesChartType.FastLine; 110 116 series.ToolTip = row.Name + " #VAL"; 111 for (int i = 0; i < row.Values.Count; i++) { 112 var value = row.Values[i]; 113 if (IsInvalidValue(value)) { 114 DataPoint point = new DataPoint(); 115 point.IsEmpty = true; 116 series.Points.Add(point); 117 } else { 118 series.Points.Add(value); 119 } 120 } 117 FillSeriesWithRowValues(series, row); 121 118 chart.Series.Add(series); 122 } 119 UpdateYCursorInterval(); 120 } 121 122 private void UpdateYCursorInterval() { 123 double interestingValuesRange = (from series in chart.Series 124 where series.Enabled 125 let values = (from point in series.Points 126 where !point.IsEmpty 127 select point.YValues[0]) 128 .DefaultIfEmpty(1.0) 129 let range = values.Max() - values.Min() 130 where range > 0.0 131 select range) 132 .DefaultIfEmpty(1.0) 133 .Min(); 134 135 double digits = (int)Math.Log10(interestingValuesRange) - 3; 136 double yZoomInterval = Math.Pow(10, digits); 137 this.chart.ChartAreas[0].CursorY.Interval = yZoomInterval; 138 } 139 123 140 private void RemoveDataRow(DataRow row) { 124 141 Series series = chart.Series[row.Name]; 125 142 chart.Series.Remove(series); 143 if (invisibleSeries.Contains(series)) 144 invisibleSeries.Remove(series); 126 145 } 127 146 … … 216 235 valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row); 217 236 if (row != null) { 218 foreach (IndexedItem<double> item in e.Items) { 219 var value = item.Value; 220 if (IsInvalidValue(item.Value)) { 221 DataPoint point = new DataPoint(); 222 point.IsEmpty = true; 223 chart.Series[row.Name].Points.Insert(item.Index, point); 224 } else { 225 chart.Series[row.Name].Points.InsertY(item.Index, value); 237 Series rowSeries = chart.Series[row.Name]; 238 if (!invisibleSeries.Contains(rowSeries)) { 239 foreach (IndexedItem<double> item in e.Items) { 240 var value = item.Value; 241 if (IsInvalidValue(item.Value)) { 242 DataPoint point = new DataPoint(); 243 point.IsEmpty = true; 244 rowSeries.Points.Insert(item.Index, point); 245 } else { 246 rowSeries.Points.InsertY(item.Index, value); 247 } 226 248 } 249 UpdateYCursorInterval(); 227 250 } 228 251 } … … 236 259 valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row); 237 260 if (row != null) { 238 List<DataPoint> points = new List<DataPoint>(); 239 foreach (IndexedItem<double> item in e.Items) 240 points.Add(chart.Series[row.Name].Points[item.Index]); 241 foreach (DataPoint point in points) 242 chart.Series[row.Name].Points.Remove(point); 261 Series rowSeries = chart.Series[row.Name]; 262 if (!invisibleSeries.Contains(rowSeries)) { 263 List<DataPoint> points = new List<DataPoint>(); 264 foreach (IndexedItem<double> item in e.Items) 265 points.Add(rowSeries.Points[item.Index]); 266 foreach (DataPoint point in points) 267 rowSeries.Points.Remove(point); 268 UpdateYCursorInterval(); 269 } 243 270 } 244 271 } … … 251 278 valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row); 252 279 if (row != null) { 253 foreach (IndexedItem<double> item in e.Items) { 254 if (IsInvalidValue(item.Value)) 255 chart.Series[row.Name].Points[item.Index].IsEmpty = true; 256 else { 257 chart.Series[row.Name].Points[item.Index].YValues = new double[] { item.Value }; 258 chart.Series[row.Name].Points[item.Index].IsEmpty = false; 280 Series rowSeries = chart.Series[row.Name]; 281 if (!invisibleSeries.Contains(rowSeries)) { 282 foreach (IndexedItem<double> item in e.Items) { 283 if (IsInvalidValue(item.Value)) 284 rowSeries.Points[item.Index].IsEmpty = true; 285 else { 286 rowSeries.Points[item.Index].YValues = new double[] { item.Value }; 287 rowSeries.Points[item.Index].IsEmpty = false; 288 } 259 289 } 290 UpdateYCursorInterval(); 260 291 } 261 292 } … … 269 300 valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row); 270 301 if (row != null) { 271 foreach (IndexedItem<double> item in e.Items) { 272 if (IsInvalidValue(item.Value)) 273 chart.Series[row.Name].Points[item.Index].IsEmpty = true; 274 else { 275 chart.Series[row.Name].Points[item.Index].YValues = new double[] { item.Value }; 276 chart.Series[row.Name].Points[item.Index].IsEmpty = false; 302 Series rowSeries = chart.Series[row.Name]; 303 if (!invisibleSeries.Contains(rowSeries)) { 304 foreach (IndexedItem<double> item in e.Items) { 305 if (IsInvalidValue(item.Value)) 306 rowSeries.Points[item.Index].IsEmpty = true; 307 else { 308 rowSeries.Points[item.Index].YValues = new double[] { item.Value }; 309 rowSeries.Points[item.Index].IsEmpty = false; 310 } 277 311 } 312 UpdateYCursorInterval(); 278 313 } 279 314 } … … 288 323 valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row); 289 324 if (row != null) { 290 chart.Series[row.Name].Points.Clear(); 291 foreach (IndexedItem<double> item in e.Items) { 292 if (IsInvalidValue(item.Value)) 293 chart.Series[row.Name].Points[item.Index].IsEmpty = true; 294 else { 295 chart.Series[row.Name].Points[item.Index].YValues = new double[] { item.Value }; 296 chart.Series[row.Name].Points[item.Index].IsEmpty = false; 325 Series rowSeries = chart.Series[row.Name]; 326 if (!invisibleSeries.Contains(rowSeries)) { 327 rowSeries.Points.Clear(); 328 foreach (IndexedItem<double> item in e.Items) { 329 if (IsInvalidValue(item.Value)) 330 rowSeries.Points[item.Index].IsEmpty = true; 331 else { 332 rowSeries.Points[item.Index].YValues = new double[] { item.Value }; 333 rowSeries.Points[item.Index].IsEmpty = false; 334 } 297 335 } 298 336 } 299 } 300 } 301 } 337 UpdateYCursorInterval(); 338 } 339 } 340 } 341 #endregion 342 #region chart events 343 private void chart_MouseDown(object sender, MouseEventArgs e) { 344 HitTestResult result = chart.HitTest(e.X, e.Y); 345 if (result.ChartElementType == ChartElementType.LegendItem) { 346 ToggleSeriesVisible(result.Series); 347 } 348 } 349 350 private void ToggleSeriesVisible(Series series) { 351 if (!invisibleSeries.Contains(series)) { 352 series.Points.Clear(); 353 invisibleSeries.Add(series); 354 } else { 355 invisibleSeries.Remove(series); 356 if (Content != null) { 357 358 var row = (from r in Content.Rows 359 where r.Name == series.Name 360 select r).Single(); 361 FillSeriesWithRowValues(series, row); 362 this.chart.Legends[series.Legend].ForeColor = Color.Black; 363 UpdateYCursorInterval(); 364 } 365 } 366 } 367 368 private void FillSeriesWithRowValues(Series series, DataRow row) { 369 for (int i = 0; i < row.Values.Count; i++) { 370 var value = row.Values[i]; 371 if (IsInvalidValue(value)) { 372 DataPoint point = new DataPoint(); 373 point.IsEmpty = true; 374 series.Points.Add(point); 375 } else { 376 series.Points.Add(value); 377 } 378 } 379 } 380 381 private void chart_MouseMove(object sender, MouseEventArgs e) { 382 HitTestResult result = chart.HitTest(e.X, e.Y); 383 if (result.ChartElementType == ChartElementType.LegendItem) 384 this.Cursor = Cursors.Hand; 385 else 386 this.Cursor = Cursors.Default; 387 } 388 private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) { 389 foreach (LegendItem legendItem in e.LegendItems) { 390 var series = chart.Series[legendItem.SeriesName]; 391 if (series != null) { 392 bool seriesIsInvisible = invisibleSeries.Contains(series); 393 foreach (LegendCell cell in legendItem.Cells) { 394 cell.ForeColor = seriesIsInvisible ? Color.Gray : Color.Black; 395 } 396 } 397 } 398 } 399 302 400 #endregion 303 401
Note: See TracChangeset
for help on using the changeset viewer.