Changeset 7268 for branches/HeuristicLab.TimeSeries/HeuristicLab.Analysis.Views/3.3/DataTableView.cs
- Timestamp:
- 01/03/12 11:22:21 (12 years ago)
- Location:
- branches/HeuristicLab.TimeSeries
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries
- Property svn:mergeinfo changed
/trunk/sources merged: 7214,7216-7230,7233-7239,7241,7243-7252,7254,7256-7261,7265-7266
- Property svn:mergeinfo changed
-
branches/HeuristicLab.TimeSeries/HeuristicLab.Analysis.Views/3.3/DataTableView.cs
r7213 r7268 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 1Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 31 31 32 32 namespace HeuristicLab.Analysis.Views { 33 /// <summary>34 /// The visual representation of a <see cref="Variable"/>.35 /// </summary>36 33 [View("DataTable View")] 37 34 [Content(typeof(DataTable), true)] … … 39 36 protected List<Series> invisibleSeries; 40 37 protected Dictionary<IObservableList<double>, DataRow> valuesRowsTable; 41 /// <summary> 42 /// Gets or sets the variable to represent visually. 43 /// </summary> 44 /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>. 45 /// No own data storage present.</remarks> 38 46 39 public new DataTable Content { 47 40 get { return (DataTable)base.Content; } … … 49 42 } 50 43 51 /// <summary>52 /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".53 /// </summary>54 44 public DataTableView() { 55 45 InitializeComponent(); … … 61 51 62 52 #region Event Handler Registration 63 /// <summary>64 /// Removes the eventhandlers from the underlying <see cref="Variable"/>.65 /// </summary>66 /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>67 53 protected override void DeregisterContentEvents() { 68 54 foreach (DataRow row in Content.Rows) … … 75 61 base.DeregisterContentEvents(); 76 62 } 77 78 /// <summary>79 /// Adds eventhandlers to the underlying <see cref="Variable"/>.80 /// </summary>81 /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>82 63 protected override void RegisterContentEvents() { 83 64 base.RegisterContentEvents(); … … 91 72 } 92 73 93 /// <summary>94 /// Automatically called for every existing data row and whenever a data row is added95 /// to the data table. Do not call this method directly.96 /// </summary>97 /// <param name="row">The DataRow that was added.</param>98 74 protected virtual void RegisterDataRowEvents(DataRow row) { 99 75 row.NameChanged += new EventHandler(Row_NameChanged); … … 106 82 row.Values.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_CollectionReset); 107 83 } 108 109 /// <summary>110 /// Automatically called for every data row that is removed from the DataTable. Do111 /// not directly call this method.112 /// </summary>113 /// <param name="row">The DataRow that was removed.</param>114 84 protected virtual void DeregisterDataRowEvents(DataRow row) { 115 85 row.Values.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsAdded); … … 148 118 public void ShowConfiguration() { 149 119 if (Content != null) { 150 DataTableVisualPropertiesDialog dialog = new DataTableVisualPropertiesDialog(Content); 151 dialog.ShowDialog(); 120 using (DataTableVisualPropertiesDialog dialog = new DataTableVisualPropertiesDialog(Content)) { 121 dialog.ShowDialog(this); 122 } 152 123 } else MessageBox.Show("Nothing to configure."); 153 124 } 154 125 155 /// <summary>156 /// Add the DataRow as a series to the chart.157 /// </summary>158 /// <param name="row">DataRow to add as series to the chart.</param>159 126 protected virtual void AddDataRow(DataRow row) { 160 127 Series series = new Series(row.Name); … … 223 190 if (Content.VisualProperties.TitleFont != null) chart.Titles[0].Font = Content.VisualProperties.TitleFont; 224 191 if (!Content.VisualProperties.TitleColor.IsEmpty) chart.Titles[0].ForeColor = Content.VisualProperties.TitleColor; 192 chart.Titles[0].Text = Content.VisualProperties.Title; 225 193 226 194 if (Content.VisualProperties.AxisTitleFont != null) area.AxisX.TitleFont = Content.VisualProperties.AxisTitleFont; … … 265 233 } 266 234 267 /// <summary>268 /// Set the Y Cursor interval to visible points of enabled series.269 /// </summary>270 235 protected virtual void UpdateYCursorInterval() { 271 236 double interestingValuesRange = ( … … 286 251 287 252 288 /// <summary>289 /// Remove the corresponding series for a certain DataRow.290 /// </summary>291 /// <param name="row">DataRow which series should be removed.</param>292 253 protected virtual void RemoveDataRow(DataRow row) { 293 254 Series series = chart.Series[row.Name]; … … 577 538 } 578 539 540 double intervalCenter = intervalWidth / 2; 541 542 double min = 0.0; 543 if (!Double.IsNaN(Content.VisualProperties.XAxisMinimumFixedValue) && !Content.VisualProperties.XAxisMinimumAuto) 544 min = Content.VisualProperties.XAxisMinimumFixedValue; 545 else min = minValue; 546 547 double axisInterval = intervalWidth / row.VisualProperties.ScaleFactor; 548 579 549 var area = chart.ChartAreas[0]; 580 double current = 0.0; 581 if (!Double.IsNaN(Content.VisualProperties.XAxisMinimumFixedValue) && !Content.VisualProperties.XAxisMinimumAuto) 582 current = Content.VisualProperties.XAxisMinimumFixedValue; 583 else current = minValue; 584 585 area.AxisX.Interval = intervalWidth / row.VisualProperties.ScaleFactor; 586 area.AxisX.IntervalOffset = intervalWidth / row.VisualProperties.ScaleFactor; 587 588 series.SetCustomProperty("PointWidth", intervalWidth.ToString()); 589 590 int frequency = 0; 591 foreach (double v in row.Values.Where(x => !IsInvalidValue(x)).OrderBy(x => x)) { 592 while (v > current + intervalWidth) { 593 series.Points.AddXY(current + intervalWidth, frequency); 594 current += intervalWidth; 595 frequency = 0; 596 } 597 frequency++; 598 } 599 series.Points.AddXY(current + intervalWidth, frequency); 550 area.AxisX.Interval = axisInterval; 551 552 series.SetCustomProperty("PointWidth", "1"); // 0.8 is the default value 553 554 // get the range or intervals which define the grouping of the frequency values 555 var doubleRange = DoubleRange(min, maxValue + intervalWidth, intervalWidth).Skip(1).ToList(); 556 557 // aggregate the row values by unique key and frequency value 558 var valueFrequencies = (from v in row.Values 559 where !IsInvalidValue(v) 560 orderby v 561 group v by v into g 562 select new Tuple<double, double>(g.First(), g.Count())).ToList(); 563 564 // shift the chart to the left so the bars are placed on the intervals 565 if (valueFrequencies.First().Item1 < doubleRange.First()) 566 series.Points.Add(new DataPoint(min - intervalWidth, 0)); 567 568 // add data points 569 int j = 0; 570 foreach (var d in doubleRange) { 571 double sum = 0.0; 572 // sum the frequency values that fall within the same interval 573 while (j < valueFrequencies.Count && valueFrequencies[j].Item1 < d) { 574 sum += valueFrequencies[j].Item2; 575 ++j; 576 } 577 series.Points.Add(new DataPoint(d - intervalCenter, sum) { ToolTip = "X: [" + (d - intervalWidth) + "-" + d + "), Y: " + sum }); 578 } 600 579 } 601 580 602 581 #region Helpers 582 public static IEnumerable<double> DoubleRange(double min, double max, double step) { 583 double i; 584 for (i = min; i <= max; i += step) 585 yield return i; 586 587 if (i != max + step) 588 yield return i; 589 } 590 603 591 protected void RemoveCustomPropertyIfExists(Series series, string property) { 604 592 if (series.IsCustomPropertySet(property)) series.DeleteCustomProperty(property); … … 644 632 } 645 633 646 /// <summary>647 /// Determines whether a double value can be displayed (converted to Decimal and not an NaN).648 /// </summary>649 /// <param name="x">The number to check.</param>650 /// <returns><code>true</code> if the value can be safely shwon in the chart,651 /// <code>false</code> otherwise.</returns>652 634 protected static bool IsInvalidValue(double x) { 653 635 return double.IsNaN(x) || x < (double)decimal.MinValue || x > (double)decimal.MaxValue;
Note: See TracChangeset
for help on using the changeset viewer.