Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 797 was 761, checked in by mstoeger, 16 years ago

changed interface between model and view (#316)

File size: 5.3 KB
Line 
1using System;
2using System.Drawing;
3using HeuristicLab.Core;
4
5namespace HeuristicLab.Visualization
6{
7  public partial class LineChart : ViewBase
8  {
9    private readonly IChartDataRowsModel model;
10    private Color[] lineColors;
11
12    /// <summary>
13    /// This constructor shouldn't be called. Only required for the designer.
14    /// </summary>
15    public LineChart()
16    {
17      InitializeComponent();
18    }
19
20    /// <summary>
21    /// Initializes the chart.
22    /// </summary>
23    /// <param name="model">Referenz to the model, for data</param>
24    public LineChart(IChartDataRowsModel model) : this()
25    {
26      if (model == null)
27      {
28        throw new NullReferenceException("Model cannot be null.");
29      }
30
31      this.model = model;
32
33      //TODO: read line colors instead of static ones
34      lineColors = new Color[3];
35      lineColors[0] = Color.Red;
36      lineColors[1] = Color.Green;
37      lineColors[2] = Color.Blue;
38     
39      //TODO: correct Rectangle to fit
40      RectangleD clientRectangle = new RectangleD(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Right,
41                                                  ClientRectangle.Bottom);
42      canvasUI1.MainCanvas.WorldShape = new WorldShape(clientRectangle, clientRectangle);
43      Reset();
44    }
45
46    /// <summary>
47    /// Resets the line chart by deleting all shapes and reloading all data from the model.
48    /// </summary>
49    private void Reset()
50    {
51      // TODO an neues model interface anpassen   
52      throw new NotImplementedException();
53     
54//      BeginUpdate();
55//
56//      // TODO clear existing shapes
57//
58//      WorldShape mainWorld = canvasUI1.MainCanvas.WorldShape;
59//
60//      double spacing = mainWorld.BoundingBox.Width/model.Columns.Count;
61//      double oldX = 0;
62//      double currentX = spacing;
63//      ChartDataRowsModelColumn oldColumn = null;
64//      // reload data from the model and create shapes
65//      foreach (ChartDataRowsModelColumn column in model.Columns)
66//      {
67//        if (oldColumn != null)
68//        {
69//          if (column.Values != null)
70//          {
71//            for (int i = 0; i < column.Values.Length; i++)
72//            {
73//              LineShape line = new LineShape(oldX, oldColumn.Values[i], currentX, column.Values[i], 0, lineColors[i]);
74//              mainWorld.AddShape(line);
75//            }
76//            oldX = currentX;
77//            currentX += spacing;
78//          }
79//          oldColumn = column;
80//        }
81//        else
82//        {
83//          oldColumn = column;
84//        }
85//
86//        canvasUI1.Invalidate();
87//
88//        //   AddColumn(column.ColumnId, column.Values);
89//      }
90//
91//      EndUpdate();
92    }
93
94    /// <summary>
95    /// Event handler which gets called when data in the model changes.
96    /// </summary>
97    /// <param name="type">Type of change</param>
98    /// <param name="columnId">Id of the changed column</param>
99    /// <param name="values">Values contained within the changed column</param>
100    private void OnDataChanged(ChangeType type, long columnId, double[] values)
101    {
102      switch (type)
103      {
104        case ChangeType.Add:
105          AddColumn(columnId, values);
106          break;
107        case ChangeType.Modify:
108          ModifyColumn(columnId, values);
109          break;
110        case ChangeType.Remove:
111          RemoveColumn(columnId);
112          break;
113        default:
114          throw new ArgumentOutOfRangeException("type");
115      }
116    }
117
118    /// <summary>
119    /// Adds a new column to the chart.
120    /// </summary>
121    /// <param name="columnId">Id of the column</param>
122    /// <param name="values">Values of the column</param>
123    private void AddColumn(long columnId, double[] values)
124    {
125      throw new NotImplementedException();
126    }
127
128    /// <summary>
129    /// Modifies an existing column of the chart.
130    /// </summary>
131    /// <param name="columnId">Id of the column</param>
132    /// <param name="values">Values of the column</param>
133    private void ModifyColumn(long columnId, double[] values)
134    {
135      throw new NotImplementedException();
136    }
137
138    /// <summary>
139    /// Removes a column from the chart.
140    /// </summary>
141    /// <param name="columnId">Id of the column</param>
142    private void RemoveColumn(long columnId)
143    {
144      throw new NotImplementedException();
145    }
146
147    #region Add-/RemoveItemEvents
148
149    protected override void AddItemEvents()
150    {
151      // TODO an neues model interface anpassen   
152      throw new NotImplementedException();
153//      base.AddItemEvents();
154//      model.ColumnChanged += OnDataChanged;
155    }
156
157    protected override void RemoveItemEvents()
158    {
159      // TODO an neues model interface anpassen   
160      throw new NotImplementedException();
161
162//      base.RemoveItemEvents();
163//      model.ColumnChanged -= OnDataChanged;
164    }
165
166    #endregion
167
168    #region Begin-/EndUpdate
169
170    private int beginUpdateCount = 0;
171
172    public void BeginUpdate()
173    {
174      beginUpdateCount++;
175    }
176
177    public void EndUpdate()
178    {
179      if (beginUpdateCount == 0)
180      {
181        throw new InvalidOperationException("Too many EndUpdates.");
182      }
183
184      beginUpdateCount--;
185
186      if (beginUpdateCount == 0)
187      {
188        Invalidate();
189      }
190    }
191
192    #endregion
193  }
194}
Note: See TracBrowser for help on using the repository browser.