[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;
|
---|
[2474] | 33 | using HeuristicLab.Common;
|
---|
[2520] | 34 | using HeuristicLab.Core.Views;
|
---|
| 35 | using HeuristicLab.MainForm;
|
---|
[2] | 36 |
|
---|
| 37 | namespace HeuristicLab.Logging {
|
---|
[1167] | 38 | /// <summary>
|
---|
| 39 | /// The visual representation of a <see cref="Linechart"/>.
|
---|
| 40 | /// </summary>
|
---|
[2520] | 41 | [Content(typeof(Linechart), true)]
|
---|
[2546] | 42 | public partial class LinechartView : ItemViewBase {
|
---|
[926] | 43 | private double maxY = double.MinValue, minY = double.MaxValue;
|
---|
[362] | 44 | private static int[] colors = new int[] {
|
---|
| 45 | 182,182,255,
|
---|
| 46 | 218,255,182,
|
---|
| 47 | 255,182,218,
|
---|
| 48 | 182,255,255,
|
---|
| 49 | 218,182,255,
|
---|
| 50 | 255,182,255,
|
---|
| 51 | 255,182,182,
|
---|
| 52 | 255,218,182,
|
---|
| 53 | 255,255,182,
|
---|
| 54 | 182,255,182,
|
---|
| 55 | 182,255,218,
|
---|
| 56 | 182,218,255
|
---|
| 57 | };
|
---|
| 58 |
|
---|
[1167] | 59 | /// <summary>
|
---|
| 60 | /// Gets or sets the Linechart object to represent visually.
|
---|
| 61 | /// </summary>
|
---|
| 62 | /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
|
---|
| 63 | /// No own data storage present.</remarks>
|
---|
[2] | 64 | public Linechart Linechart {
|
---|
| 65 | get { return (Linechart)base.Item; }
|
---|
| 66 | set { base.Item = value; }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[1167] | 69 | /// <summary>
|
---|
| 70 | /// Initializes a new instance of <see cref="LinechartView"/>.
|
---|
| 71 | /// </summary>
|
---|
[2] | 72 | public LinechartView() {
|
---|
| 73 | InitializeComponent();
|
---|
| 74 | Caption = "Linechart View";
|
---|
| 75 | }
|
---|
[1167] | 76 | /// <summary>
|
---|
| 77 | /// Initializes a new instance of <see cref="LinechartView"/> with the given <paramref name="linechart"/>.
|
---|
| 78 | /// </summary>
|
---|
| 79 | /// <param name="linechart">The linechart to represent visually.</param>
|
---|
[2] | 80 | public LinechartView(Linechart linechart)
|
---|
| 81 | : this() {
|
---|
| 82 | Linechart = linechart;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[1167] | 85 | /// <summary>
|
---|
| 86 | /// Removes the event handlers from the underlying <see cref="Linechart"/>.
|
---|
| 87 | /// </summary>
|
---|
| 88 | /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
[2] | 89 | protected override void RemoveItemEvents() {
|
---|
[362] | 90 | if(Linechart != null) {
|
---|
[2474] | 91 | Linechart.Values.ItemAdded -= new EventHandler<EventArgs<IItem, int>>(Values_ItemAdded);
|
---|
| 92 | Linechart.Values.ItemRemoved -= new EventHandler<EventArgs<IItem, int>>(Values_ItemRemoved);
|
---|
[2] | 93 | }
|
---|
| 94 | base.RemoveItemEvents();
|
---|
| 95 | }
|
---|
[1167] | 96 | /// <summary>
|
---|
| 97 | /// Adds event handlers to the underlying <see cref="Linechart"/>.
|
---|
| 98 | /// </summary>
|
---|
| 99 | /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
[2] | 100 | protected override void AddItemEvents() {
|
---|
| 101 | base.AddItemEvents();
|
---|
[362] | 102 | if(Linechart != null) {
|
---|
[2474] | 103 | Linechart.Values.ItemAdded += new EventHandler<EventArgs<IItem, int>>(Values_ItemAdded);
|
---|
| 104 | Linechart.Values.ItemRemoved += new EventHandler<EventArgs<IItem, int>>(Values_ItemRemoved);
|
---|
[2] | 105 | }
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[1167] | 108 | /// <summary>
|
---|
| 109 | /// Updates all controls with the latest data of the model.
|
---|
| 110 | /// </summary>
|
---|
| 111 | /// <remarks>Calls <see cref="ViewBase.UpdateControls"/> of base class <see cref="UpdateControls"/>.</remarks>
|
---|
[2] | 112 | protected override void UpdateControls() {
|
---|
| 113 | base.UpdateControls();
|
---|
| 114 | Datachart datachart = new Datachart(-50, -5000, 1000, 55000);
|
---|
| 115 | datachart.Title = "Line Chart";
|
---|
| 116 | dataChartControl.ScaleOnResize = false;
|
---|
| 117 | dataChartControl.Chart = datachart;
|
---|
| 118 | datachart.Group.Clear();
|
---|
| 119 | datachart.Group.Add(new Axis(datachart, 0, 0, AxisType.Both));
|
---|
[362] | 120 | if(Linechart != null) {
|
---|
[2] | 121 | datachart.UpdateEnabled = false;
|
---|
[362] | 122 | for(int i = 0; i < Linechart.NumberOfLines; i++) {
|
---|
| 123 | int colorIndex = (i % 12)*3;
|
---|
| 124 | Color curCol = Color.FromArgb(colors[colorIndex],colors[colorIndex + 1], colors[colorIndex + 2]);
|
---|
| 125 | Pen p = new Pen(curCol);
|
---|
| 126 | SolidBrush b = new SolidBrush(curCol);
|
---|
| 127 | datachart.AddDataRow(DataRowType.Lines, p, b);
|
---|
| 128 | }
|
---|
[2] | 129 |
|
---|
[362] | 130 | for(int i = 0; i < Linechart.Values.Count; i++) {
|
---|
[2] | 131 | ItemList list = (ItemList)Linechart.Values[i];
|
---|
[362] | 132 | for(int j = 0; j < list.Count; j++) {
|
---|
[926] | 133 | double value = 0.0;
|
---|
| 134 | if (list[j] is IntData) value = (double)((IntData)list[j]).Data;
|
---|
| 135 | else value = ((DoubleData)list[j]).Data;
|
---|
[362] | 136 | if(!double.IsInfinity(value) && !double.IsNaN(value)) {
|
---|
| 137 | if(value < minY) minY = value;
|
---|
| 138 | if(value > maxY) maxY = value;
|
---|
| 139 | datachart.AddDataPoint(j, i, value);
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
[2] | 142 | }
|
---|
[362] | 143 | datachart.ZoomIn(-Linechart.Values.Count * 0.05, minY - (minY * 0.1), Linechart.Values.Count * 1.05, maxY * 1.05);
|
---|
[2] | 144 | datachart.UpdateEnabled = true;
|
---|
| 145 | datachart.EnforceUpdate();
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | #region Values Events
|
---|
[2474] | 150 | private delegate void ItemIndexDelegate(object sender, EventArgs<IItem, int> e);
|
---|
| 151 | private void Values_ItemRemoved(object sender, EventArgs<IItem, int> e) {
|
---|
[362] | 152 | if(InvokeRequired) {
|
---|
[2] | 153 | Invoke(new ItemIndexDelegate(Values_ItemRemoved), sender, e);
|
---|
| 154 | } else {
|
---|
| 155 | Datachart datachart = dataChartControl.Chart;
|
---|
| 156 | }
|
---|
| 157 | }
|
---|
[2474] | 158 | private void Values_ItemAdded(object sender, EventArgs<IItem, int> e) {
|
---|
[362] | 159 | if(InvokeRequired) {
|
---|
[2] | 160 | Invoke(new ItemIndexDelegate(Values_ItemAdded), sender, e);
|
---|
| 161 | } else {
|
---|
| 162 | Datachart datachart = dataChartControl.Chart;
|
---|
[2474] | 163 | ItemList list = (ItemList)e.Value;
|
---|
[2] | 164 | datachart.UpdateEnabled = false;
|
---|
[926] | 165 | for (int i = 0; i < list.Count; i++) {
|
---|
| 166 | double value = 0.0;
|
---|
| 167 | if (list[i] is IntData) value = (double)((IntData)list[i]).Data;
|
---|
| 168 | else value = ((DoubleData)list[i]).Data;
|
---|
[2474] | 169 | datachart.AddDataPoint(i, e.Value2, value);
|
---|
[926] | 170 | if (value < minY) minY = value;
|
---|
| 171 | if (value > maxY) maxY = value;
|
---|
| 172 | }
|
---|
| 173 | datachart.ZoomIn(-Linechart.Values.Count * 0.05, minY - (minY * 0.1), Linechart.Values.Count * 1.05, maxY * 1.05);
|
---|
[2] | 174 | datachart.UpdateEnabled = true;
|
---|
| 175 | datachart.EnforceUpdate();
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 | #endregion
|
---|
| 179 | }
|
---|
| 180 | }
|
---|