[2] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Drawing;
|
---|
| 26 | using System.Data;
|
---|
| 27 | using System.Text;
|
---|
| 28 | using System.Windows.Forms;
|
---|
| 29 | using HeuristicLab.Core;
|
---|
| 30 | using HeuristicLab.Data;
|
---|
| 31 | using HeuristicLab.Charting;
|
---|
| 32 | using HeuristicLab.Charting.Data;
|
---|
| 33 |
|
---|
| 34 | namespace HeuristicLab.Logging {
|
---|
| 35 | public partial class LinechartView : ViewBase {
|
---|
[362] | 36 | private static int[] colors = new int[] {
|
---|
| 37 | 182,182,255,
|
---|
| 38 | 218,255,182,
|
---|
| 39 | 255,182,218,
|
---|
| 40 | 182,255,255,
|
---|
| 41 | 218,182,255,
|
---|
| 42 | 255,182,255,
|
---|
| 43 | 255,182,182,
|
---|
| 44 | 255,218,182,
|
---|
| 45 | 255,255,182,
|
---|
| 46 | 182,255,182,
|
---|
| 47 | 182,255,218,
|
---|
| 48 | 182,218,255
|
---|
| 49 | };
|
---|
| 50 |
|
---|
[2] | 51 | public Linechart Linechart {
|
---|
| 52 | get { return (Linechart)base.Item; }
|
---|
| 53 | set { base.Item = value; }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | public LinechartView() {
|
---|
| 57 | InitializeComponent();
|
---|
| 58 | Caption = "Linechart View";
|
---|
| 59 | }
|
---|
| 60 | public LinechartView(Linechart linechart)
|
---|
| 61 | : this() {
|
---|
| 62 | Linechart = linechart;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | protected override void RemoveItemEvents() {
|
---|
[362] | 66 | if(Linechart != null) {
|
---|
[2] | 67 | Linechart.Values.ItemAdded -= new EventHandler<ItemIndexEventArgs>(Values_ItemAdded);
|
---|
| 68 | Linechart.Values.ItemRemoved -= new EventHandler<ItemIndexEventArgs>(Values_ItemRemoved);
|
---|
| 69 | }
|
---|
| 70 | base.RemoveItemEvents();
|
---|
| 71 | }
|
---|
| 72 | protected override void AddItemEvents() {
|
---|
| 73 | base.AddItemEvents();
|
---|
[362] | 74 | if(Linechart != null) {
|
---|
[2] | 75 | Linechart.Values.ItemAdded += new EventHandler<ItemIndexEventArgs>(Values_ItemAdded);
|
---|
| 76 | Linechart.Values.ItemRemoved += new EventHandler<ItemIndexEventArgs>(Values_ItemRemoved);
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | protected override void UpdateControls() {
|
---|
| 81 | base.UpdateControls();
|
---|
| 82 | Datachart datachart = new Datachart(-50, -5000, 1000, 55000);
|
---|
| 83 | datachart.Title = "Line Chart";
|
---|
| 84 | dataChartControl.ScaleOnResize = false;
|
---|
| 85 | dataChartControl.Chart = datachart;
|
---|
| 86 | datachart.Group.Clear();
|
---|
| 87 | datachart.Group.Add(new Axis(datachart, 0, 0, AxisType.Both));
|
---|
[362] | 88 | double maxY = double.MinValue, minY = double.MaxValue;
|
---|
| 89 | if(Linechart != null) {
|
---|
[2] | 90 | datachart.UpdateEnabled = false;
|
---|
[362] | 91 | for(int i = 0; i < Linechart.NumberOfLines; i++) {
|
---|
| 92 | int colorIndex = (i % 12)*3;
|
---|
| 93 | Color curCol = Color.FromArgb(colors[colorIndex],colors[colorIndex + 1], colors[colorIndex + 2]);
|
---|
| 94 | Pen p = new Pen(curCol);
|
---|
| 95 | SolidBrush b = new SolidBrush(curCol);
|
---|
| 96 | datachart.AddDataRow(DataRowType.Lines, p, b);
|
---|
| 97 | }
|
---|
[2] | 98 |
|
---|
[362] | 99 | for(int i = 0; i < Linechart.Values.Count; i++) {
|
---|
[2] | 100 | ItemList list = (ItemList)Linechart.Values[i];
|
---|
[362] | 101 | for(int j = 0; j < list.Count; j++) {
|
---|
| 102 | double value = ((DoubleData)list[j]).Data;
|
---|
| 103 | if(!double.IsInfinity(value) && !double.IsNaN(value)) {
|
---|
| 104 | if(value < minY) minY = value;
|
---|
| 105 | if(value > maxY) maxY = value;
|
---|
| 106 | datachart.AddDataPoint(j, i, value);
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
[2] | 109 | }
|
---|
[362] | 110 | datachart.ZoomIn(-Linechart.Values.Count * 0.05, minY - (minY * 0.1), Linechart.Values.Count * 1.05, maxY * 1.05);
|
---|
[2] | 111 | datachart.UpdateEnabled = true;
|
---|
| 112 | datachart.EnforceUpdate();
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | #region Values Events
|
---|
| 117 | private delegate void ItemIndexDelegate(object sender, ItemIndexEventArgs e);
|
---|
| 118 | private void Values_ItemRemoved(object sender, ItemIndexEventArgs e) {
|
---|
[362] | 119 | if(InvokeRequired) {
|
---|
[2] | 120 | Invoke(new ItemIndexDelegate(Values_ItemRemoved), sender, e);
|
---|
| 121 | } else {
|
---|
| 122 | Datachart datachart = dataChartControl.Chart;
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | private void Values_ItemAdded(object sender, ItemIndexEventArgs e) {
|
---|
[362] | 126 | if(InvokeRequired) {
|
---|
[2] | 127 | Invoke(new ItemIndexDelegate(Values_ItemAdded), sender, e);
|
---|
| 128 | } else {
|
---|
| 129 | Datachart datachart = dataChartControl.Chart;
|
---|
| 130 | ItemList list = (ItemList)e.Item;
|
---|
| 131 | datachart.UpdateEnabled = false;
|
---|
[362] | 132 | for(int i = 0; i < list.Count; i++)
|
---|
[2] | 133 | datachart.AddDataPoint(i, e.Index, ((DoubleData)list[i]).Data);
|
---|
| 134 | datachart.UpdateEnabled = true;
|
---|
| 135 | datachart.EnforceUpdate();
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 | #endregion
|
---|
| 139 | }
|
---|
| 140 | }
|
---|