Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/03/12 11:22:21 (12 years ago)
Author:
gkronber
Message:

#1081: merged r7214:7266 from trunk into time series branch.

Location:
branches/HeuristicLab.TimeSeries
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TimeSeries

  • branches/HeuristicLab.TimeSeries/HeuristicLab.Analysis.Views/3.3/DataTableView.cs

    r7213 r7268  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3131
    3232namespace HeuristicLab.Analysis.Views {
    33   /// <summary>
    34   /// The visual representation of a <see cref="Variable"/>.
    35   /// </summary>
    3633  [View("DataTable View")]
    3734  [Content(typeof(DataTable), true)]
     
    3936    protected List<Series> invisibleSeries;
    4037    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
    4639    public new DataTable Content {
    4740      get { return (DataTable)base.Content; }
     
    4942    }
    5043
    51     /// <summary>
    52     /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
    53     /// </summary>
    5444    public DataTableView() {
    5545      InitializeComponent();
     
    6151
    6252    #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>
    6753    protected override void DeregisterContentEvents() {
    6854      foreach (DataRow row in Content.Rows)
     
    7561      base.DeregisterContentEvents();
    7662    }
    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>
    8263    protected override void RegisterContentEvents() {
    8364      base.RegisterContentEvents();
     
    9172    }
    9273
    93     /// <summary>
    94     /// Automatically called for every existing data row and whenever a data row is added
    95     /// to the data table. Do not call this method directly.
    96     /// </summary>
    97     /// <param name="row">The DataRow that was added.</param>
    9874    protected virtual void RegisterDataRowEvents(DataRow row) {
    9975      row.NameChanged += new EventHandler(Row_NameChanged);
     
    10682      row.Values.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_CollectionReset);
    10783    }
    108 
    109     /// <summary>
    110     /// Automatically called for every data row that is removed from the DataTable. Do
    111     /// not directly call this method.
    112     /// </summary>
    113     /// <param name="row">The DataRow that was removed.</param>
    11484    protected virtual void DeregisterDataRowEvents(DataRow row) {
    11585      row.Values.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsAdded);
     
    148118    public void ShowConfiguration() {
    149119      if (Content != null) {
    150         DataTableVisualPropertiesDialog dialog = new DataTableVisualPropertiesDialog(Content);
    151         dialog.ShowDialog();
     120        using (DataTableVisualPropertiesDialog dialog = new DataTableVisualPropertiesDialog(Content)) {
     121          dialog.ShowDialog(this);
     122        }
    152123      } else MessageBox.Show("Nothing to configure.");
    153124    }
    154125
    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>
    159126    protected virtual void AddDataRow(DataRow row) {
    160127      Series series = new Series(row.Name);
     
    223190      if (Content.VisualProperties.TitleFont != null) chart.Titles[0].Font = Content.VisualProperties.TitleFont;
    224191      if (!Content.VisualProperties.TitleColor.IsEmpty) chart.Titles[0].ForeColor = Content.VisualProperties.TitleColor;
     192      chart.Titles[0].Text = Content.VisualProperties.Title;
    225193
    226194      if (Content.VisualProperties.AxisTitleFont != null) area.AxisX.TitleFont = Content.VisualProperties.AxisTitleFont;
     
    265233    }
    266234
    267     /// <summary>
    268     /// Set the Y Cursor interval to visible points of enabled series.
    269     /// </summary>
    270235    protected virtual void UpdateYCursorInterval() {
    271236      double interestingValuesRange = (
     
    286251
    287252
    288     /// <summary>
    289     /// Remove the corresponding series for a certain DataRow.
    290     /// </summary>
    291     /// <param name="row">DataRow which series should be removed.</param>
    292253    protected virtual void RemoveDataRow(DataRow row) {
    293254      Series series = chart.Series[row.Name];
     
    577538      }
    578539
     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
    579549      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      }
    600579    }
    601580
    602581    #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
    603591    protected void RemoveCustomPropertyIfExists(Series series, string property) {
    604592      if (series.IsCustomPropertySet(property)) series.DeleteCustomProperty(property);
     
    644632    }
    645633
    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>
    652634    protected static bool IsInvalidValue(double x) {
    653635      return double.IsNaN(x) || x < (double)decimal.MinValue || x > (double)decimal.MaxValue;
Note: See TracChangeset for help on using the changeset viewer.