Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.0/sources/HeuristicLab.Logging/LinechartView.cs @ 4949

Last change on this file since 4949 was 2, checked in by swagner, 17 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

File size: 4.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Text;
28using System.Windows.Forms;
29using HeuristicLab.Core;
30using HeuristicLab.Data;
31using HeuristicLab.Charting;
32using HeuristicLab.Charting.Data;
33
34namespace HeuristicLab.Logging {
35  public partial class LinechartView : ViewBase {
36    public Linechart Linechart {
37      get { return (Linechart)base.Item; }
38      set { base.Item = value; }
39    }
40
41    public LinechartView() {
42      InitializeComponent();
43      Caption = "Linechart View";
44    }
45    public LinechartView(Linechart linechart)
46      : this() {
47      Linechart = linechart;
48    }
49
50    protected override void RemoveItemEvents() {
51      if (Linechart != null) {
52        Linechart.Values.ItemAdded -= new EventHandler<ItemIndexEventArgs>(Values_ItemAdded);
53        Linechart.Values.ItemRemoved -= new EventHandler<ItemIndexEventArgs>(Values_ItemRemoved);
54      }
55      base.RemoveItemEvents();
56    }
57    protected override void AddItemEvents() {
58      base.AddItemEvents();
59      if (Linechart != null) {
60        Linechart.Values.ItemAdded += new EventHandler<ItemIndexEventArgs>(Values_ItemAdded);
61        Linechart.Values.ItemRemoved += new EventHandler<ItemIndexEventArgs>(Values_ItemRemoved);
62      }
63    }
64
65    protected override void UpdateControls() {
66      base.UpdateControls();
67      Datachart datachart = new Datachart(-50, -5000, 1000, 55000);
68      datachart.Title = "Line Chart";
69      dataChartControl.ScaleOnResize = false;
70      dataChartControl.Chart = datachart;
71      datachart.Group.Clear();
72      datachart.Group.Add(new Axis(datachart, 0, 0, AxisType.Both));
73      if (Linechart != null) {
74        datachart.UpdateEnabled = false;
75        for (int i = 0; i < Linechart.NumberOfLines; i++)
76          datachart.AddDataRow(DataRowType.Lines, Pens.Black, Brushes.Blue);
77
78        for (int i = 0; i < Linechart.Values.Count; i++) {
79          ItemList list = (ItemList)Linechart.Values[i];
80          for (int j = 0; j < list.Count; j++)
81            datachart.AddDataPoint(j, i, ((DoubleData)list[j]).Data);
82        }
83        datachart.UpdateEnabled = true;
84        datachart.EnforceUpdate();
85      }
86    }
87
88    #region Values Events
89    private delegate void ItemIndexDelegate(object sender, ItemIndexEventArgs e);
90    private void Values_ItemRemoved(object sender, ItemIndexEventArgs e) {
91      if (InvokeRequired) {
92        Invoke(new ItemIndexDelegate(Values_ItemRemoved), sender, e);
93      } else {
94        Datachart datachart = dataChartControl.Chart;
95      }
96    }
97    private void Values_ItemAdded(object sender, ItemIndexEventArgs e) {
98      if (InvokeRequired) {
99        Invoke(new ItemIndexDelegate(Values_ItemAdded), sender, e);
100      } else {
101        Datachart datachart = dataChartControl.Chart;
102        ItemList list = (ItemList)e.Item;
103        datachart.UpdateEnabled = false;
104        for (int i = 0; i < list.Count; i++)
105          datachart.AddDataPoint(i, e.Index, ((DoubleData)list[i]).Data);
106        datachart.UpdateEnabled = true;
107        datachart.EnforceUpdate();
108      }
109    }
110    #endregion
111  }
112}
Note: See TracBrowser for help on using the repository browser.