Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Logging/PointXYChartView.cs @ 673

Last change on this file since 673 was 673, checked in by mkommend, 16 years ago

corrected initial zoom to use absolute range values (ticket #310)

File size: 5.4 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 PointXYChartView : ViewBase {
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
51    public PointXYChart PointXYChart {
52      get { return (PointXYChart)base.Item; }
53      set { base.Item = value; }
54    }
55
56    public PointXYChartView() {
57      InitializeComponent();
58      Caption = "PointXYChart View";
59    }
60    public PointXYChartView(PointXYChart pointXYChart)
61      : this() {
62      PointXYChart = pointXYChart;
63    }
64
65    protected override void RemoveItemEvents() {
66      if (PointXYChart != null) {
67        PointXYChart.Values.ItemAdded -= new EventHandler<ItemIndexEventArgs>(Values_ItemAdded);
68        PointXYChart.Values.ItemRemoved -= new EventHandler<ItemIndexEventArgs>(Values_ItemRemoved);
69      }
70      base.RemoveItemEvents();
71    }
72    protected override void AddItemEvents() {
73      base.AddItemEvents();
74      if (PointXYChart != null) {
75        PointXYChart.Values.ItemAdded += new EventHandler<ItemIndexEventArgs>(Values_ItemAdded);
76        PointXYChart.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 = "Point X/Y Chart";
84      dataChartControl.ScaleOnResize = false;
85      dataChartControl.Chart = datachart;
86      datachart.Group.Clear();
87      datachart.Group.Add(new Axis(datachart, 0, 0, AxisType.Both));
88      double maxY = double.MinValue, minY = double.MaxValue;
89      double maxX = double.MinValue, minX = double.MaxValue;
90      if (PointXYChart != null) {
91        datachart.UpdateEnabled = false;
92        for (int i = 0; i < PointXYChart.Values.Count; i++) {
93          int colorIndex = (i % 12) * 3;
94          Color curCol = Color.FromArgb(colors[colorIndex], colors[colorIndex + 1], colors[colorIndex + 2]);
95          Pen p = new Pen(curCol);
96          SolidBrush b = new SolidBrush(curCol);
97          datachart.AddDataRow(PointXYChart.ConnectDots.Data ? DataRowType.Lines : DataRowType.Points, p, b);
98        }
99
100        for (int i = 0; i < PointXYChart.Values.Count; i++) {
101          ItemList<DoubleArrayData> list = (ItemList<DoubleArrayData>)PointXYChart.Values[i];
102          for (int j = 0; j < list.Count; j++) {
103            double[] value = ((DoubleArrayData)list[j]).Data;
104            if (!double.IsInfinity(value[0]) && !double.IsNaN(value[0]) && !double.IsInfinity(value[1]) && !double.IsNaN(value[1])) {
105              if (value[0] < minX) minX = value[0];
106              if (value[0] > maxX) maxX = value[0];
107              if (value[1] < minY) minY = value[1];
108              if (value[1] > maxY) maxY = value[1];
109
110              datachart.AddDataPoint(i, value[0], value[1]);                                                         
111            }
112          }
113        }
114        datachart.ZoomIn(minX - (Math.Abs(maxX - minX) * 0.1), minY - (Math.Abs(maxY -minY) * 0.1), maxX + (Math.Abs(maxX - minX) * 0.1), maxY + (Math.Abs(maxY - minY) * 0.1));
115        datachart.UpdateEnabled = true;
116        datachart.EnforceUpdate();
117      }
118    }
119
120    #region Values Events
121    private delegate void ItemIndexDelegate(object sender, ItemIndexEventArgs e);
122    private void Values_ItemRemoved(object sender, ItemIndexEventArgs e) {
123      if (InvokeRequired) {
124        Invoke(new ItemIndexDelegate(Values_ItemRemoved), sender, e);
125      } else {
126        Datachart datachart = dataChartControl.Chart;
127      }
128    }
129    private void Values_ItemAdded(object sender, ItemIndexEventArgs e) {
130      if (InvokeRequired) {
131        Invoke(new ItemIndexDelegate(Values_ItemAdded), sender, e);
132      } else {
133        //Datachart datachart = dataChartControl.Chart;
134        //ItemList list = (ItemList)e.Item;
135        //datachart.UpdateEnabled = false;
136        //for (int i = 0; i < list.Count; i++)
137        //  datachart.AddDataPoint(i, e.Index, ((DoubleArrayData)list[i]).Data[0]);
138        //datachart.UpdateEnabled = true;
139        //datachart.EnforceUpdate();
140      }
141    }
142    #endregion
143  }
144}
Note: See TracBrowser for help on using the repository browser.