Free cookie consent management tool by TermsFeed Policy Generator

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

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

changed interface between model and view (#316)

File size: 5.3 KB
RevLine 
[683]1using System;
[754]2using System.Drawing;
[697]3using HeuristicLab.Core;
[683]4
[754]5namespace HeuristicLab.Visualization
6{
7  public partial class LineChart : ViewBase
8  {
[697]9    private readonly IChartDataRowsModel model;
[754]10    private Color[] lineColors;
[684]11
[697]12    /// <summary>
13    /// This constructor shouldn't be called. Only required for the designer.
14    /// </summary>
[754]15    public LineChart()
16    {
[684]17      InitializeComponent();
18    }
19
[697]20    /// <summary>
21    /// Initializes the chart.
22    /// </summary>
[754]23    /// <param name="model">Referenz to the model, for data</param>
24    public LineChart(IChartDataRowsModel model) : this()
25    {
26      if (model == null)
27      {
[697]28        throw new NullReferenceException("Model cannot be null.");
29      }
[684]30
[697]31      this.model = model;
[684]32
[754]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);
[697]43      Reset();
44    }
[684]45
[697]46    /// <summary>
47    /// Resets the line chart by deleting all shapes and reloading all data from the model.
48    /// </summary>
[754]49    private void Reset()
50    {
[761]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();
[683]92    }
[684]93
[697]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>
[754]100    private void OnDataChanged(ChangeType type, long columnId, double[] values)
101    {
102      switch (type)
103      {
[697]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>
[754]123    private void AddColumn(long columnId, double[] values)
124    {
[684]125      throw new NotImplementedException();
126    }
[697]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>
[754]133    private void ModifyColumn(long columnId, double[] values)
134    {
[697]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>
[754]142    private void RemoveColumn(long columnId)
143    {
[697]144      throw new NotImplementedException();
145    }
146
147    #region Add-/RemoveItemEvents
148
[754]149    protected override void AddItemEvents()
150    {
[761]151      // TODO an neues model interface anpassen   
152      throw new NotImplementedException();
153//      base.AddItemEvents();
154//      model.ColumnChanged += OnDataChanged;
[697]155    }
156
[754]157    protected override void RemoveItemEvents()
158    {
[761]159      // TODO an neues model interface anpassen   
160      throw new NotImplementedException();
161
162//      base.RemoveItemEvents();
163//      model.ColumnChanged -= OnDataChanged;
[697]164    }
165
166    #endregion
167
168    #region Begin-/EndUpdate
169
170    private int beginUpdateCount = 0;
171
[754]172    public void BeginUpdate()
173    {
[697]174      beginUpdateCount++;
175    }
176
[754]177    public void EndUpdate()
178    {
179      if (beginUpdateCount == 0)
180      {
[697]181        throw new InvalidOperationException("Too many EndUpdates.");
182      }
183
184      beginUpdateCount--;
185
[754]186      if (beginUpdateCount == 0)
187      {
[697]188        Invalidate();
189      }
190    }
191
192    #endregion
[684]193  }
194}
Note: See TracBrowser for help on using the repository browser.