Free cookie consent management tool by TermsFeed Policy Generator

source: branches/histogram/HeuristicLab.Analysis.Views/3.3/DataTableView.cs @ 6014

Last change on this file since 6014 was 6014, checked in by abeham, 12 years ago

#1465

  • added option to set fixed minimum and maximum for all four possible axis
  • added an icon to the properties context menu entry
    • added dependency from ChartControlsExtensions to Common.Resources
File size: 24.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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 System.Windows.Forms;
27using System.Windows.Forms.DataVisualization.Charting;
28using HeuristicLab.Collections;
29using HeuristicLab.Core.Views;
30using HeuristicLab.MainForm;
31
32namespace HeuristicLab.Analysis.Views {
33  /// <summary>
34  /// The visual representation of a <see cref="Variable"/>.
35  /// </summary>
36  [View("DataTable View")]
37  [Content(typeof(DataTable), true)]
38  public partial class DataTableView : NamedItemView {
39    protected List<Series> invisibleSeries;
40    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>
46    public new DataTable Content {
47      get { return (DataTable)base.Content; }
48      set { base.Content = value; }
49    }
50
51    /// <summary>
52    /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
53    /// </summary>
54    public DataTableView() {
55      InitializeComponent();
56      valuesRowsTable = new Dictionary<IObservableList<double>, DataRow>();
57      invisibleSeries = new List<Series>();
58      chart.CustomizeAllChartAreas();
59      chart.ChartAreas[0].CursorX.Interval = 1;
60    }
61
62    #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    protected override void DeregisterContentEvents() {
68      foreach (DataRow row in Content.Rows)
69        DeregisterDataRowEvents(row);
70      Content.VisualPropertiesChanged -= new EventHandler(Content_VisualPropertiesChanged);
71      Content.Rows.ItemsAdded -= new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsAdded);
72      Content.Rows.ItemsRemoved -= new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsRemoved);
73      Content.Rows.ItemsReplaced -= new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsReplaced);
74      Content.Rows.CollectionReset -= new CollectionItemsChangedEventHandler<DataRow>(Rows_CollectionReset);
75      base.DeregisterContentEvents();
76    }
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    protected override void RegisterContentEvents() {
83      base.RegisterContentEvents();
84      Content.VisualPropertiesChanged += new EventHandler(Content_VisualPropertiesChanged);
85      Content.Rows.ItemsAdded += new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsAdded);
86      Content.Rows.ItemsRemoved += new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsRemoved);
87      Content.Rows.ItemsReplaced += new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsReplaced);
88      Content.Rows.CollectionReset += new CollectionItemsChangedEventHandler<DataRow>(Rows_CollectionReset);
89      foreach (DataRow row in Content.Rows)
90        RegisterDataRowEvents(row);
91    }
92
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>
98    protected virtual void RegisterDataRowEvents(DataRow row) {
99      row.NameChanged += new EventHandler(Row_NameChanged);
100      row.VisualPropertiesChanged += new EventHandler(Row_VisualPropertiesChanged);
101      valuesRowsTable.Add(row.Values, row);
102      row.Values.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsAdded);
103      row.Values.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsRemoved);
104      row.Values.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsReplaced);
105      row.Values.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsMoved);
106      row.Values.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_CollectionReset);
107    }
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>
114    protected virtual void DeregisterDataRowEvents(DataRow row) {
115      row.Values.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsAdded);
116      row.Values.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsRemoved);
117      row.Values.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsReplaced);
118      row.Values.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsMoved);
119      row.Values.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_CollectionReset);
120      valuesRowsTable.Remove(row.Values);
121      row.VisualPropertiesChanged -= new EventHandler(Row_VisualPropertiesChanged);
122      row.NameChanged -= new EventHandler(Row_NameChanged);
123    }
124    #endregion
125
126    protected override void OnContentChanged() {
127      base.OnContentChanged();
128      invisibleSeries.Clear();
129      chart.Titles[0].Text = string.Empty;
130      chart.ChartAreas[0].AxisX.Title = string.Empty;
131      chart.ChartAreas[0].AxisY.Title = string.Empty;
132      chart.ChartAreas[0].AxisY2.Title = string.Empty;
133      chart.Series.Clear();
134      if (Content != null) {
135        chart.Titles[0].Text = Content.Name;
136        foreach (DataRow row in Content.Rows)
137          AddDataRow(row);
138        ConfigureChartArea(chart.ChartAreas[0]);
139      }
140    }
141
142    protected override void SetEnabledStateOfControls() {
143      base.SetEnabledStateOfControls();
144      chart.Enabled = Content != null;
145    }
146
147    /// <summary>
148    /// Add the DataRow as a series to the chart.
149    /// </summary>
150    /// <param name="row">DataRow to add as series to the chart.</param>
151    protected virtual void AddDataRow(DataRow row) {
152      Series series = new Series(row.Name);
153      ConfigureSeries(series, row);
154      FillSeriesWithRowValues(series, row);
155
156      chart.Series.Add(series);
157      chart.ChartAreas[0].RecalculateAxesScale();
158      ConfigureChartArea(chart.ChartAreas[0]);
159      UpdateYCursorInterval();
160    }
161
162    private void ConfigureSeries(Series series, DataRow row) {
163      RemoveCustomPropertyIfExists(series, "PointWidth");
164      series.BorderWidth = 1;
165      series.BorderDashStyle = ChartDashStyle.Solid;
166
167      switch (row.VisualProperties.ChartType) {
168        case DataRowVisualProperties.DataRowChartType.Line:
169          series.ChartType = SeriesChartType.FastLine;
170          series.BorderWidth = row.VisualProperties.LineWidth;
171          series.BorderDashStyle = ConvertLineStyle(row.VisualProperties.LineStyle);
172          break;
173        case DataRowVisualProperties.DataRowChartType.Bars:
174          series.ChartType = SeriesChartType.Bar;
175          break;
176        case DataRowVisualProperties.DataRowChartType.Columns:
177          series.ChartType = SeriesChartType.Column;
178          break;
179        case DataRowVisualProperties.DataRowChartType.Points:
180          series.ChartType = SeriesChartType.FastPoint;
181          series.BorderWidth = row.VisualProperties.LineWidth;
182          series.BorderDashStyle = ConvertLineStyle(row.VisualProperties.LineStyle);
183          break;
184        case DataRowVisualProperties.DataRowChartType.Histogram:
185          series.ChartType = SeriesChartType.Column;
186          series.SetCustomProperty("PointWidth", "1");
187          break;
188        default:
189          series.ChartType = SeriesChartType.FastPoint;
190          break;
191      }
192      series.YAxisType = row.VisualProperties.SecondYAxis ? AxisType.Secondary : AxisType.Primary;
193      series.XAxisType = row.VisualProperties.SecondXAxis ? AxisType.Secondary : AxisType.Primary;
194      if (row.VisualProperties.Color != Color.Empty)
195        series.Color = row.VisualProperties.Color;
196      else series.Color = Color.Empty;
197      series.ToolTip = row.Name + " X = #INDEX, Y = #VAL";
198    }
199
200    private void ConfigureChartArea(ChartArea area) {
201      area.AxisX.Title = Content.VisualProperties.XAxisTitle;
202      area.AxisX2.Title = Content.VisualProperties.SecondXAxisTitle;
203      area.AxisY.Title = Content.VisualProperties.YAxisTitle;
204      area.AxisY2.Title = Content.VisualProperties.SecondYAxisTitle;
205      area.RecalculateAxesScale();
206      if (!Content.VisualProperties.XAxisMinimumAuto)
207        area.AxisX.Minimum = Content.VisualProperties.XAxisMinimumFixedValue;
208      else area.AxisX.Minimum = double.NaN;
209      if (!Content.VisualProperties.XAxisMaximumAuto)
210        area.AxisX.Maximum = Content.VisualProperties.XAxisMaximumFixedValue;
211      else area.AxisX.Maximum = double.NaN;
212      if (!Content.VisualProperties.SecondXAxisMinimumAuto)
213        area.AxisX2.Minimum = Content.VisualProperties.SecondXAxisMinimumFixedValue;
214      if (!Content.VisualProperties.SecondXAxisMaximumAuto)
215        area.AxisX2.Maximum = Content.VisualProperties.SecondXAxisMaximumFixedValue;
216      if (!Content.VisualProperties.YAxisMinimumAuto)
217        area.AxisY.Minimum = Content.VisualProperties.YAxisMinimumFixedValue;
218      if (!Content.VisualProperties.YAxisMaximumAuto)
219        area.AxisY.Maximum = Content.VisualProperties.YAxisMaximumFixedValue;
220      if (!Content.VisualProperties.SecondYAxisMinimumAuto)
221        area.AxisY2.Minimum = Content.VisualProperties.SecondYAxisMinimumFixedValue;
222      if (!Content.VisualProperties.SecondYAxisMaximumAuto)
223        area.AxisY2.Maximum = Content.VisualProperties.SecondYAxisMaximumFixedValue;
224    }
225
226    /// <summary>
227    /// Set the Y Cursor interval to visible points of enabled series.
228    /// </summary>
229    protected virtual void UpdateYCursorInterval() {
230      double interestingValuesRange = (
231        from series in chart.Series
232        where series.Enabled
233        let values = (from point in series.Points
234                      where !point.IsEmpty
235                      select point.YValues[0]).DefaultIfEmpty(1.0)
236        let range = values.Max() - values.Min()
237        where range > 0.0
238        select range
239        ).DefaultIfEmpty(1.0).Min();
240
241      double digits = (int)Math.Log10(interestingValuesRange) - 3;
242      double yZoomInterval = Math.Pow(10, digits);
243      this.chart.ChartAreas[0].CursorY.Interval = yZoomInterval;
244    }
245
246
247    /// <summary>
248    /// Remove the corresponding series for a certain DataRow.
249    /// </summary>
250    /// <param name="row">DataRow which series should be removed.</param>
251    protected virtual void RemoveDataRow(DataRow row) {
252      Series series = chart.Series[row.Name];
253      chart.Series.Remove(series);
254      if (invisibleSeries.Contains(series))
255        invisibleSeries.Remove(series);
256      chart.ChartAreas[0].RecalculateAxesScale();
257    }
258
259    #region Event Handlers
260    #region Content Event Handlers
261    protected override void Content_NameChanged(object sender, EventArgs e) {
262      if (InvokeRequired)
263        Invoke(new EventHandler(Content_NameChanged), sender, e);
264      else {
265        chart.Titles[0].Text = Content.Name;
266        base.Content_NameChanged(sender, e);
267      }
268    }
269    private void Content_VisualPropertiesChanged(object sender, EventArgs e) {
270      if (InvokeRequired)
271        Invoke(new EventHandler(Content_VisualPropertiesChanged), sender, e);
272      else {
273        ConfigureChartArea(chart.ChartAreas[0]);
274      }
275    }
276    #endregion
277    #region Rows Event Handlers
278    private void Rows_ItemsAdded(object sender, CollectionItemsChangedEventArgs<DataRow> e) {
279      if (InvokeRequired)
280        Invoke(new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsAdded), sender, e);
281      else {
282        foreach (DataRow row in e.Items) {
283          AddDataRow(row);
284          RegisterDataRowEvents(row);
285        }
286      }
287    }
288    private void Rows_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<DataRow> e) {
289      if (InvokeRequired)
290        Invoke(new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsRemoved), sender, e);
291      else {
292        foreach (DataRow row in e.Items) {
293          DeregisterDataRowEvents(row);
294          RemoveDataRow(row);
295        }
296      }
297    }
298    private void Rows_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<DataRow> e) {
299      if (InvokeRequired)
300        Invoke(new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsReplaced), sender, e);
301      else {
302        foreach (DataRow row in e.OldItems) {
303          DeregisterDataRowEvents(row);
304          RemoveDataRow(row);
305        }
306        foreach (DataRow row in e.Items) {
307          AddDataRow(row);
308          RegisterDataRowEvents(row);
309        }
310      }
311    }
312    private void Rows_CollectionReset(object sender, CollectionItemsChangedEventArgs<DataRow> e) {
313      if (InvokeRequired)
314        Invoke(new CollectionItemsChangedEventHandler<DataRow>(Rows_CollectionReset), sender, e);
315      else {
316        foreach (DataRow row in e.OldItems) {
317          DeregisterDataRowEvents(row);
318          RemoveDataRow(row);
319        }
320        foreach (DataRow row in e.Items) {
321          AddDataRow(row);
322          RegisterDataRowEvents(row);
323        }
324      }
325    }
326    #endregion
327    #region Row Event Handlers
328    private void Row_VisualPropertiesChanged(object sender, EventArgs e) {
329      if (InvokeRequired)
330        Invoke(new EventHandler(Row_VisualPropertiesChanged), sender, e);
331      else {
332        DataRow row = (DataRow)sender;
333        Series series = chart.Series[row.Name];
334        series.Points.Clear();
335        ConfigureSeries(series, row);
336        FillSeriesWithRowValues(series, row);
337        chart.ChartAreas[0].RecalculateAxesScale();
338      }
339    }
340    private void Row_NameChanged(object sender, EventArgs e) {
341      if (InvokeRequired)
342        Invoke(new EventHandler(Row_NameChanged), sender, e);
343      else {
344        DataRow row = (DataRow)sender;
345        chart.Series[row.Name].Name = row.Name;
346      }
347    }
348    #endregion
349    #region Values Event Handlers
350    private void Values_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) {
351      if (InvokeRequired)
352        Invoke(new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsAdded), sender, e);
353      else {
354        DataRow row = null;
355        valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row);
356        if (row != null) {
357          Series rowSeries = chart.Series[row.Name];
358          if (!invisibleSeries.Contains(rowSeries)) {
359            rowSeries.Points.Clear();
360            FillSeriesWithRowValues(rowSeries, row);
361            UpdateYCursorInterval();
362          }
363        }
364      }
365    }
366    private void Values_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) {
367      if (InvokeRequired)
368        Invoke(new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsRemoved), sender, e);
369      else {
370        DataRow row = null;
371        valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row);
372        if (row != null) {
373          Series rowSeries = chart.Series[row.Name];
374          if (!invisibleSeries.Contains(rowSeries)) {
375            rowSeries.Points.Clear();
376            FillSeriesWithRowValues(rowSeries, row);
377            UpdateYCursorInterval();
378          }
379        }
380      }
381    }
382    private void Values_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) {
383      if (InvokeRequired)
384        Invoke(new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsReplaced), sender, e);
385      else {
386        DataRow row = null;
387        valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row);
388        if (row != null) {
389          Series rowSeries = chart.Series[row.Name];
390          if (!invisibleSeries.Contains(rowSeries)) {
391            if (row.VisualProperties.ChartType == DataRowVisualProperties.DataRowChartType.Histogram) {
392              rowSeries.Points.Clear();
393              FillSeriesWithRowValues(rowSeries, row);
394            } else {
395              foreach (IndexedItem<double> item in e.Items) {
396                if (IsInvalidValue(item.Value))
397                  rowSeries.Points[item.Index].IsEmpty = true;
398                else {
399                  rowSeries.Points[item.Index].YValues = new double[] { item.Value };
400                  rowSeries.Points[item.Index].IsEmpty = false;
401                }
402              }
403            }
404            UpdateYCursorInterval();
405          }
406        }
407      }
408    }
409    private void Values_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) {
410      if (InvokeRequired)
411        Invoke(new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsMoved), sender, e);
412      else {
413        DataRow row = null;
414        valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row);
415        if (row != null) {
416          Series rowSeries = chart.Series[row.Name];
417          if (!invisibleSeries.Contains(rowSeries)) {
418            rowSeries.Points.Clear();
419            FillSeriesWithRowValues(rowSeries, row);
420            UpdateYCursorInterval();
421          }
422        }
423      }
424    }
425
426    private void Values_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) {
427      if (InvokeRequired)
428        Invoke(new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_CollectionReset), sender, e);
429      else {
430        DataRow row = null;
431        valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row);
432        if (row != null) {
433          Series rowSeries = chart.Series[row.Name];
434          if (!invisibleSeries.Contains(rowSeries)) {
435            rowSeries.Points.Clear();
436            FillSeriesWithRowValues(rowSeries, row);
437            UpdateYCursorInterval();
438          }
439        }
440      }
441    }
442    #endregion
443    #endregion
444
445    #region Chart Event Handlers
446    private void chart_MouseDown(object sender, MouseEventArgs e) {
447      HitTestResult result = chart.HitTest(e.X, e.Y);
448      if (result.ChartElementType == ChartElementType.LegendItem) {
449        ToggleSeriesVisible(result.Series);
450      }
451    }
452    private void chart_MouseMove(object sender, MouseEventArgs e) {
453      HitTestResult result = chart.HitTest(e.X, e.Y);
454      if (result.ChartElementType == ChartElementType.LegendItem)
455        this.Cursor = Cursors.Hand;
456      else
457        this.Cursor = Cursors.Default;
458    }
459    private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) {
460      foreach (LegendItem legendItem in e.LegendItems) {
461        var series = chart.Series[legendItem.SeriesName];
462        if (series != null) {
463          bool seriesIsInvisible = invisibleSeries.Contains(series);
464          foreach (LegendCell cell in legendItem.Cells) {
465            cell.ForeColor = seriesIsInvisible ? Color.Gray : Color.Black;
466          }
467        }
468      }
469    }
470    private void chart_PropertiesClicked(object sender, EventArgs e) {
471      DataTableVisualPropertiesDialog dialog = new DataTableVisualPropertiesDialog(Content);
472      dialog.ShowDialog();
473    }
474    #endregion
475
476    private void ToggleSeriesVisible(Series series) {
477      if (!invisibleSeries.Contains(series)) {
478        series.Points.Clear();
479        invisibleSeries.Add(series);
480      } else {
481        invisibleSeries.Remove(series);
482        if (Content != null) {
483
484          var row = (from r in Content.Rows
485                     where r.Name == series.Name
486                     select r).Single();
487          FillSeriesWithRowValues(series, row);
488          this.chart.Legends[series.Legend].ForeColor = Color.Black;
489          UpdateYCursorInterval();
490        }
491      }
492    }
493
494    private void FillSeriesWithRowValues(Series series, DataRow row) {
495      switch (row.VisualProperties.ChartType) {
496        case DataRowVisualProperties.DataRowChartType.Histogram:
497          CalculateHistogram(series, row);
498          break;
499        default: {
500            for (int i = 0; i < row.Values.Count; i++) {
501              var value = row.Values[i];
502              DataPoint point = new DataPoint();
503              point.XValue = row.VisualProperties.StartIndexZero ? i : i + 1;
504              if (IsInvalidValue(value))
505                point.IsEmpty = true;
506              else
507                point.YValues = new double[] { value };
508              series.Points.Add(point);
509            }
510          }
511          break;
512      }
513    }
514
515    protected virtual void CalculateHistogram(Series series, DataRow row) {
516      series.Points.Clear();
517      if (!row.Values.Any()) return;
518      int bins = row.VisualProperties.Bins;
519
520      double minValue = row.Values.Min();
521      double maxValue = row.Values.Max();
522      double intervalWidth = (maxValue - minValue) / bins;
523      if (intervalWidth <= 0) return;
524
525      if (!row.VisualProperties.ExactBins) {
526        intervalWidth = HumanRoundRange(intervalWidth);
527        minValue = Math.Floor(minValue / intervalWidth) * intervalWidth;
528        maxValue = Math.Ceiling(maxValue / intervalWidth) * intervalWidth;
529      }
530
531      double current = minValue, intervalCenter = intervalWidth / 2.0;
532      int frequency = 0;
533      foreach (double v in row.Values.Where(x => !IsInvalidValue(x)).OrderBy(x => x)) {
534        while (v > current + intervalWidth) {
535          series.Points.AddXY(current + intervalCenter, frequency);
536          current += intervalWidth;
537          frequency = 0;
538        }
539        frequency++;
540      }
541      series.Points.AddXY(current + intervalCenter, frequency);
542    }
543
544    #region Helpers
545    protected void RemoveCustomPropertyIfExists(Series series, string property) {
546      if (series.IsCustomPropertySet(property)) series.DeleteCustomProperty(property);
547    }
548
549    private double HumanRoundRange(double range) {
550      double base10 = Math.Pow(10.0, Math.Floor(Math.Log10(range)));
551      double rounding = range / base10;
552      if (rounding <= 1.5) rounding = 1;
553      else if (rounding <= 2.25) rounding = 2;
554      else if (rounding <= 3.75) rounding = 2.5;
555      else if (rounding <= 7.5) rounding = 5;
556      else rounding = 10;
557      return rounding * base10;
558    }
559
560    private ChartDashStyle ConvertLineStyle(DataRowVisualProperties.DataRowLineStyle dataRowLineStyle) {
561      switch (dataRowLineStyle) {
562        case DataRowVisualProperties.DataRowLineStyle.Dash:
563          return ChartDashStyle.Dash;
564        case DataRowVisualProperties.DataRowLineStyle.DashDot:
565          return ChartDashStyle.DashDot;
566        case DataRowVisualProperties.DataRowLineStyle.DashDotDot:
567          return ChartDashStyle.DashDotDot;
568        case DataRowVisualProperties.DataRowLineStyle.Dot:
569          return ChartDashStyle.Dot;
570        case DataRowVisualProperties.DataRowLineStyle.NotSet:
571          return ChartDashStyle.NotSet;
572        case DataRowVisualProperties.DataRowLineStyle.Solid:
573          return ChartDashStyle.Solid;
574        default:
575          return ChartDashStyle.NotSet;
576      }
577    }
578
579    /// <summary>
580    /// Determines whether a double value can be displayed (converted to Decimal and not an NaN).
581    /// </summary>
582    /// <param name="x">The number to check.</param>
583    /// <returns><code>true</code> if the value can be safely shwon in the chart,
584    /// <code>false</code> otherwise.</returns>
585    protected static bool IsInvalidValue(double x) {
586      return double.IsNaN(x) || x < (double)decimal.MinValue || x > (double)decimal.MaxValue;
587    }
588    #endregion
589  }
590}
Note: See TracBrowser for help on using the repository browser.