#region License Information
/* HeuristicLab
* Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Charting;
using HeuristicLab.Charting.Data;
namespace HeuristicLab.Logging {
public partial class LinechartView : ViewBase {
public Linechart Linechart {
get { return (Linechart)base.Item; }
set { base.Item = value; }
}
public LinechartView() {
InitializeComponent();
Caption = "Linechart View";
}
public LinechartView(Linechart linechart)
: this() {
Linechart = linechart;
}
protected override void RemoveItemEvents() {
if (Linechart != null) {
Linechart.Values.ItemAdded -= new EventHandler(Values_ItemAdded);
Linechart.Values.ItemRemoved -= new EventHandler(Values_ItemRemoved);
}
base.RemoveItemEvents();
}
protected override void AddItemEvents() {
base.AddItemEvents();
if (Linechart != null) {
Linechart.Values.ItemAdded += new EventHandler(Values_ItemAdded);
Linechart.Values.ItemRemoved += new EventHandler(Values_ItemRemoved);
}
}
protected override void UpdateControls() {
base.UpdateControls();
Datachart datachart = new Datachart(-50, -5000, 1000, 55000);
datachart.Title = "Line Chart";
dataChartControl.ScaleOnResize = false;
dataChartControl.Chart = datachart;
datachart.Group.Clear();
datachart.Group.Add(new Axis(datachart, 0, 0, AxisType.Both));
if (Linechart != null) {
datachart.UpdateEnabled = false;
for (int i = 0; i < Linechart.NumberOfLines; i++)
datachart.AddDataRow(DataRowType.Lines, Pens.Black, Brushes.Blue);
for (int i = 0; i < Linechart.Values.Count; i++) {
ItemList list = (ItemList)Linechart.Values[i];
for (int j = 0; j < list.Count; j++)
datachart.AddDataPoint(j, i, ((DoubleData)list[j]).Data);
}
datachart.UpdateEnabled = true;
datachart.EnforceUpdate();
}
}
#region Values Events
private delegate void ItemIndexDelegate(object sender, ItemIndexEventArgs e);
private void Values_ItemRemoved(object sender, ItemIndexEventArgs e) {
if (InvokeRequired) {
Invoke(new ItemIndexDelegate(Values_ItemRemoved), sender, e);
} else {
Datachart datachart = dataChartControl.Chart;
}
}
private void Values_ItemAdded(object sender, ItemIndexEventArgs e) {
if (InvokeRequired) {
Invoke(new ItemIndexDelegate(Values_ItemAdded), sender, e);
} else {
Datachart datachart = dataChartControl.Chart;
ItemList list = (ItemList)e.Item;
datachart.UpdateEnabled = false;
for (int i = 0; i < list.Count; i++)
datachart.AddDataPoint(i, e.Index, ((DoubleData)list[i]).Data);
datachart.UpdateEnabled = true;
datachart.EnforceUpdate();
}
}
#endregion
}
}