Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/LineChart.cs @ 715

Last change on this file since 715 was 697, checked in by mstoeger, 16 years ago

changed interface between model and view to support full and partial updates as decided in the last meeting (#316)

  • model.Columns property provides access to all values contained within the model for full updates
  • model.DataChanged event notifies the view of partial updates
File size: 3.4 KB
Line 
1using System;
2using HeuristicLab.Core;
3
4namespace HeuristicLab.Visualization {
5  public partial class LineChart : ViewBase {
6    private readonly IChartDataRowsModel model;
7
8    /// <summary>
9    /// This constructor shouldn't be called. Only required for the designer.
10    /// </summary>
11    public LineChart() {
12      InitializeComponent();
13    }
14
15    /// <summary>
16    /// Initializes the chart.
17    /// </summary>
18    /// <param name="model"></param>
19    public LineChart(IChartDataRowsModel model) : this() {
20      if (model == null) {
21        throw new NullReferenceException("Model cannot be null.");
22      }
23
24      this.model = model;
25
26      Reset();
27    }
28
29    /// <summary>
30    /// Resets the line chart by deleting all shapes and reloading all data from the model.
31    /// </summary>
32    private void Reset() {
33      BeginUpdate();
34
35      // TODO clear existing shapes
36
37      // reload data from the model and create shapes
38      foreach (ChartDataRowsModelColumn column in model.Columns) {
39        AddColumn(column.ColumnId, column.Values);
40      }
41
42      EndUpdate();
43    }
44
45    /// <summary>
46    /// Event handler which gets called when data in the model changes.
47    /// </summary>
48    /// <param name="type">Type of change</param>
49    /// <param name="columnId">Id of the changed column</param>
50    /// <param name="values">Values contained within the changed column</param>
51    private void OnDataChanged(ChangeType type, long columnId, double[] values) {
52      switch (type) {
53        case ChangeType.Add:
54          AddColumn(columnId, values);
55          break;
56        case ChangeType.Modify:
57          ModifyColumn(columnId, values);
58          break;
59        case ChangeType.Remove:
60          RemoveColumn(columnId);
61          break;
62        default:
63          throw new ArgumentOutOfRangeException("type");
64      }
65    }
66
67    /// <summary>
68    /// Adds a new column to the chart.
69    /// </summary>
70    /// <param name="columnId">Id of the column</param>
71    /// <param name="values">Values of the column</param>
72    private void AddColumn(long columnId, double[] values) {
73      throw new NotImplementedException();
74    }
75
76    /// <summary>
77    /// Modifies an existing column of the chart.
78    /// </summary>
79    /// <param name="columnId">Id of the column</param>
80    /// <param name="values">Values of the column</param>
81    private void ModifyColumn(long columnId, double[] values) {
82      throw new NotImplementedException();
83    }
84
85    /// <summary>
86    /// Removes a column from the chart.
87    /// </summary>
88    /// <param name="columnId">Id of the column</param>
89    private void RemoveColumn(long columnId) {
90      throw new NotImplementedException();
91    }
92
93    #region Add-/RemoveItemEvents
94
95    protected override void AddItemEvents() {
96      base.AddItemEvents();
97      model.ColumnChanged += OnDataChanged;
98    }
99
100    protected override void RemoveItemEvents() {
101      base.RemoveItemEvents();
102      model.ColumnChanged -= OnDataChanged;
103    }
104
105    #endregion
106
107    #region Begin-/EndUpdate
108
109    private int beginUpdateCount = 0;
110
111    public void BeginUpdate() {
112      beginUpdateCount++;
113    }
114
115    public void EndUpdate() {
116      if (beginUpdateCount == 0) {
117        throw new InvalidOperationException("Too many EndUpdates.");
118      }
119
120      beginUpdateCount--;
121
122      if (beginUpdateCount == 0) {
123        Invalidate();
124      }
125    }
126
127    #endregion
128  }
129}
Note: See TracBrowser for help on using the repository browser.